master
Nic0Nic0Nii 3 years ago
parent 6be8a028be
commit 1242f6e35a
  1. 9
      server.js
  2. 12
      server_test.js

@ -831,6 +831,12 @@ app.post(PREFIX+"/registerUser",(req,res)=>{
db.query('insert into users(username,email,password_hash,created_on,roles_id,avatar,recovery_hash) values($1,$2,$3,$4,(select id from roles where name=\'Guest\'),$5,$6)',[req.body.username,req.body.email,req.body.password,new Date(),req.body.avatar,req.body.userID]) db.query('insert into users(username,email,password_hash,created_on,roles_id,avatar,recovery_hash) values($1,$2,$3,$4,(select id from roles where name=\'Guest\'),$5,$6)',[req.body.username,req.body.email,req.body.password,new Date(),req.body.avatar,req.body.userID])
} }
}) })
.catch((err)=>{
console.log(err.message)
res.status(500).send(err.message)
})
} else {
res.status(500).send("Unsupported operation!")
} }
}) })
@ -846,6 +852,9 @@ app.post(PREFIX+"/validUser",(req,res)=>{
res.status(200).json({verified:false}) res.status(200).json({verified:false})
} }
}) })
.catch((err)=>{
res.status(500).send(err.message)
})
} else { } else {
db.query('select * from users where username=$1 and password_hash=$2 limit 1',[req.body.username,sh.SecretHash(req.body.password)]) db.query('select * from users where username=$1 and password_hash=$2 limit 1',[req.body.username,sh.SecretHash(req.body.password)])
.then((data)=>{ .then((data)=>{

@ -785,6 +785,12 @@ app.post(PREFIX+"/registerUser",(req,res)=>{
db.query('insert into users(username,email,password_hash,created_on,roles_id,avatar,recovery_hash) values($1,$2,$3,$4,(select id from roles where name=\'Guest\'),$5,$6)',[req.body.username,req.body.email,req.body.password,new Date(),req.body.avatar,req.body.userID]) db.query('insert into users(username,email,password_hash,created_on,roles_id,avatar,recovery_hash) values($1,$2,$3,$4,(select id from roles where name=\'Guest\'),$5,$6)',[req.body.username,req.body.email,req.body.password,new Date(),req.body.avatar,req.body.userID])
} }
}) })
.catch((err)=>{
console.log(err.message)
res.status(500).send(err.message)
})
} else {
res.status(500).send("Unsupported operation!")
} }
}) })
@ -797,10 +803,12 @@ app.post(PREFIX+"/validUser",(req,res)=>{
if (data.rows.length>0) { if (data.rows.length>0) {
res.status(200).json({verified:true}) res.status(200).json({verified:true})
} else { } else {
//This doesn't exist. At this time we will register them since this is external. res.status(200).json({verified:false})
db.query('insert into users(username,email,password_hash,created_on,roles_id,avatar,recovery_hash) values($1,$2,$3,$4,(select id from roles where name=\'Guest\'),$5,$6)',[req.body.username,req.body.email,req.body.password,new Date(),req.body.avatar,req.body.userID])
} }
}) })
.catch((err)=>{
res.status(500).send(err.message)
})
} else { } else {
db.query('select * from users where username=$1 and password_hash=$2 limit 1',[req.body.username,sh.SecretHash(req.body.password)]) db.query('select * from users where username=$1 and password_hash=$2 limit 1',[req.body.username,sh.SecretHash(req.body.password)])
.then((data)=>{ .then((data)=>{

Loading…
Cancel
Save