-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.js
57 lines (52 loc) · 1.56 KB
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var mysql=require("mysql");
function createConnection()
{
var connection=mysql.createPool({
connectionLimit:5,
host:'ec2-52-205-226-13.compute-1.amazonaws.com',
user:"myuser",
password:"pass123",
database:"CruiseUsers"
})
return connection;
}
function signUp(require,response)
{
var conn=createConnection();
let signUp_query="INSERT INTO Users(firstName,lastName,email,password) VALUES ?";
var user=[];
let data=[];
data.push(require.body.firstName);
data.push(require.body.lastName);
data.push(require.body.email);
data.push(require.body.psw);
user.push(data);
console.log("Data "+user+"");
conn.query(signUp_query,[user],function(err,rows,fields)
{
if(!err)
{
response.send("ok:SignUp succcessfull!!");
}else{
console.log("Error : "+err);
response.send("Error:SignUp failed Please try with different email");
}
});
}
function login(require,response)
{
var conn=createConnection();
let login_query="Select * from Users where email='"+require.body.email+"' and password='"+require.body.psw+"'";
conn.query(login_query,function(err,rows,fields){
if(!err)
{
console.log("JSon"+JSON.stringify(rows));
response.send("ok@:"+JSON.stringify(rows)+"@:Login succcessfull!!");
}else{
console.log("Error : "+err);
response.send("Error:Login failed Please try again ");
}
})
}
exports.login=login;
exports.signUp=signUp;