From 3c3d35bff58882f7624c105bea13ff43acaaab5b Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Mon, 20 Feb 2023 17:09:59 +0100 Subject: [PATCH] Enable creation of multiple users --- app/Http/Requests/UserStoreRequest.php | 2 +- app/Rules/FirstUser.php | 41 ------------------- resources/js/routes.js | 1 - resources/js/views/Error.vue | 8 ---- resources/js/views/auth/Register.vue | 6 +-- resources/lang/en/errors.php | 1 - resources/lang/en/validation.php | 3 -- .../Http/Auth/RegisterControllerTest.php | 19 --------- 8 files changed, 2 insertions(+), 79 deletions(-) delete mode 100644 app/Rules/FirstUser.php diff --git a/app/Http/Requests/UserStoreRequest.php b/app/Http/Requests/UserStoreRequest.php index 7c8f5f4f..23e2773a 100644 --- a/app/Http/Requests/UserStoreRequest.php +++ b/app/Http/Requests/UserStoreRequest.php @@ -24,7 +24,7 @@ class UserStoreRequest extends FormRequest public function rules() { return [ - 'name' => [new \App\Rules\FirstUser, 'required', 'string', 'max:255'], + 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255', 'password' => 'required|string|min:8|confirmed', ]; diff --git a/app/Rules/FirstUser.php b/app/Rules/FirstUser.php deleted file mode 100644 index a4295973..00000000 --- a/app/Rules/FirstUser.php +++ /dev/null @@ -1,41 +0,0 @@ -count() === 0 ? true : false; - } - - /** - * Get the validation error message. - * - * @return array|string - */ - public function message() - { - return trans('validation.custom.name.firstUser'); - } -} diff --git a/resources/js/routes.js b/resources/js/routes.js index 3dc9fb74..855d75d6 100644 --- a/resources/js/routes.js +++ b/resources/js/routes.js @@ -62,7 +62,6 @@ const router = new Router({ { path: '/webauthn/recover', name: 'webauthn.recover', component: WebauthnRecover, meta: { disabledWithAuthProxy: true, showAbout: true } }, { path: '/about', name: 'about',component: About, meta: { showAbout: true } }, - { path: '/flooded', name: 'flooded',component: Errors, props: true }, { path: '/error', name: 'genericError',component: Errors, props: true }, { path: '/404', name: '404',component: Errors, props: true }, { path: '*', redirect: { name: '404' } } diff --git a/resources/js/views/Error.vue b/resources/js/views/Error.vue index 9d1f1f73..5ee262e9 100644 --- a/resources/js/views/Error.vue +++ b/resources/js/views/Error.vue @@ -6,14 +6,6 @@
{{ $t('errors.resource_not_found') }}
- {{ $t('errors.already_one_user_registered') }}
- {{ $t('errors.cannot_register_more_user') }}
-
{{ $t('errors.error_occured') }}
diff --git a/resources/js/views/auth/Register.vue b/resources/js/views/auth/Register.vue index 74ac8c42..ce6cf588 100644 --- a/resources/js/views/auth/Register.vue +++ b/resources/js/views/auth/Register.vue @@ -74,11 +74,7 @@ this.showWebauthnRegistration = true }) .catch(error => { - if( error.response.status === 422 && error.response.data.errors.name.includes(this.$t('validation.custom.name.firstUser')) ) { - - this.$notify({ type: 'is-danger', text: this.$t('errors.cannot_register_more_user'), duration:-1 }) - } - else if( error.response.status !== 422 ) { + if( error.response.status !== 422 ) { this.$router.push({ name: 'genericError', params: { err: error.response } }); } diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index 1d71b703..8f8fc2fa 100644 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -15,7 +15,6 @@ return [ 'resource_not_found' => 'Resource not found', 'error_occured' => 'An error occured:', - 'cannot_register_more_user' => 'You cannot register more than one user.', 'refresh' => 'Refresh', 'no_valid_otp' => 'No valid OTP resource in this QR code', 'something_wrong_with_server' => 'Something is wrong with your server', diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 23651f1f..d56d0324 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -185,9 +185,6 @@ return [ ], 'ids' => [ 'regex' => 'IDs must be comma separated, without trailing comma.', - ], - 'name' => [ - 'firstUser' => 'There is already a registered user', ] ], diff --git a/tests/Feature/Http/Auth/RegisterControllerTest.php b/tests/Feature/Http/Auth/RegisterControllerTest.php index 93b35318..e44790b5 100644 --- a/tests/Feature/Http/Auth/RegisterControllerTest.php +++ b/tests/Feature/Http/Auth/RegisterControllerTest.php @@ -48,25 +48,6 @@ class RegisterControllerTest extends FeatureTestCase ]); } - /** - * @test - * - * @covers \App\Rules\FirstUser - */ - public function test_register_returns_already_an_existing_user() - { - DB::table('users')->delete(); - $user = User::factory()->create(); - - $response = $this->json('POST', '/user', [ - 'name' => self::USERNAME, - 'email' => self::EMAIL, - 'password' => self::PASSWORD, - 'password_confirmation' => self::PASSWORD, - ]) - ->assertJsonValidationErrorFor('name'); - } - /** * @test */