我试图在socket.io上使用jquery终端,但我无法弄清楚如何让登录正常工作。
有人可以帮助我吗?
var terminal = $('#terminal').terminal(function(command, terminal) {
socket.emit('stdin', command);
},
{
login: function(username, password, callback) {
var password = CryptoJS.SHA1($('#login_password').val()).toString(CryptoJS.enc.Base64);
socket.emit('stdin', "/login "+ username + " " + password);
// should wait for a response then callback
},
greetings: "You are authenticated",
tabcompletion: true,
exit: false,
completion: function(terminal, command, callback) {
callback(['/login']);
},
onBlur: function() {
// the height of the body is only 2 lines initialy
return false;
},
onClear: function() {
// the height of the body is only 2 lines initialy
}
});
答案 0 :(得分:0)
可能你应该使用不同的事件然后stdin登录:
login: function(username, password, callback) {
var password = CryptoJS.SHA1($('#login_password').val()).toString(CryptoJS.enc.Base64);
socket.emit('login', "/login "+ username + " " + password);
socket.on('auth', function(token) {
callback(token);
});
}
然后在服务器上监听登录事件并使用令牌发送auth事件。