diff options
| author | Jan Tuomi <jan.tuomi@eficode.com> | 2020-02-25 15:03:07 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@eficode.com> | 2020-02-25 15:03:07 +0200 |
| commit | 0947b64287f7dd39310b7da10c7d8675c090b230 (patch) | |
| tree | cfcd69bbd2eb6a9fb7a674e548a08904fcd6a415 /backend/src/authn.js | |
| parent | 72b5fc9357f0100f4cc560c1430f7ea2d849eb40 (diff) | |
yepmaster
Diffstat (limited to 'backend/src/authn.js')
| -rw-r--r-- | backend/src/authn.js | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/backend/src/authn.js b/backend/src/authn.js index 52ba862..78703bb 100644 --- a/backend/src/authn.js +++ b/backend/src/authn.js @@ -107,24 +107,19 @@ const registerRoute = async (req, res) => { const salt = shortid.generate(); const pwHash = sha512(salt + password); - const sessionToken = shortid.generate(); - const sessionTokenHash = sha512(salt + sessionToken); - const insertedUsers = await db('users').insert({ username, password: pwHash, email, salt }).returning('*'); const user = insertedUsers[0]; const activationToken = shortid.generate(); await db('tokens').insert({ user_id: user.id, type: 'activation', value: activationToken }); - // await db('tokens').insert({ user_id: user.id, type: 'session', value: sessionTokenHash }); - // res.set('Set-Cookie', buildSessionCookie({ username, sessionToken, remember: false, isLogout: false })); - await consoleBackend.send({ recipients: [ username ], subject: `Welcome to the service, ${username}!`, body: `Welcome.\n\nActivate your account at http://localhost:3000/activate/${activationToken}.\n\nBR,\nTeam`, }); + res.set('Set-Cookie', buildSessionCookie({ isLogout: true })); return res.json({ username, }); @@ -142,7 +137,7 @@ const loginRoute = async (req, res) => { const user = await db('users').where({ username }).first(); if (!user) { res.status(400); - res.json({ + return res.json({ error: 'Wrong username or password', }); } @@ -152,16 +147,14 @@ const loginRoute = async (req, res) => { if (pwHash !== user.password) { res.status(400); - res.json({ + return res.json({ error: 'Wrong username or password', }); } const sessionToken = shortid.generate(); const sessionTokenHash = sha512(user.salt + sessionToken); - await db('tokens').insert({ user_id: user.id, type: 'session', value: sessionTokenHash }); - res.set('Set-Cookie', buildSessionCookie({ username, sessionToken, isLogout: false })); return res.json({ |
