mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-22 16:23:18 +01:00
Refactor checkUser controller
This commit is contained in:
parent
747eb98de3
commit
893f29849e
@ -33,16 +33,9 @@ class RegisterController extends Controller
|
||||
*/
|
||||
public function checkUser()
|
||||
{
|
||||
|
||||
$count = DB::table('users')->count();
|
||||
$username = DB::table('users')->where('id', 1)->value('name');
|
||||
|
||||
if( $count === 1 ) {
|
||||
return response()->json(['userCount' => $count, 'username' => $username], 200);
|
||||
}
|
||||
else {
|
||||
return response()->json(['userCount' => $count], 200);
|
||||
}
|
||||
return response()->json(['username' => $username], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,12 +1,12 @@
|
||||
<template>
|
||||
<form-wrapper :title="$t('auth.forms.login')" :punchline="punchline" v-if="userCount === 1">
|
||||
<form-wrapper :title="$t('auth.forms.login')" :punchline="punchline" v-if="username">
|
||||
<div v-if="isDemo" 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 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 v-if=" !username ">{{ $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,9 +18,7 @@
|
||||
export default {
|
||||
data(){
|
||||
return {
|
||||
|
||||
userCount: null,
|
||||
username: '',
|
||||
username: null,
|
||||
isDemo: this.$root.appSettings.isDemoApp,
|
||||
form: new Form({
|
||||
email: '',
|
||||
@ -70,11 +68,10 @@
|
||||
next(async vm => {
|
||||
const { data } = await vm.axios.post('api/checkuser')
|
||||
|
||||
if( data.userCount === 0 ) {
|
||||
if( !data.username ) {
|
||||
return next({ name: 'register' });
|
||||
}
|
||||
else {
|
||||
vm.userCount = data.userCount
|
||||
vm.username = data.username
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user