mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-24 22:12:06 +02:00
Push to Register form or hide it from Login form
This commit is contained in:
parent
241bd1873a
commit
7df763073b
@ -49,7 +49,8 @@ class RegisterController extends Controller
|
||||
{
|
||||
// check if a user already exists
|
||||
if( DB::table('users')->count() > 0 ) {
|
||||
return response()->json(['message' => __('errors.already_one_user_registered')], 400);
|
||||
// return response()->json(['message' => __('errors.already_one_user_registered')], 400);
|
||||
throw \Illuminate\Validation\ValidationException::withMessages(['taken' => __('errors.already_one_user_registered')]);
|
||||
}
|
||||
|
||||
$this->validator($request->all())->validate();
|
||||
|
@ -1,12 +1,12 @@
|
||||
<template>
|
||||
<form-wrapper :title="$t('auth.forms.login')">
|
||||
<form-wrapper :title="$t('auth.forms.login')" v-if="userCount === 1">
|
||||
<div v-if="$root.appSettings.isDemoApp" class="notification is-info has-text-centered" v-html="$t('auth.forms.welcome_to_demo_app_use_those_credentials')" />
|
||||
<form @submit.prevent="handleSubmit" @keydown="form.onKeydown($event)">
|
||||
<form-field :form="form" fieldName="email" inputType="email" :label="$t('auth.forms.email')" autofocus />
|
||||
<form-field :form="form" fieldName="password" inputType="password" :label="$t('auth.forms.password')" />
|
||||
<form-buttons :isBusy="form.isBusy" :caption="$t('auth.sign_in')" />
|
||||
</form>
|
||||
<p>{{ $t('auth.forms.dont_have_account_yet') }} <router-link :to="{ name: 'register' }" class="is-link">{{ $t('auth.register') }}</router-link></p>
|
||||
<p v-if="userCount === 0 ">{{ $t('auth.forms.dont_have_account_yet') }} <router-link :to="{ name: 'register' }" class="is-link">{{ $t('auth.register') }}</router-link></p>
|
||||
<p>{{ $t('auth.forms.forgot_your_password') }} <router-link :to="{ name: 'password.request' }" class="is-link">{{ $t('auth.forms.request_password_reset') }}</router-link></p>
|
||||
</form-wrapper>
|
||||
</template>
|
||||
@ -18,6 +18,7 @@
|
||||
export default {
|
||||
data(){
|
||||
return {
|
||||
userCount: null,
|
||||
form: new Form({
|
||||
email: '',
|
||||
password: ''
|
||||
@ -57,6 +58,17 @@
|
||||
return next('/');
|
||||
}
|
||||
|
||||
next(async vm => {
|
||||
const { data } = await vm.axios.post('api/checkuser')
|
||||
|
||||
if( data.userCount === 0 ) {
|
||||
return next({ name: 'register' });
|
||||
}
|
||||
else {
|
||||
vm.userCount = data.userCount
|
||||
}
|
||||
});
|
||||
|
||||
next();
|
||||
},
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
<template>
|
||||
<form-wrapper :title="$t('auth.register')">
|
||||
<form @submit.prevent="handleSubmit" @keydown="form.onKeydown($event)">
|
||||
<p class="block" v-html="$t('auth.forms.punchline')">
|
||||
</p>
|
||||
<form-field :form="form" fieldName="name" inputType="text" :label="$t('auth.forms.name')" autofocus />
|
||||
<form-field :form="form" fieldName="email" inputType="email" :label="$t('auth.forms.email')" />
|
||||
<form-field :form="form" fieldName="password" inputType="password" :label="$t('auth.forms.password')" />
|
||||
@ -31,36 +33,29 @@
|
||||
async handleSubmit(e) {
|
||||
e.preventDefault()
|
||||
|
||||
const { data } = await this.form.post('api/register')
|
||||
this.form.post('/api/register', {returnError: true})
|
||||
.then(response => {
|
||||
localStorage.setItem('user',response.data.message.name)
|
||||
localStorage.setItem('jwt',response.data.message.token)
|
||||
|
||||
if( this.form.errors.any() === false ) {
|
||||
|
||||
localStorage.setItem('user',data.message.name)
|
||||
localStorage.setItem('jwt',data.message.token)
|
||||
|
||||
if (localStorage.getItem('jwt') != null) {
|
||||
this.$router.push({name: 'accounts'})
|
||||
if (localStorage.getItem('jwt') != null){
|
||||
this.$router.go('/');
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error.response)
|
||||
if( error.response.status === 422 && error.response.data.errors.taken ) {
|
||||
|
||||
this.$notify({ type: 'is-danger', text: this.$t('errors.already_one_user_registered') + ' ' + this.$t('errors.cannot_register_more_user'), duration:-1 })
|
||||
}
|
||||
else if( error.response.status !== 422 ) {
|
||||
|
||||
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
beforeRouteEnter (to, from, next) {
|
||||
if (localStorage.getItem('jwt')) {
|
||||
return next('/');
|
||||
}
|
||||
|
||||
next(async vm => {
|
||||
const { data } = await vm.axios.post('api/checkuser')
|
||||
|
||||
if( data.userCount > 0 ) {
|
||||
vm.form.isDisabled = true
|
||||
|
||||
vm.$notify({ type: 'is-danger', text: vm.$t('errors.already_one_user_registered') + ' ' + vm.$t('errors.cannot_register_more_user'), duration:-1 })
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
beforeRouteLeave (to, from, next) {
|
||||
this.$notify({
|
||||
clean: true
|
||||
|
@ -52,6 +52,8 @@ return [
|
||||
'edit_account' => 'Edit account',
|
||||
'profile_saved' => 'Profile successfully updated!',
|
||||
'welcome_to_demo_app_use_those_credentials' => 'Welcome to the 2FAuth demo.<br><br>You can connect using the email address <strong>demo@2fauth.app</strong> and the password <strong>demo</demo>',
|
||||
'punchline' => 'Welcome to 2FAuth.<br/>
|
||||
You need an account to go further. Fill this form to register yourself, and please, choose a strong password, 2FA data are sensitives.',
|
||||
],
|
||||
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user