mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-05-01 12:54:39 +02:00
Check user count to prevent more than one registered user
This commit is contained in:
parent
9fc722bda0
commit
289b36d9d0
@ -5,6 +5,7 @@
|
||||
use App\User;
|
||||
use Validator;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
@ -56,6 +57,20 @@ public function logout()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check if a user exists
|
||||
* @param Request $request [description]
|
||||
* @return json
|
||||
*/
|
||||
public function checkUser()
|
||||
{
|
||||
|
||||
$count = DB::table('users')->count();
|
||||
|
||||
return response()->json(['userCount' => $count], 200);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* register new user
|
||||
* @param Request $request [description]
|
||||
@ -63,6 +78,14 @@ public function logout()
|
||||
*/
|
||||
public function register(Request $request)
|
||||
{
|
||||
|
||||
// check if a user already exists
|
||||
$count = DB::table('users')->count();
|
||||
|
||||
if( $count > 0 ) {
|
||||
return response()->json(['error' => __('already_one_user_registered')], 400);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
'email' => 'required|email',
|
||||
|
6
resources/js/app.js
vendored
6
resources/js/app.js
vendored
@ -59,6 +59,12 @@ const router = new VueRouter({
|
||||
name: 'edit',
|
||||
component: Edit,
|
||||
},
|
||||
{
|
||||
path: '/flooded',
|
||||
name: 'flooded',
|
||||
component: NotFound,
|
||||
props: true
|
||||
},
|
||||
{
|
||||
path: '/error',
|
||||
name: 'GenericError',
|
||||
|
@ -5,6 +5,12 @@
|
||||
<p class="error-404"></p>
|
||||
<p>{{ $t('errors.resource_not_found') }}<router-link :to="{ name: 'accounts' }" class="is-text has-text-white">{{ $t('errors.refresh') }}</router-link></p>
|
||||
</div>
|
||||
<div v-else-if="$route.name == 'flooded'">
|
||||
<p class="error-generic"></p>
|
||||
<p>{{ $t('errors.already_one_user_registered') }}<br>
|
||||
{{ $t('errors.cannot_register_more_user') }}<br><br>
|
||||
{{ $t('errors.please') }}<router-link :to="{ name: 'accounts' }" class="is-text has-text-white">{{ $t('auth.sign_in') }}</router-link></p>
|
||||
</div>
|
||||
<div v-else>
|
||||
<p class="error-generic"></p>
|
||||
<p>{{ $t('errors.error_occured') }}<router-link :to="{ name: 'accounts' }" class="is-text has-text-white">{{ $t('errors.refresh') }}</router-link></p>
|
||||
@ -50,14 +56,6 @@
|
||||
this.$router.push({name: 'accounts' });
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
beforeRouteEnter (to, from, next) {
|
||||
if ( ! localStorage.getItem('jwt')) {
|
||||
return next('login')
|
||||
}
|
||||
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<br />
|
||||
<span class="tag is-danger" v-if="errorMessage">
|
||||
{{ errorMessage }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="columns is-mobile is-centered">
|
||||
@ -58,10 +62,25 @@
|
||||
email : '',
|
||||
password : '',
|
||||
password_confirmation : '',
|
||||
errors: {}
|
||||
errors: {},
|
||||
errorMessage: ''
|
||||
}
|
||||
},
|
||||
|
||||
created: function() {
|
||||
// we check if a user account already exists
|
||||
axios.post('api/checkuser')
|
||||
.then(response => {
|
||||
if( response.data.userCount > 0) {
|
||||
this.errorMessage = this.$t('errors.already_one_user_registered') + ' ' + this.$t('errors.cannot_register_more_user')
|
||||
this.$router.push({ name: 'flooded' });
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
this.$router.push({ name: 'error', params: { err: error.response.message } });
|
||||
});
|
||||
},
|
||||
|
||||
methods : {
|
||||
handleSubmit(e) {
|
||||
e.preventDefault()
|
||||
|
5
resources/js/vue-i18n-locales.generated.js
vendored
5
resources/js/vue-i18n-locales.generated.js
vendored
@ -14,7 +14,7 @@ export default {
|
||||
"email": "Email",
|
||||
"password": "Password",
|
||||
"confirm_password": "Confirm password",
|
||||
"dont_have_account_yet": "Don't have an account yet?",
|
||||
"dont_have_account_yet": "Don't have your account yet?",
|
||||
"already_register": "Already registered?",
|
||||
"passwords_do_not_match": "Passwords do not match"
|
||||
}
|
||||
@ -25,7 +25,10 @@ export default {
|
||||
"errors": {
|
||||
"resource_not_found": "Resource not found, please ",
|
||||
"error_occured": "An error occured, please ",
|
||||
"already_one_user_registered": "There is already a registered user.",
|
||||
"cannot_register_more_user": "You cannot register more than one user.",
|
||||
"refresh": "refresh",
|
||||
"please": "Please ",
|
||||
"response": {
|
||||
"no_valid_totp": "No valid TOTP resource in this QR code"
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
'email' => 'Email',
|
||||
'password' => 'Password',
|
||||
'confirm_password' => 'Confirm password',
|
||||
'dont_have_account_yet' => 'Don\'t have an account yet?',
|
||||
'dont_have_account_yet' => 'Don\'t have your account yet?',
|
||||
'already_register' => 'Already registered?',
|
||||
'passwords_do_not_match' => 'Passwords do not match',
|
||||
]
|
||||
|
@ -15,7 +15,10 @@
|
||||
|
||||
'resource_not_found' => 'Resource not found, please ',
|
||||
'error_occured' => 'An error occured, please ',
|
||||
'already_one_user_registered' => 'There is already a registered user.',
|
||||
'cannot_register_more_user' => 'You cannot register more than one user.',
|
||||
'refresh' => 'refresh',
|
||||
'please' => 'Please ',
|
||||
'response' => [
|
||||
'no_valid_totp' => 'No valid TOTP resource in this QR code',
|
||||
]
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
Route::post('login', 'UserController@login');
|
||||
Route::post('checkuser', 'UserController@checkUser');
|
||||
Route::post('register', 'UserController@register');
|
||||
|
||||
Route::group(['middleware' => 'auth:api'], function(){
|
||||
|
Loading…
Reference in New Issue
Block a user