From 37ac60f223ccf217b9e6f4ff0686cf8fadbd3706 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Sun, 9 Sep 2018 11:58:08 +0100 Subject: [PATCH] Sketch login/register queries --- apiserver/app.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/apiserver/app.js b/apiserver/app.js index 3a5c3dc9..7eb22d75 100644 --- a/apiserver/app.js +++ b/apiserver/app.js @@ -51,7 +51,7 @@ app.get('/buildings', function(req, res){ }) }) -app.post('/user', function(req, res){ +app.post('/register', function(req, res){ db.query( `INSERT INTO users ( @@ -63,20 +63,28 @@ app.post('/user', function(req, res){ gen_random_uuid(), %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( `SELECT + user_id, ( - hash = crypt(%s, pass) - ) AS authenticated - FROM; - ` + pass = crypt(%s, pass) + ) AS auth_ok + FROM users + WHERE + username = %s + `, + password, + username ) })