From 242dfe61c69ec5f2a006a735d3da475281b0659e Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Wed, 18 Aug 2021 21:14:26 +0100 Subject: [PATCH 01/10] :sparkles: Implements guest access into Login page --- src/components/Settings/AuthButtons.vue | 80 +++++++++++++++ src/views/Login.vue | 131 ++++++++++++++++++++++-- 2 files changed, 202 insertions(+), 9 deletions(-) create mode 100644 src/components/Settings/AuthButtons.vue diff --git a/src/components/Settings/AuthButtons.vue b/src/components/Settings/AuthButtons.vue new file mode 100644 index 0000000000..5065310295 --- /dev/null +++ b/src/components/Settings/AuthButtons.vue @@ -0,0 +1,80 @@ + + + + + diff --git a/src/views/Login.vue b/src/views/Login.vue index 1b8e147b74..dfc2b2dbac 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -1,6 +1,22 @@ @@ -36,7 +73,12 @@ import router from '@/router'; import Button from '@/components/FormElements/Button'; import Input from '@/components/FormElements/Input'; import Defaults, { localStorageKeys } from '@/utils/defaults'; -import { checkCredentials, login } from '@/utils/Auth'; +import { + checkCredentials, + login, + isLoggedIn, + logout, +} from '@/utils/Auth'; export default { name: 'login', @@ -76,6 +118,21 @@ export default { successMsg: this.$t('login.success-message'), }; }, + existingUsername() { + return localStorage[localStorageKeys.USERNAME]; + }, + isUserAlreadyLoggedIn() { + const users = this.appConfig.auth; + const loggedIn = (!users || users.length === 0 || isLoggedIn(users)); + return (loggedIn && this.existingUsername); + }, + isGuestAccessEnabled() { + if (!this.appConfig || !this.appConfig.enableGuestAccess) return false; + return this.appConfig.enableGuestAccess; + }, + isAuthenticationEnabled() { + return (this.appConfig && this.appConfig.auth && this.appConfig.auth.length > 0); + }, }, methods: { /* Checks form is filled in, then initiates the login, and redirects to /home */ @@ -93,11 +150,42 @@ export default { this.status = response.correct ? 'success' : 'error'; if (response.correct) { // Yay, credentials were correct :) login(this.username, this.password, timeout); // Login, to set the cookie - setTimeout(() => { // Wait a short while, then redirect back home - router.push({ path: '/' }); - }, 250); + this.goHome(); + } + }, + /* Calls function to double-check guest access enabled, then log in as guest */ + guestLogin() { + const isAllowed = this.isGuestAccessEnabled; + if (isAllowed) { + this.$toasted.show('Logged in as Guest, Redirecting...', { className: 'toast-success' }); + this.goHome(); + } else { + this.$toasted.show('Guest access not allowed', { className: 'toast-error' }); } }, + /* Calls logout, shows status message, and refreshed page */ + getOut() { + logout(); + this.status = 'success'; + this.message = 'Logging out...'; + this.refreshPage(); + }, + /* Logged in user redirects to home page */ + stayLoggedIn() { + this.status = 'success'; + this.message = 'Redirecting...'; + this.goHome(); + }, + /* Refreshes the page */ + refreshPage() { + setTimeout(() => { location.reload(); }, 250); // eslint-disable-line no-restricted-globals + }, + /* Redirects to the homepage */ + goHome() { + setTimeout(() => { // Wait a short while, then redirect back home + router.push({ path: '/' }); + }, 250); + }, /* Since Theme setter isn't loaded at this point, we must manually get and apply users theme */ setTheme() { const theme = localStorage[localStorageKeys.THEME] || Defaults.theme; @@ -119,23 +207,43 @@ export default { display: flex; align-items: center; justify-content: center; + justify-content: space-evenly; min-height: calc(100vh - var(--footer-height)); + /* User is already logged in note */ + div.already-logged-in { + margin: 0 auto 0.5rem; + p.already-logged-in { + margin: 0 auto 0.5rem; + text-align: center; + } + span.username { + font-weight: bold; + text-transform: capitalize; + } + span.already-logged-in-note { + font-size: 0.8rem; + opacity: var(--dimming-factor); + text-align: left; + } + } + /* Login form container */ - form.login-form { + form.login-form, form.guest-form, div.already-logged-in, div.not-configured { background: var(--login-form-background); color: var(--login-form-color); border: 1px solid var(--login-form-color); border-radius: var(--curve-factor); font-size: 1.4rem; padding: 2rem; - margin: 2rem auto; + margin: 2rem; + max-width: 22rem; display: flex; flex-direction: column; /* Login form title */ - h2.login-title { - font-size: 3rem; + h2 { + font-size: 2rem; margin: 0 0 1rem 0; text-align: center; cursor: default; @@ -177,6 +285,11 @@ export default { &.success { color: var(--success); } &.error { color: var(--warning); } } + p.guest-intro { + font-size: 0.8rem; + opacity: var(--dimming-factor); + text-align: left; + } } } From e4d76607122430bedccac220bce2b819c164a448 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Wed, 18 Aug 2021 21:15:47 +0100 Subject: [PATCH 02/10] :truck: Renames AppButtons to AuthButtons --- src/components/Settings/AppButtons.vue | 62 ------------------- src/components/Settings/SettingsContainer.vue | 25 ++++++-- 2 files changed, 19 insertions(+), 68 deletions(-) delete mode 100644 src/components/Settings/AppButtons.vue diff --git a/src/components/Settings/AppButtons.vue b/src/components/Settings/AppButtons.vue deleted file mode 100644 index 875ae11b41..0000000000 --- a/src/components/Settings/AppButtons.vue +++ /dev/null @@ -1,62 +0,0 @@ - - - - - diff --git a/src/components/Settings/SettingsContainer.vue b/src/components/Settings/SettingsContainer.vue index 9c6a1bf6b1..799145986b 100644 --- a/src/components/Settings/SettingsContainer.vue +++ b/src/components/Settings/SettingsContainer.vue @@ -1,5 +1,6 @@