diff --git a/resources/js_vue3/router/index.js b/resources/js_vue3/router/index.js index 6e468d63..201e00c8 100644 --- a/resources/js_vue3/router/index.js +++ b/resources/js_vue3/router/index.js @@ -2,10 +2,12 @@ import { createRouter, createWebHistory } from 'vue-router' import middlewarePipeline from "@/router/middlewarePipeline"; import { useUserStore } from '@/stores/user' import { useTwofaccounts } from '@/stores/twofaccounts' +import { useAppSettingsStore } from '@/stores/appSettings' import authGuard from './middlewares/authGuard' import starter from './middlewares/starter' import noEmptyError from './middlewares/noEmptyError' +import noRegistration from './middlewares/noRegistration' import setReturnTo from './middlewares/setReturnTo' 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: '/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: '/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 } }, @@ -48,7 +50,8 @@ router.beforeEach((to, from, next) => { const middlewares = to.meta.middlewares const user = useUserStore() const twofaccounts = useTwofaccounts() - const stores = { user: user, twofaccounts: twofaccounts } + const appSettings = useAppSettingsStore() + const stores = { user: user, twofaccounts: twofaccounts, appSettings: appSettings } const nextMiddleware = {} const context = { to, from, next, nextMiddleware, stores } diff --git a/resources/js_vue3/router/middlewares/noRegistration.js b/resources/js_vue3/router/middlewares/noRegistration.js new file mode 100644 index 00000000..d778d55c --- /dev/null +++ b/resources/js_vue3/router/middlewares/noRegistration.js @@ -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() +} \ No newline at end of file diff --git a/resources/js_vue3/stores/appSettings.js b/resources/js_vue3/stores/appSettings.js index bd119246..351464f8 100644 --- a/resources/js_vue3/stores/appSettings.js +++ b/resources/js_vue3/stores/appSettings.js @@ -1,5 +1,4 @@ import { defineStore } from 'pinia' -import appSettingService from '@/services/appSettingService' export const useAppSettingsStore = defineStore({ id: 'appSettings', diff --git a/resources/js_vue3/views/auth/Login.vue b/resources/js_vue3/views/auth/Login.vue index 55db16f4..5d102d57 100644 --- a/resources/js_vue3/views/auth/Login.vue +++ b/resources/js_vue3/views/auth/Login.vue @@ -73,6 +73,12 @@ {{ $t('auth.login_and_password') }}
+
+ {{ $t('auth.forms.dont_have_account_yet') }}
+