How to navigate to another html page?
Posted
by
newbie
on Stack Overflow
See other posts from Stack Overflow
or by newbie
Published on 2013-10-20T15:43:08Z
Indexed on
2013/10/20
15:54 UTC
Read the original article
Hit count: 247
In my application there's a usual login page sending username and password to the server script, where it needs to be authenticated, and in case of an authentic user, the server should redirect to a page student.html. This is my code
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){
;
});
});
Can anyone suggest what should I do?
© Stack Overflow or respective owner