aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentChange password and api keys (diff)
downloadhost.fuwn.me-c169ab6dc1727c7ca5dd45fcaeb419b44cbf1908.tar.xz
host.fuwn.me-c169ab6dc1727c7ca5dd45fcaeb419b44cbf1908.zip
Some stuff
Diffstat (limited to 'src')
-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
-rw-r--r--src/site/assets/styles/style.scss77
-rw-r--r--src/site/pages/dashboard/settings.vue42
-rw-r--r--src/site/pages/dashboard/users.vue6
7 files changed, 105 insertions, 108 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;
diff --git a/src/site/assets/styles/style.scss b/src/site/assets/styles/style.scss
index 71ce27b..b85602b 100644
--- a/src/site/assets/styles/style.scss
+++ b/src/site/assets/styles/style.scss
@@ -1,29 +1,6 @@
// Let's first take care of having the customized colors ready.
@import "./_colors.scss";
-// Loading screen is the first thing that shows up, let's put it at the top.
-div#loading {
- position: absolute;
- top: 0;
- left: 0;
- z-index: 100;
- height: 100%;
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: center;
-
- div.background {
- position: absolute;
- z-index: -1;
- height: 100%;
- width: 100%;
- top: 0px;
- left: 0px;
- background: $background;
- }
-}
-
// Bulma/Buefy customization
@import "../../../node_modules/bulma/sass/utilities/_all.sass";
@@ -34,33 +11,6 @@ $size-normal: 1rem;
@import "../../../node_modules/bulma/bulma.sass";
@import "../../../node_modules/buefy/src/scss/buefy.scss";
-/*
-.material-icons {
- font-family: 'Material Icons';
- font-weight: normal;
- font-style: normal;
- font-size: 24px;
- line-height: 1;
- letter-spacing: normal;
- text-transform: none;
- display: inline-block;
- white-space: nowrap;
- word-wrap: normal;
- direction: ltr;
- font-feature-settings: "liga";
- -webkit-font-feature-settings: 'liga';
- -webkit-font-smoothing: antialiased;
-}
-*/
-
-/*
-*,
-*::before,
-*::after {
- box-sizing: border-box;
- text-rendering: optimizeLegibility;
-}
-*/
html {
// font-size: 100%;
font-size: 14px;
@@ -73,16 +23,25 @@ h4 {
line-height: 1.25em;
}
-div.spacer {
- &.mt1 { margin-top: 1em; }
- &.mt2 { margin-top: 2em; }
- &.mt3 { margin-top: 3em; }
- &.mt4 { margin-top: 4em; }
- &.mt5 { margin-top: 5em; }
- &.mt6 { margin-top: 6em; }
- &.mt7 { margin-top: 7em; }
-}
+.mt1 { margin-top: 1em; }
+.mt2 { margin-top: 2em; }
+.mt3 { margin-top: 3em; }
+.mt4 { margin-top: 4em; }
+.mt5 { margin-top: 5em; }
+.mt6 { margin-top: 6em; }
+.mt7 { margin-top: 7em; }
+.mb1 { margin-bottom: 1em; }
+.mb2 { margin-bottom: 2em; }
+.mb3 { margin-bottom: 3em; }
+.mb4 { margin-bottom: 4em; }
+.mb5 { margin-bottom: 5em; }
+.mb6 { margin-bottom: 6em; }
+.mb7 { margin-bottom: 7em; }
+
+.text-center {
+ text-align: center;
+}
// Bulma color changes.
.tooltip.is-top.is-primary:before { border-top: 5px solid #20222b; }
.tooltip.is-primary:after { background: #20222b; }
diff --git a/src/site/pages/dashboard/settings.vue b/src/site/pages/dashboard/settings.vue
index 19b0c5b..a71358e 100644
--- a/src/site/pages/dashboard/settings.vue
+++ b/src/site/pages/dashboard/settings.vue
@@ -70,7 +70,7 @@
<b-field label="Album link length"
message="How many characters a link for an album should have"
horizontal>
- <b-input v-model="options.albumLength"
+ <b-input v-model="options.albumLinkLength"
expanded />
</b-field>
@@ -93,7 +93,7 @@
<b-field label="Strip EXIF"
message="Remove EXIF metadata from uploaded files"
horizontal>
- <b-switch v-model="options.removeExif"
+ <b-switch v-model="options.stripExif"
:true-value="true"
:false-value="false" />
</b-field>
@@ -109,13 +109,15 @@
<b-field label="Enable creating account"
message="Enable creating new accounts in the platform"
horizontal>
- <b-switch v-model="options.userAccounts"
+ <b-switch v-model="options.enableAccounts"
:true-value="true"
:false-value="false" />
</b-field>
- <button class="button is-primary"
- @click="restartService">Restart service</button>
+ <div class="mb2 mt2 text-center">
+ <button class="button is-primary"
+ @click="promptRestartService">Save and restart service</button>
+ </div>
</div>
</div>
</div>
@@ -135,6 +137,11 @@ export default {
options: {}
};
},
+ computed: {
+ config() {
+ return this.$store.state.config;
+ }
+ },
metaInfo() {
return { title: 'Settings' };
},
@@ -144,10 +151,33 @@ export default {
title: 'Settings',
location: window.location.href
});
+
+ this.getSettings();
},
methods: {
+ async getSettings() {
+ try {
+ const response = await this.axios.get(`${this.config.baseURL}/service/config`);
+ this.options = response.data.config;
+ console.log(this.options);
+ } catch (error) {
+ this.$onPromiseError(error);
+ }
+ },
+ promptRestartService() {
+ this.$dialog.confirm({
+ message: 'Keep in mind that restarting only works if you have PM2 or something similar set up. Continue?',
+ onConfirm: () => this.restartService()
+ });
+ },
async restartService() {
- //
+ try {
+ const response = await this.axios.post(`${this.config.baseURL}/service/restart`);
+ this.$toast.open(response.data.message);
+ return;
+ } catch (error) {
+ this.$onPromiseError(error);
+ }
}
}
};
diff --git a/src/site/pages/dashboard/users.vue b/src/site/pages/dashboard/users.vue
index df16918..c930876 100644
--- a/src/site/pages/dashboard/users.vue
+++ b/src/site/pages/dashboard/users.vue
@@ -229,7 +229,7 @@ export default {
this.users = response.data.users;
console.log(this.users);
} catch (error) {
- console.error(error);
+ this.$onPromiseError(error);
}
},
async changeEnabledStatus(row) {
@@ -239,7 +239,7 @@ export default {
});
this.$toast.open(response.data.message);
} catch (error) {
- console.error(error);
+ this.$onPromiseError(error);
}
},
async changeIsAdmin(row) {
@@ -249,7 +249,7 @@ export default {
});
this.$toast.open(response.data.message);
} catch (error) {
- console.error(error);
+ this.$onPromiseError(error);
}
}
}