aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes/user/apiKey.js
diff options
context:
space:
mode:
authorPitu <[email protected]>2019-02-28 23:26:28 +0900
committerPitu <[email protected]>2019-02-28 23:26:28 +0900
commitf37d20694386e59622fdfab586a9b580011efce6 (patch)
treea59d69e97ccabba0d8e3ff1ba0bfc8f4341b9acd /src/api/routes/user/apiKey.js
parentWhen a call regarding the token fails, logout (diff)
downloadhost.fuwn.me-f37d20694386e59622fdfab586a9b580011efce6.tar.xz
host.fuwn.me-f37d20694386e59622fdfab586a9b580011efce6.zip
Change password and api keys
Diffstat (limited to 'src/api/routes/user/apiKey.js')
-rw-r--r--src/api/routes/user/apiKey.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/api/routes/user/apiKey.js b/src/api/routes/user/apiKey.js
new file mode 100644
index 0000000..820e28c
--- /dev/null
+++ b/src/api/routes/user/apiKey.js
@@ -0,0 +1,27 @@
+const Route = require('../../structures/Route');
+const randomstring = require('randomstring');
+const moment = require('moment');
+
+class apiKeyPOST extends Route {
+ constructor() {
+ super('/user/apikey/change', 'post');
+ }
+
+ async run(req, res, db, user) {
+ const now = moment.utc().toDate();
+ const apiKey = randomstring.generate(64);
+ await db.table('users')
+ .where({ id: user.id })
+ .update({
+ apiKey,
+ apiKeyEditedAt: now
+ });
+
+ return res.json({
+ message: 'Successfully created new api key',
+ apiKey
+ });
+ }
+}
+
+module.exports = apiKeyPOST;