aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorPitu <[email protected]>2019-02-28 23:26:44 +0900
committerPitu <[email protected]>2019-02-28 23:26:44 +0900
commitc169ab6dc1727c7ca5dd45fcaeb419b44cbf1908 (patch)
tree48ff7a4efad6c421caa27ce762041466ad36eea2 /src/api
parentChange password and api keys (diff)
downloadhost.fuwn.me-c169ab6dc1727c7ca5dd45fcaeb419b44cbf1908.tar.xz
host.fuwn.me-c169ab6dc1727c7ca5dd45fcaeb419b44cbf1908.zip
Some stuff
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/auth/changePasswordPOST.js39
-rw-r--r--src/api/routes/auth/loginPOST.js7
-rw-r--r--src/api/routes/service/configGET.js28
-rw-r--r--src/api/routes/service/restartPOST.js14
4 files changed, 48 insertions, 40 deletions
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
});
diff --git a/src/api/routes/service/configGET.js b/src/api/routes/service/configGET.js
new file mode 100644
index 0000000..230b594
--- /dev/null
+++ b/src/api/routes/service/configGET.js
@@ -0,0 +1,28 @@
+const Route = require('../../structures/Route');
+
+class configGET extends Route {
+ constructor() {
+ super('/service/config', 'get', { adminOnly: true });
+ }
+
+ run(req, res) {
+ return res.json({
+ message: 'Successfully retrieved config',
+ config: {
+ serviceName: process.env.SERVICE_NAME,
+ uploadFolder: process.env.UPLOAD_FOLDER,
+ linksPerAlbum: process.env.MAX_LINKS_PER_ALBUM,
+ maxUploadSize: process.env.MAX_SIZE,
+ filenameLength: process.env.GENERATED_FILENAME_LENGTH,
+ albumLinkLength: process.env.GENERATED_ALBUM_LENGTH,
+ generateThumbnails: process.env.GENERATE_THUMBNAILS,
+ generateZips: process.env.GENERATE_ZIPS,
+ stripExif: process.env.STRIP_EXIF,
+ publicMode: process.env.PUBLIC_MODE,
+ enableAccounts: process.env.USER_ACCOUNTS
+ }
+ });
+ }
+}
+
+module.exports = configGET;
diff --git a/src/api/routes/service/restartPOST.js b/src/api/routes/service/restartPOST.js
new file mode 100644
index 0000000..530cc91
--- /dev/null
+++ b/src/api/routes/service/restartPOST.js
@@ -0,0 +1,14 @@
+const Route = require('../../structures/Route');
+
+class restartPOST extends Route {
+ constructor() {
+ super('/service/restart', 'post', { adminOnly: true });
+ }
+
+ run(req, res) {
+ res.json({ message: 'Restarting...' });
+ process.exit(0);
+ }
+}
+
+module.exports = restartPOST;