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