Show NotFound instead of the Register view when registration is disabled

This commit is contained in:
Bubka 2023-11-16 08:09:11 +01:00
parent e30e373c6f
commit 65fc726f6c
4 changed files with 22 additions and 3 deletions

View File

@ -2,10 +2,12 @@ import { createRouter, createWebHistory } from 'vue-router'
import middlewarePipeline from "@/router/middlewarePipeline"; import middlewarePipeline from "@/router/middlewarePipeline";
import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
import { useTwofaccounts } from '@/stores/twofaccounts' import { useTwofaccounts } from '@/stores/twofaccounts'
import { useAppSettingsStore } from '@/stores/appSettings'
import authGuard from './middlewares/authGuard' import authGuard from './middlewares/authGuard'
import starter from './middlewares/starter' import starter from './middlewares/starter'
import noEmptyError from './middlewares/noEmptyError' import noEmptyError from './middlewares/noEmptyError'
import noRegistration from './middlewares/noRegistration'
import setReturnTo from './middlewares/setReturnTo' import setReturnTo from './middlewares/setReturnTo'
const router = createRouter({ const router = createRouter({
@ -31,7 +33,7 @@ const router = createRouter({
{ path: '/settings/webauthn', name: 'settings.webauthn.devices', component: () => import('../views/settings/WebAuthn.vue'), meta: { middlewares: [authGuard], showAbout: true } }, { path: '/settings/webauthn', name: 'settings.webauthn.devices', component: () => import('../views/settings/WebAuthn.vue'), meta: { middlewares: [authGuard], showAbout: true } },
{ path: '/login', name: 'login', component: () => import('../views/auth/Login.vue'), meta: { middlewares: [setReturnTo], disabledWithAuthProxy: true, showAbout: true } }, { path: '/login', name: 'login', component: () => import('../views/auth/Login.vue'), meta: { middlewares: [setReturnTo], disabledWithAuthProxy: true, showAbout: true } },
{ path: '/register', name: 'register', component: () => import('../views/auth/Register.vue'), meta: { middlewares: [setReturnTo], disabledWithAuthProxy: true, showAbout: true } }, { path: '/register', name: 'register', component: () => import('../views/auth/Register.vue'), meta: { middlewares: [noRegistration, setReturnTo], disabledWithAuthProxy: true, showAbout: true } },
{ path: '/password/request', name: 'password.request', component: () => import('../views/auth/RequestReset.vue'), meta: { middlewares: [setReturnTo], disabledWithAuthProxy: true, showAbout: true } }, { path: '/password/request', name: 'password.request', component: () => import('../views/auth/RequestReset.vue'), meta: { middlewares: [setReturnTo], disabledWithAuthProxy: true, showAbout: true } },
{ path: '/user/password/reset', name: 'password.reset', component: () => import('../views/auth/password/Reset.vue'), meta: { middlewares: [setReturnTo], disabledWithAuthProxy: true, showAbout: true } }, { path: '/user/password/reset', name: 'password.reset', component: () => import('../views/auth/password/Reset.vue'), meta: { middlewares: [setReturnTo], disabledWithAuthProxy: true, showAbout: true } },
{ path: '/webauthn/lost', name: 'webauthn.lost', component: () => import('../views/auth/RequestReset.vue'), meta: { middlewares: [setReturnTo], disabledWithAuthProxy: true, showAbout: true } }, { path: '/webauthn/lost', name: 'webauthn.lost', component: () => import('../views/auth/RequestReset.vue'), meta: { middlewares: [setReturnTo], disabledWithAuthProxy: true, showAbout: true } },
@ -48,7 +50,8 @@ router.beforeEach((to, from, next) => {
const middlewares = to.meta.middlewares const middlewares = to.meta.middlewares
const user = useUserStore() const user = useUserStore()
const twofaccounts = useTwofaccounts() const twofaccounts = useTwofaccounts()
const stores = { user: user, twofaccounts: twofaccounts } const appSettings = useAppSettingsStore()
const stores = { user: user, twofaccounts: twofaccounts, appSettings: appSettings }
const nextMiddleware = {} const nextMiddleware = {}
const context = { to, from, next, nextMiddleware, stores } const context = { to, from, next, nextMiddleware, stores }

View File

@ -0,0 +1,11 @@
/**
* Prevent the Register view to be reachable when registration is disabled
*/
export default async function noRegistration({ to, next, nextMiddleware, stores }) {
const { appSettings } = stores
if (appSettings.disableRegistration) {
next({ name: 'notFound' })
}
else nextMiddleware()
}

View File

@ -1,5 +1,4 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import appSettingService from '@/services/appSettingService'
export const useAppSettingsStore = defineStore({ export const useAppSettingsStore = defineStore({
id: 'appSettings', id: 'appSettings',

View File

@ -73,6 +73,12 @@
{{ $t('auth.login_and_password') }} {{ $t('auth.login_and_password') }}
</a> </a>
</p> </p>
<p v-if="appSettings.disableRegistration == false" class="mt-4">
{{ $t('auth.forms.dont_have_account_yet') }}&nbsp;
<RouterLink id="lnkRegister" :to="{ name: 'register' }" class="is-link">
{{ $t('auth.register') }}
</RouterLink>
</p>
</div> </div>
</FormWrapper> </FormWrapper>
<!-- login/password legacy form --> <!-- login/password legacy form -->