From 7a74647d3e5b5681b9d5d3fa9b6e12d062232683 Mon Sep 17 00:00:00 2001 From: Pitu Date: Tue, 26 Feb 2019 23:13:24 +0900 Subject: [PATCH] User management --- src/api/routes/admin/userDemote.js | 6 +- src/api/routes/admin/userDisable.js | 27 +++ src/api/routes/admin/userEnable.js | 27 +++ src/api/routes/admin/userPromote.js | 4 +- src/site/components/sidebar/Sidebar.vue | 24 ++- src/site/pages/dashboard/users.vue | 257 ++++++++++++++++++++++++ 6 files changed, 332 insertions(+), 13 deletions(-) create mode 100644 src/api/routes/admin/userDisable.js create mode 100644 src/api/routes/admin/userEnable.js create mode 100644 src/site/pages/dashboard/users.vue diff --git a/src/api/routes/admin/userDemote.js b/src/api/routes/admin/userDemote.js index e9c37a0..fa288fc 100644 --- a/src/api/routes/admin/userDemote.js +++ b/src/api/routes/admin/userDemote.js @@ -2,13 +2,13 @@ const Route = require('../../structures/Route'); class userDemote extends Route { constructor() { - super('/admin/users/demote', 'get', { adminOnly: true }); + super('/admin/users/demote', 'post', { adminOnly: true }); } async run(req, res, db) { if (!req.body) return res.status(400).json({ message: 'No body provided' }); const { id } = req.body; - if (!id) return res.status(400).json({ message: 'No name provided' }); + if (!id) return res.status(400).json({ message: 'No id provided' }); try { await db.table('users') @@ -19,7 +19,7 @@ class userDemote extends Route { } return res.json({ - message: 'Successfully promoted user' + message: 'Successfully demoted user' }); } } diff --git a/src/api/routes/admin/userDisable.js b/src/api/routes/admin/userDisable.js new file mode 100644 index 0000000..c7dffa8 --- /dev/null +++ b/src/api/routes/admin/userDisable.js @@ -0,0 +1,27 @@ +const Route = require('../../structures/Route'); + +class userDisable extends Route { + constructor() { + super('/admin/users/disable', 'post', { adminOnly: true }); + } + + async run(req, res, db) { + if (!req.body) return res.status(400).json({ message: 'No body provided' }); + const { id } = req.body; + if (!id) return res.status(400).json({ message: 'No id provided' }); + + try { + await db.table('users') + .where({ id }) + .update({ enabled: false }); + } catch (error) { + return super.error(res, error); + } + + return res.json({ + message: 'Successfully disabled user' + }); + } +} + +module.exports = userDisable; diff --git a/src/api/routes/admin/userEnable.js b/src/api/routes/admin/userEnable.js new file mode 100644 index 0000000..7e5743d --- /dev/null +++ b/src/api/routes/admin/userEnable.js @@ -0,0 +1,27 @@ +const Route = require('../../structures/Route'); + +class userEnable extends Route { + constructor() { + super('/admin/users/enable', 'post', { adminOnly: true }); + } + + async run(req, res, db) { + if (!req.body) return res.status(400).json({ message: 'No body provided' }); + const { id } = req.body; + if (!id) return res.status(400).json({ message: 'No id provided' }); + + try { + await db.table('users') + .where({ id }) + .update({ enabled: true }); + } catch (error) { + return super.error(res, error); + } + + return res.json({ + message: 'Successfully enabled user' + }); + } +} + +module.exports = userEnable; diff --git a/src/api/routes/admin/userPromote.js b/src/api/routes/admin/userPromote.js index caae176..4062dfa 100644 --- a/src/api/routes/admin/userPromote.js +++ b/src/api/routes/admin/userPromote.js @@ -2,13 +2,13 @@ const Route = require('../../structures/Route'); class userPromote extends Route { constructor() { - super('/admin/users/promote', 'get', { adminOnly: true }); + super('/admin/users/promote', 'post', { adminOnly: true }); } async run(req, res, db) { if (!req.body) return res.status(400).json({ message: 'No body provided' }); const { id } = req.body; - if (!id) return res.status(400).json({ message: 'No name provided' }); + if (!id) return res.status(400).json({ message: 'No id provided' }); try { await db.table('users') diff --git a/src/site/components/sidebar/Sidebar.vue b/src/site/components/sidebar/Sidebar.vue index 3317eca..cf3fc4b 100644 --- a/src/site/components/sidebar/Sidebar.vue +++ b/src/site/components/sidebar/Sidebar.vue @@ -44,15 +44,23 @@ Account -
- - Users - - - Settings - + diff --git a/src/site/pages/dashboard/users.vue b/src/site/pages/dashboard/users.vue new file mode 100644 index 0000000..df16918 --- /dev/null +++ b/src/site/pages/dashboard/users.vue @@ -0,0 +1,257 @@ + + + + + + +