Sketch login/register queries

This commit is contained in:
Tom Russell 2018-09-09 11:58:08 +01:00
parent b9fd63698d
commit 37ac60f223

View File

@ -51,7 +51,7 @@ app.get('/buildings', function(req, res){
}) })
}) })
app.post('/user', function(req, res){ app.post('/register', function(req, res){
db.query( db.query(
`INSERT `INSERT
INTO users ( INTO users (
@ -63,20 +63,28 @@ app.post('/user', function(req, res){
gen_random_uuid(), gen_random_uuid(),
%s, %s,
%s, %s,
crypt(%s, gen_salt('bf')); -- hash (max password input length is 72) crypt(%s, gen_salt('bf')) -- hash (max password input length is 72)
) )
` `,
username,
email,
password
) )
}) })
app.get('/user', function(req, res){ app.get('/login', function(req, res){
db.query( db.query(
`SELECT `SELECT
user_id,
( (
hash = crypt(%s, pass) pass = crypt(%s, pass)
) AS authenticated ) AS auth_ok
FROM; FROM users
` WHERE
username = %s
`,
password,
username
) )
}) })