From e7767ac7095f93393a627fd5e867af4a1ca4b011 Mon Sep 17 00:00:00 2001 From: Pitu <7425261+Pitu@users.noreply.github.com> Date: Sun, 16 Sep 2018 00:56:13 -0300 Subject: Routes --- src/api/routes/auth/apiKey.js | 23 ++++++++++++++ src/api/routes/auth/changePasswordPOST.js | 41 ++++++++++++++++++++++++ src/api/routes/auth/loginPOST.js | 39 +++++++++++++++++++++++ src/api/routes/auth/registerPOST.js | 53 +++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 src/api/routes/auth/apiKey.js create mode 100644 src/api/routes/auth/changePasswordPOST.js create mode 100644 src/api/routes/auth/loginPOST.js create mode 100644 src/api/routes/auth/registerPOST.js (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/apiKey.js b/src/api/routes/auth/apiKey.js new file mode 100644 index 0000000..84df2e3 --- /dev/null +++ b/src/api/routes/auth/apiKey.js @@ -0,0 +1,23 @@ +const Route = require('../../structures/Route'); + +class apiKeyGET extends Route { + constructor() { + super('/auth/apiKey', 'get'); + } + + run(req, res, user) { + return res.json({ message: 'Hai hai api works.' }); + } +} + +class apiKeyPOST extends Route { + constructor() { + super('/auth/apiKey', 'post'); + } + + run(req, res, user) { + return res.json({ message: 'Hai hai api works.' }); + } +} + +module.exports = [apiKeyGET, apiKeyPOST]; diff --git a/src/api/routes/auth/changePasswordPOST.js b/src/api/routes/auth/changePasswordPOST.js new file mode 100644 index 0000000..bd64320 --- /dev/null +++ b/src/api/routes/auth/changePasswordPOST.js @@ -0,0 +1,41 @@ +const Route = require('../../structures/Route'); +const config = require('../../../../config'); +const log = require('../../utils/Log'); +const db = require('knex')(config.server.database); +const bcrypt = require('bcrypt'); +const moment = require('moment'); + +class changePasswordPOST extends Route { + constructor() { + super('/auth/password/change', 'post'); + } + + async run(req, res, user) { + if (!req.body) return res.status(400).json({ message: 'No body provided' }); + const { password, newPassword } = req.body; + if (!password || !newPassword) return res.status(401).json({ message: 'Invalid body provided' }); + + if (newPassword.length < 6 || newPassword.length > 64) { + return res.status(400).json({ message: 'Password must have 6-64 characters' }); + } + + let hash; + try { + hash = await bcrypt.hash(newPassword, 10); + } catch (error) { + log.error('Error generating password hash'); + log.error(error); + return res.status(401).json({ message: 'There was a problem processing your account' }); + } + + const now = moment.utc().toDate(); + await db.table('users').where('id', user.id).update({ + password: hash, + passwordEditedAt: now + }); + + return res.json({ message: 'The password was changed successfully' }); + } +} + +module.exports = changePasswordPOST; diff --git a/src/api/routes/auth/loginPOST.js b/src/api/routes/auth/loginPOST.js new file mode 100644 index 0000000..7e85812 --- /dev/null +++ b/src/api/routes/auth/loginPOST.js @@ -0,0 +1,39 @@ +const Route = require('../../structures/Route'); +const config = require('../../../../config'); +const db = require('knex')(config.server.database); +const bcrypt = require('bcrypt'); +const moment = require('moment'); +const JWT = require('jsonwebtoken'); + +class loginPOST extends Route { + constructor() { + super('/auth/login', 'post', { bypassAuth: true }); + } + + async run(req, res) { + if (!req.body) return res.status(400).json({ message: 'No body provided' }); + const { username, password } = req.body; + if (!username || !password) return res.status(401).json({ message: 'Invalid body provided' }); + + const user = await db.table('users').where('username', username).first(); + if (!user) return res.status(401).json({ message: 'Invalid authorization' }); + + const comparePassword = await bcrypt.compare(password, user.password); + if (!comparePassword) return res.status(401).json({ message: 'Invalid authorization.' }); + + const jwt = JWT.sign({ + iss: 'lolisafe', + sub: user.id, + iat: moment.utc().valueOf() + }, config.server.secret, { expiresIn: '30d' }); + + return res.json({ + message: 'Successfully logged in.', + user: { username: user.username }, + token: jwt, + apiKey: user.apiKey + }); + } +} + +module.exports = loginPOST; diff --git a/src/api/routes/auth/registerPOST.js b/src/api/routes/auth/registerPOST.js new file mode 100644 index 0000000..dad45fd --- /dev/null +++ b/src/api/routes/auth/registerPOST.js @@ -0,0 +1,53 @@ +const Route = require('../../structures/Route'); +const config = require('../../../../config'); +const log = require('../../utils/Log'); +const db = require('knex')(config.server.database); +const bcrypt = require('bcrypt'); +const randomstring = require('randomstring'); +const moment = require('moment'); + +class registerPOST extends Route { + constructor() { + super('/auth/register', 'post', { bypassAuth: true }); + } + + async run(req, res) { + if (!config.enableCreateUserAccounts) return res.status(401).json({ message: 'Creation of new accounts is currently disabled' }); + if (!req.body) return res.status(400).json({ message: 'No body provided' }); + const { username, password } = req.body; + if (!username || !password) return res.status(401).json({ message: 'Invalid body provided' }); + + if (username.length < 4 || username.length > 32) { + return res.status(400).json({ message: 'Username must have 4-32 characters' }); + } + if (password.length < 6 || password.length > 64) { + return res.status(400).json({ message: 'Password must have 6-64 characters' }); + } + + const user = await db.table('users').where('username', username).first(); + if (user) return res.status(401).json({ message: 'Username already exists' }); + + let hash; + try { + hash = await bcrypt.hash(password, 10); + } catch (error) { + log.error('Error generating password hash'); + log.error(error); + return res.status(401).json({ message: 'There was a problem processing your account' }); + } + + const now = moment.utc().toDate(); + await db.table('users').insert({ + username, + password: hash, + passwordEditedAt: now, + apiKey: randomstring.generate(64), + apiKeyEditedAt: now, + createdAt: now, + editedAt: now + }); + return res.json({ message: 'The account was created successfully' }); + } +} + +module.exports = registerPOST; -- cgit v1.2.3 From f2c885b718528d42df412e612520fb471c46d0bd Mon Sep 17 00:00:00 2001 From: Pitu <7425261+Pitu@users.noreply.github.com> Date: Mon, 17 Sep 2018 04:55:42 -0300 Subject: Commented all the code --- src/api/routes/auth/loginPOST.js | 9 +++++++++ src/api/routes/auth/registerPOST.js | 9 +++++++++ 2 files changed, 18 insertions(+) (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/loginPOST.js b/src/api/routes/auth/loginPOST.js index 7e85812..eaf09e8 100644 --- a/src/api/routes/auth/loginPOST.js +++ b/src/api/routes/auth/loginPOST.js @@ -15,12 +15,21 @@ class loginPOST extends Route { const { username, password } = req.body; if (!username || !password) return res.status(401).json({ message: 'Invalid body provided' }); + /* + Checks if the user exists + */ const user = await db.table('users').where('username', username).first(); if (!user) return res.status(401).json({ message: 'Invalid authorization' }); + /* + Checks if the password is right + */ const comparePassword = await bcrypt.compare(password, user.password); if (!comparePassword) return res.status(401).json({ message: 'Invalid authorization.' }); + /* + Create the jwt with some data + */ const jwt = JWT.sign({ iss: 'lolisafe', sub: user.id, diff --git a/src/api/routes/auth/registerPOST.js b/src/api/routes/auth/registerPOST.js index dad45fd..d3532f4 100644 --- a/src/api/routes/auth/registerPOST.js +++ b/src/api/routes/auth/registerPOST.js @@ -24,9 +24,15 @@ class registerPOST extends Route { return res.status(400).json({ message: 'Password must have 6-64 characters' }); } + /* + Make sure the username doesn't exist yet + */ const user = await db.table('users').where('username', username).first(); if (user) return res.status(401).json({ message: 'Username already exists' }); + /* + Hash the supplied password + */ let hash; try { hash = await bcrypt.hash(password, 10); @@ -36,6 +42,9 @@ class registerPOST extends Route { return res.status(401).json({ message: 'There was a problem processing your account' }); } + /* + Create the user + */ const now = moment.utc().toDate(); await db.table('users').insert({ username, -- cgit v1.2.3 From 89a271818ed25b0a17a17dd1d6804e34d1f2ec0f Mon Sep 17 00:00:00 2001 From: Pitu Date: Tue, 19 Feb 2019 23:52:24 +0900 Subject: Switch config to .env --- src/api/routes/auth/changePasswordPOST.js | 4 +--- src/api/routes/auth/registerPOST.js | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/changePasswordPOST.js b/src/api/routes/auth/changePasswordPOST.js index bd64320..d698896 100644 --- a/src/api/routes/auth/changePasswordPOST.js +++ b/src/api/routes/auth/changePasswordPOST.js @@ -1,7 +1,5 @@ const Route = require('../../structures/Route'); -const config = require('../../../../config'); const log = require('../../utils/Log'); -const db = require('knex')(config.server.database); const bcrypt = require('bcrypt'); const moment = require('moment'); @@ -10,7 +8,7 @@ class changePasswordPOST extends Route { super('/auth/password/change', 'post'); } - async run(req, res, user) { + async run(req, res, db, user) { if (!req.body) return res.status(400).json({ message: 'No body provided' }); const { password, newPassword } = req.body; if (!password || !newPassword) return res.status(401).json({ message: 'Invalid body provided' }); diff --git a/src/api/routes/auth/registerPOST.js b/src/api/routes/auth/registerPOST.js index d3532f4..762eaf2 100644 --- a/src/api/routes/auth/registerPOST.js +++ b/src/api/routes/auth/registerPOST.js @@ -1,7 +1,5 @@ const Route = require('../../structures/Route'); -const config = require('../../../../config'); const log = require('../../utils/Log'); -const db = require('knex')(config.server.database); const bcrypt = require('bcrypt'); const randomstring = require('randomstring'); const moment = require('moment'); @@ -11,8 +9,8 @@ class registerPOST extends Route { super('/auth/register', 'post', { bypassAuth: true }); } - async run(req, res) { - if (!config.enableCreateUserAccounts) return res.status(401).json({ message: 'Creation of new accounts is currently disabled' }); + async run(req, res, db) { + if (!process.env.USER_ACCOUNTS) return res.status(401).json({ message: 'Creation of new accounts is currently disabled' }); if (!req.body) return res.status(400).json({ message: 'No body provided' }); const { username, password } = req.body; if (!username || !password) return res.status(401).json({ message: 'Invalid body provided' }); -- cgit v1.2.3 From a284a9a0645774547d9b56887504cd72161e11ff Mon Sep 17 00:00:00 2001 From: Pitu Date: Fri, 22 Feb 2019 00:37:20 +0900 Subject: Leftovers --- src/api/routes/auth/loginPOST.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/loginPOST.js b/src/api/routes/auth/loginPOST.js index eaf09e8..760e54b 100644 --- a/src/api/routes/auth/loginPOST.js +++ b/src/api/routes/auth/loginPOST.js @@ -1,6 +1,4 @@ const Route = require('../../structures/Route'); -const config = require('../../../../config'); -const db = require('knex')(config.server.database); const bcrypt = require('bcrypt'); const moment = require('moment'); const JWT = require('jsonwebtoken'); @@ -10,7 +8,7 @@ class loginPOST extends Route { super('/auth/login', 'post', { bypassAuth: true }); } - async run(req, res) { + async run(req, res, db) { if (!req.body) return res.status(400).json({ message: 'No body provided' }); const { username, password } = req.body; if (!username || !password) return res.status(401).json({ message: 'Invalid body provided' }); @@ -34,7 +32,7 @@ class loginPOST extends Route { iss: 'lolisafe', sub: user.id, iat: moment.utc().valueOf() - }, config.server.secret, { expiresIn: '30d' }); + }, process.env.SECRET, { expiresIn: '30d' }); return res.json({ message: 'Successfully logged in.', -- cgit v1.2.3 From fc95cb7b0f047806937c25f0fc1104c72b0a32cb Mon Sep 17 00:00:00 2001 From: Pitu Date: Sat, 23 Feb 2019 00:45:45 +0900 Subject: Better DB handling and stuff --- src/api/routes/auth/registerPOST.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/registerPOST.js b/src/api/routes/auth/registerPOST.js index 762eaf2..ee8e5ae 100644 --- a/src/api/routes/auth/registerPOST.js +++ b/src/api/routes/auth/registerPOST.js @@ -51,7 +51,9 @@ class registerPOST extends Route { apiKey: randomstring.generate(64), apiKeyEditedAt: now, createdAt: now, - editedAt: now + editedAt: now, + enabled: true, + isAdmin: false }); return res.json({ message: 'The account was created successfully' }); } -- cgit v1.2.3 From f37d20694386e59622fdfab586a9b580011efce6 Mon Sep 17 00:00:00 2001 From: Pitu Date: Thu, 28 Feb 2019 23:26:28 +0900 Subject: Change password and api keys --- src/api/routes/auth/apiKey.js | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 src/api/routes/auth/apiKey.js (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/apiKey.js b/src/api/routes/auth/apiKey.js deleted file mode 100644 index 84df2e3..0000000 --- a/src/api/routes/auth/apiKey.js +++ /dev/null @@ -1,23 +0,0 @@ -const Route = require('../../structures/Route'); - -class apiKeyGET extends Route { - constructor() { - super('/auth/apiKey', 'get'); - } - - run(req, res, user) { - return res.json({ message: 'Hai hai api works.' }); - } -} - -class apiKeyPOST extends Route { - constructor() { - super('/auth/apiKey', 'post'); - } - - run(req, res, user) { - return res.json({ message: 'Hai hai api works.' }); - } -} - -module.exports = [apiKeyGET, apiKeyPOST]; -- cgit v1.2.3 From c169ab6dc1727c7ca5dd45fcaeb419b44cbf1908 Mon Sep 17 00:00:00 2001 From: Pitu Date: Thu, 28 Feb 2019 23:26:44 +0900 Subject: Some stuff --- src/api/routes/auth/changePasswordPOST.js | 39 ------------------------------- src/api/routes/auth/loginPOST.js | 7 +++++- 2 files changed, 6 insertions(+), 40 deletions(-) delete mode 100644 src/api/routes/auth/changePasswordPOST.js (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/changePasswordPOST.js b/src/api/routes/auth/changePasswordPOST.js deleted file mode 100644 index d698896..0000000 --- a/src/api/routes/auth/changePasswordPOST.js +++ /dev/null @@ -1,39 +0,0 @@ -const Route = require('../../structures/Route'); -const log = require('../../utils/Log'); -const bcrypt = require('bcrypt'); -const moment = require('moment'); - -class changePasswordPOST extends Route { - constructor() { - super('/auth/password/change', 'post'); - } - - async run(req, res, db, user) { - if (!req.body) return res.status(400).json({ message: 'No body provided' }); - const { password, newPassword } = req.body; - if (!password || !newPassword) return res.status(401).json({ message: 'Invalid body provided' }); - - if (newPassword.length < 6 || newPassword.length > 64) { - return res.status(400).json({ message: 'Password must have 6-64 characters' }); - } - - let hash; - try { - hash = await bcrypt.hash(newPassword, 10); - } catch (error) { - log.error('Error generating password hash'); - log.error(error); - return res.status(401).json({ message: 'There was a problem processing your account' }); - } - - const now = moment.utc().toDate(); - await db.table('users').where('id', user.id).update({ - password: hash, - passwordEditedAt: now - }); - - return res.json({ message: 'The password was changed successfully' }); - } -} - -module.exports = changePasswordPOST; diff --git a/src/api/routes/auth/loginPOST.js b/src/api/routes/auth/loginPOST.js index 760e54b..38bbc49 100644 --- a/src/api/routes/auth/loginPOST.js +++ b/src/api/routes/auth/loginPOST.js @@ -36,7 +36,12 @@ class loginPOST extends Route { return res.json({ message: 'Successfully logged in.', - user: { username: user.username }, + user: { + id: user.id, + username: user.username, + apiKey: user.apiKey, + isAdmin: user.isAdmin + }, token: jwt, apiKey: user.apiKey }); -- cgit v1.2.3 From 9cba85c47cfde1decbee513e48f82deff27a438d Mon Sep 17 00:00:00 2001 From: Pitu Date: Thu, 28 Feb 2019 23:52:04 +0900 Subject: changes --- src/api/routes/auth/loginPOST.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/loginPOST.js b/src/api/routes/auth/loginPOST.js index 38bbc49..205737a 100644 --- a/src/api/routes/auth/loginPOST.js +++ b/src/api/routes/auth/loginPOST.js @@ -19,6 +19,11 @@ class loginPOST extends Route { const user = await db.table('users').where('username', username).first(); if (!user) return res.status(401).json({ message: 'Invalid authorization' }); + /* + Checks if the user is disabled + */ + if (!user.enabled) return res.status(401).json({ message: 'This account has been disabled' }); + /* Checks if the password is right */ -- cgit v1.2.3 From 73d85e8c7938e1db30da3cc4354b143d4a078473 Mon Sep 17 00:00:00 2001 From: Pitu Date: Sat, 2 Mar 2019 02:08:11 +0900 Subject: Enviroment variables parsing fix --- src/api/routes/auth/registerPOST.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/registerPOST.js b/src/api/routes/auth/registerPOST.js index ee8e5ae..0bd8cfd 100644 --- a/src/api/routes/auth/registerPOST.js +++ b/src/api/routes/auth/registerPOST.js @@ -10,7 +10,7 @@ class registerPOST extends Route { } async run(req, res, db) { - if (!process.env.USER_ACCOUNTS) return res.status(401).json({ message: 'Creation of new accounts is currently disabled' }); + if (process.env.USER_ACCOUNTS == 'false') return res.status(401).json({ message: 'Creation of new accounts is currently disabled' }); if (!req.body) return res.status(400).json({ message: 'No body provided' }); const { username, password } = req.body; if (!username || !password) return res.status(401).json({ message: 'Invalid body provided' }); -- cgit v1.2.3 From 107d1f4750e8f82a628b528c4ec200e918be271d Mon Sep 17 00:00:00 2001 From: Pitu Date: Tue, 19 Mar 2019 07:58:36 +0000 Subject: API key WIP --- src/api/routes/auth/registerPOST.js | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/registerPOST.js b/src/api/routes/auth/registerPOST.js index 0bd8cfd..feeb360 100644 --- a/src/api/routes/auth/registerPOST.js +++ b/src/api/routes/auth/registerPOST.js @@ -1,7 +1,6 @@ const Route = require('../../structures/Route'); const log = require('../../utils/Log'); const bcrypt = require('bcrypt'); -const randomstring = require('randomstring'); const moment = require('moment'); class registerPOST extends Route { @@ -48,8 +47,6 @@ class registerPOST extends Route { username, password: hash, passwordEditedAt: now, - apiKey: randomstring.generate(64), - apiKeyEditedAt: now, createdAt: now, editedAt: now, enabled: true, -- cgit v1.2.3 From de54e19d3a102cad6364a6f9f50dab48c2367683 Mon Sep 17 00:00:00 2001 From: Pitu Date: Sun, 10 May 2020 00:03:45 +0900 Subject: chore: remove the use of uuid --- src/api/routes/auth/registerPOST.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/registerPOST.js b/src/api/routes/auth/registerPOST.js index feeb360..0500ff6 100644 --- a/src/api/routes/auth/registerPOST.js +++ b/src/api/routes/auth/registerPOST.js @@ -2,6 +2,7 @@ const Route = require('../../structures/Route'); const log = require('../../utils/Log'); const bcrypt = require('bcrypt'); const moment = require('moment'); +const uuidv4 = require('uuid/v4'); class registerPOST extends Route { constructor() { @@ -44,6 +45,7 @@ class registerPOST extends Route { */ const now = moment.utc().toDate(); await db.table('users').insert({ + uuid: uuidv4(), username, password: hash, passwordEditedAt: now, -- cgit v1.2.3 From ec67bb808773bed7fa5c39bd696d8f635fff6c42 Mon Sep 17 00:00:00 2001 From: Pitu Date: Sun, 10 May 2020 22:44:21 +0900 Subject: fix: remove uuid from user registration --- src/api/routes/auth/registerPOST.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/registerPOST.js b/src/api/routes/auth/registerPOST.js index 0500ff6..feeb360 100644 --- a/src/api/routes/auth/registerPOST.js +++ b/src/api/routes/auth/registerPOST.js @@ -2,7 +2,6 @@ const Route = require('../../structures/Route'); const log = require('../../utils/Log'); const bcrypt = require('bcrypt'); const moment = require('moment'); -const uuidv4 = require('uuid/v4'); class registerPOST extends Route { constructor() { @@ -45,7 +44,6 @@ class registerPOST extends Route { */ const now = moment.utc().toDate(); await db.table('users').insert({ - uuid: uuidv4(), username, password: hash, passwordEditedAt: now, -- cgit v1.2.3 From ad852de51a0d2dd5d29c08838d5a430c58849e74 Mon Sep 17 00:00:00 2001 From: Zephyrrus Date: Wed, 8 Jul 2020 04:00:12 +0300 Subject: chore: linter the entire project using the new rules --- src/api/routes/auth/loginPOST.js | 8 ++++---- src/api/routes/auth/registerPOST.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/loginPOST.js b/src/api/routes/auth/loginPOST.js index 205737a..5c7730c 100644 --- a/src/api/routes/auth/loginPOST.js +++ b/src/api/routes/auth/loginPOST.js @@ -1,7 +1,7 @@ -const Route = require('../../structures/Route'); const bcrypt = require('bcrypt'); const moment = require('moment'); const JWT = require('jsonwebtoken'); +const Route = require('../../structures/Route'); class loginPOST extends Route { constructor() { @@ -36,7 +36,7 @@ class loginPOST extends Route { const jwt = JWT.sign({ iss: 'lolisafe', sub: user.id, - iat: moment.utc().valueOf() + iat: moment.utc().valueOf(), }, process.env.SECRET, { expiresIn: '30d' }); return res.json({ @@ -45,10 +45,10 @@ class loginPOST extends Route { id: user.id, username: user.username, apiKey: user.apiKey, - isAdmin: user.isAdmin + isAdmin: user.isAdmin, }, token: jwt, - apiKey: user.apiKey + apiKey: user.apiKey, }); } } diff --git a/src/api/routes/auth/registerPOST.js b/src/api/routes/auth/registerPOST.js index feeb360..e2ac018 100644 --- a/src/api/routes/auth/registerPOST.js +++ b/src/api/routes/auth/registerPOST.js @@ -1,7 +1,7 @@ -const Route = require('../../structures/Route'); -const log = require('../../utils/Log'); const bcrypt = require('bcrypt'); const moment = require('moment'); +const Route = require('../../structures/Route'); +const log = require('../../utils/Log'); class registerPOST extends Route { constructor() { @@ -9,7 +9,7 @@ class registerPOST extends Route { } async run(req, res, db) { - if (process.env.USER_ACCOUNTS == 'false') return res.status(401).json({ message: 'Creation of new accounts is currently disabled' }); + if (process.env.USER_ACCOUNTS === 'false') return res.status(401).json({ message: 'Creation of new accounts is currently disabled' }); if (!req.body) return res.status(400).json({ message: 'No body provided' }); const { username, password } = req.body; if (!username || !password) return res.status(401).json({ message: 'Invalid body provided' }); @@ -50,7 +50,7 @@ class registerPOST extends Route { createdAt: now, editedAt: now, enabled: true, - isAdmin: false + isAdmin: false, }); return res.json({ message: 'The account was created successfully' }); } -- cgit v1.2.3 From 90001c2df56d58e69fd199a518ae7f3e4ed327fc Mon Sep 17 00:00:00 2001 From: Zephyrrus Date: Thu, 24 Dec 2020 10:40:50 +0200 Subject: chore: remove trailing commas --- src/api/routes/auth/loginPOST.js | 6 +++--- src/api/routes/auth/registerPOST.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/loginPOST.js b/src/api/routes/auth/loginPOST.js index 5c7730c..71867f0 100644 --- a/src/api/routes/auth/loginPOST.js +++ b/src/api/routes/auth/loginPOST.js @@ -36,7 +36,7 @@ class loginPOST extends Route { const jwt = JWT.sign({ iss: 'lolisafe', sub: user.id, - iat: moment.utc().valueOf(), + iat: moment.utc().valueOf() }, process.env.SECRET, { expiresIn: '30d' }); return res.json({ @@ -45,10 +45,10 @@ class loginPOST extends Route { id: user.id, username: user.username, apiKey: user.apiKey, - isAdmin: user.isAdmin, + isAdmin: user.isAdmin }, token: jwt, - apiKey: user.apiKey, + apiKey: user.apiKey }); } } diff --git a/src/api/routes/auth/registerPOST.js b/src/api/routes/auth/registerPOST.js index e2ac018..1cf3630 100644 --- a/src/api/routes/auth/registerPOST.js +++ b/src/api/routes/auth/registerPOST.js @@ -50,7 +50,7 @@ class registerPOST extends Route { createdAt: now, editedAt: now, enabled: true, - isAdmin: false, + isAdmin: false }); return res.json({ message: 'The account was created successfully' }); } -- cgit v1.2.3 From ec2f9e0d989792c1760b48e063467cf6e59c580a Mon Sep 17 00:00:00 2001 From: Pitu Date: Fri, 25 Dec 2020 20:45:22 +0900 Subject: Rebrand --- src/api/routes/auth/loginPOST.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/api/routes/auth') diff --git a/src/api/routes/auth/loginPOST.js b/src/api/routes/auth/loginPOST.js index 71867f0..373252b 100644 --- a/src/api/routes/auth/loginPOST.js +++ b/src/api/routes/auth/loginPOST.js @@ -34,7 +34,7 @@ class loginPOST extends Route { Create the jwt with some data */ const jwt = JWT.sign({ - iss: 'lolisafe', + iss: 'chibisafe', sub: user.id, iat: moment.utc().valueOf() }, process.env.SECRET, { expiresIn: '30d' }); -- cgit v1.2.3