【发布时间】:2016-06-06 12:32:04
【问题描述】:
我正在使用https://github.com/sahat/hackathon-starter/tree/es6。我添加了 Socket.IO 但无法找到安全获取当前登录用户信息的方法。我有一个按钮,按下时我想发送到服务器(用户名、余额和金额,以便我可以安全地更新他们的模式模型......到目前为止,我可以使用 Jade 做到这一点,但我确信这真的很糟糕.
玉:
.content-r-inner.child
.col-md-12.col-xs-12.col-lg-12.no-pad-home
if !user
include partials/flash
include partials/visitorbar
else
include partials/userbar
|
#time.timecontainer.pulsing.pulsingbox
|
.product Product:
|
input#amount(type='text')
|
#slider-range-max
|
#minus1.minus.unselectable -
|
#plus1.plus.unselectable +
// </div>
.sendAmount(onclick="GetAmount()")
// inside include partials/userbar I have GetAmount Function
function GetAmount(){
socket.emit('getAmount', {
"username": "#{user.username}",
"maxBalance": "#{user.balance}",
"getAmount": document.getElementById('amount').value
});
}
{user.username} 你可以在标签中看到...
function GetAmount(){
socket.emit('getAmount', {
"username": "JohnDoe",
"maxBalance": "3750",
"getAmount": document.getElementById('amount').value
});
}
我确信有更好更安全的方法来识别哪个用户按下了按钮...希望有人能解释我可以使用 Socket.IO 实现它的最佳方法,刚开始使用它,我发现它是在很多方面都比 Ajax 好很多,但目前对它的方法甚至 Mongo 缺乏基本的了解:))
感谢您的帮助!赞一个!!!
【问题讨论】:
标签: node.js mongodb sockets socket.io pug