在我的应用程序中,有一个通常的登录页面将用户名和密码发送到服务器脚本,需要对其进行身份验证,如果是真实用户,服务器应该重定向到页面 student.html。这是我的代码
var ports = 3000;
var portt = 3001;
var express = require('express');
var student = require('express')();
var teacher = require('express')();
var server_s = require('http').createServer(student);
var server_t = require('http').createServer(teacher);
var ios = require('socket.io').listen(server_s);
var iot = require('socket.io').listen(server_t);
var path = require('path');
server_s.listen(ports);
server_t.listen(portt);
student.use(express.static(path.join(__dirname, 'public')));
student.get('/', function(req,res){
res.sendfile(__dirname + '/login.html');
});
teacher.use(express.static(path.join(__dirname, 'public')));
teacher.get('/', function(req,res){
res.sendfile(__dirname + '/mytry.html');
});
ios.sockets.on('connection', function(socket){
var username, password;
socket.on('check',function(data){
username = data[0];
password = data[1];
//************* Database connection and query *************
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'user',
password: '*******',
database: 'my_db'
});
connection.connect();
var qstring = 'SELECT s_id FROM login_student WHERE username='+username+'AND password='+password;
connection.query(qstring, function(err, rows, fields)
{
if (err)
{
console.log('ERROR: ' + err);
socket.emit('login_failure','DB error');
return;
}
console.log('The solution is: ', rows[0].solution);
if (rows>0)
//***** Here i want redirection to another page ******
else socket.emit('login_failure','Invalid Username or password');
});
connection.end();
});
});
iot.sockets.on('connection', function(socket){
;
});
});
谁能建议我该怎么做?