mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-12-23 23:49:53 +01:00
Show NotFound instead of the Register view when registration is disabled
This commit is contained in:
parent
e30e373c6f
commit
65fc726f6c
7
resources/js_vue3/router/index.js
vendored
7
resources/js_vue3/router/index.js
vendored
@ -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 }
|
||||
|
||||
|
11
resources/js_vue3/router/middlewares/noRegistration.js
vendored
Normal file
11
resources/js_vue3/router/middlewares/noRegistration.js
vendored
Normal 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()
|
||||
}
|
1
resources/js_vue3/stores/appSettings.js
vendored
1
resources/js_vue3/stores/appSettings.js
vendored
@ -1,5 +1,4 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import appSettingService from '@/services/appSettingService'
|
||||
|
||||
export const useAppSettingsStore = defineStore({
|
||||
id: 'appSettings',
|
||||
|
@ -73,6 +73,12 @@
|
||||
{{ $t('auth.login_and_password') }}
|
||||
</a>
|
||||
</p>
|
||||
<p v-if="appSettings.disableRegistration == false" class="mt-4">
|
||||
{{ $t('auth.forms.dont_have_account_yet') }}
|
||||
<RouterLink id="lnkRegister" :to="{ name: 'register' }" class="is-link">
|
||||
{{ $t('auth.register') }}
|
||||
</RouterLink>
|
||||
</p>
|
||||
</div>
|
||||
</FormWrapper>
|
||||
<!-- login/password legacy form -->
|
||||
|
Loading…
Reference in New Issue
Block a user