Enable creation of multiple users

This commit is contained in:
Bubka 2023-02-20 17:09:59 +01:00
parent 46508fda75
commit 3c3d35bff5
8 changed files with 2 additions and 79 deletions

View File

@ -24,7 +24,7 @@ class UserStoreRequest extends FormRequest
public function rules() public function rules()
{ {
return [ return [
'name' => [new \App\Rules\FirstUser, 'required', 'string', 'max:255'], 'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255', 'email' => 'required|string|email|max:255',
'password' => 'required|string|min:8|confirmed', 'password' => 'required|string|min:8|confirmed',
]; ];

View File

@ -1,41 +0,0 @@
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\DB;
class FirstUser implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return DB::table('users')->count() === 0 ? true : false;
}
/**
* Get the validation error message.
*
* @return array|string
*/
public function message()
{
return trans('validation.custom.name.firstUser');
}
}

View File

@ -62,7 +62,6 @@ const router = new Router({
{ path: '/webauthn/recover', name: 'webauthn.recover', component: WebauthnRecover, meta: { disabledWithAuthProxy: true, showAbout: true } }, { path: '/webauthn/recover', name: 'webauthn.recover', component: WebauthnRecover, meta: { disabledWithAuthProxy: true, showAbout: true } },
{ path: '/about', name: 'about',component: About, meta: { 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: '/error', name: 'genericError',component: Errors, props: true },
{ path: '/404', name: '404',component: Errors, props: true }, { path: '/404', name: '404',component: Errors, props: true },
{ path: '*', redirect: { name: '404' } } { path: '*', redirect: { name: '404' } }

View File

@ -6,14 +6,6 @@
<p>{{ $t('errors.resource_not_found') }}</p> <p>{{ $t('errors.resource_not_found') }}</p>
<p class=""><router-link :to="{ name: 'accounts' }" class="is-text">{{ $t('errors.refresh') }}</router-link></p> <p class=""><router-link :to="{ name: 'accounts' }" class="is-text">{{ $t('errors.refresh') }}</router-link></p>
</div> </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') }}
</p>
<p><router-link :to="{ name: 'accounts' }" class="is-text">{{ $t('auth.sign_in') }}</router-link></p>
</div>
<div v-else> <div v-else>
<p class="error-generic"></p> <p class="error-generic"></p>
<p>{{ $t('errors.error_occured') }} </p> <p>{{ $t('errors.error_occured') }} </p>

View File

@ -74,11 +74,7 @@
this.showWebauthnRegistration = true this.showWebauthnRegistration = true
}) })
.catch(error => { .catch(error => {
if( error.response.status === 422 && error.response.data.errors.name.includes(this.$t('validation.custom.name.firstUser')) ) { if( error.response.status !== 422 ) {
this.$notify({ type: 'is-danger', text: this.$t('errors.cannot_register_more_user'), duration:-1 })
}
else if( error.response.status !== 422 ) {
this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response } });
} }

View File

@ -15,7 +15,6 @@ return [
'resource_not_found' => 'Resource not found', 'resource_not_found' => 'Resource not found',
'error_occured' => 'An error occured:', 'error_occured' => 'An error occured:',
'cannot_register_more_user' => 'You cannot register more than one user.',
'refresh' => 'Refresh', 'refresh' => 'Refresh',
'no_valid_otp' => 'No valid OTP resource in this QR code', 'no_valid_otp' => 'No valid OTP resource in this QR code',
'something_wrong_with_server' => 'Something is wrong with your server', 'something_wrong_with_server' => 'Something is wrong with your server',

View File

@ -185,9 +185,6 @@ return [
], ],
'ids' => [ 'ids' => [
'regex' => 'IDs must be comma separated, without trailing comma.', 'regex' => 'IDs must be comma separated, without trailing comma.',
],
'name' => [
'firstUser' => 'There is already a registered user',
] ]
], ],

View File

@ -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 * @test
*/ */