1

我有一个 node.js 服务器,一旦收到电子邮件和密码,它就会向客户端发送信息。唯一的问题是,只有在提交相同的电子邮件和密码后才会发出。这是我的服务器代码:

client.on('checkcred', function(email, password){
        helper.check(email, password,function(run){
        client.emit('conf',run);
        console.log(run);
                });
        });

助手.js

exports.check = function(zmail, pasword,callback){

                client.query('SELECT id FROM passwords WHERE email="'+zmail+'"', function(err,data){

               console.log("wrong email");
                callback("no");
                }else{
                        var savedemail = data[0].id;
                        client.query('SELECT password FROM passwords WHERE id='+savedemail+'', function(err,pass){
                                var databasepass = pass[0].password;

                                if (pasword == databasepass){
                                        console.log("correct pass");
                                        callback("yes");
                                }else{
                                        console.log("incorrectpass");
                                        callback("no");
                                }
                        });
                }

                });

}

客户:

  var socket  = io.connect('http://54.213.92.113:8080');

            socket.on('conf', function (yn) {
                    if(yn == "yes"){
                    window.location = "spec.html";
                    }else{
                    alert("Incorrect Email or Password");
                    }
                    });

 function upload(email, password){

            //check the email and password against the saved email and pass.
            socket.emit('checkcred', email, password);

        }

这是输出......你可以看到第一次输出是'wrongemail''no',中间没有发出但是第二次,一个函数被发送到客户端!

   info  - transport end (socket end)
   debug - set close timeout for client Q7N-1qceSXBxORYXU4-y
   debug - cleared close timeout for client Q7N-1qceSXBxORYXU4-y
   debug - cleared heartbeat interval for client Q7N-1qceSXBxORYXU4-y
   debug - discarding transport
wrong email
no
   debug - served static content /socket.io.js
   debug - client authorized
   info  - handshake authorized CxnoJqQuGS3VwBP1U4-z
   debug - setting request GET /socket.io/1/websocket/CxnoJqQuGS3VwBP1U4-z
   debug - set heartbeat interval for client CxnoJqQuGS3VwBP1U4-z
   debug - client authorized for 
   debug - websocket writing 1::
wrong email
   debug - websocket writing 5:::{"name":"conf","args":["no"]}
no

我不知道为什么会这样!

4

0 回答 0