diff --git a/composer.json b/composer.json index eef7c31..68009af 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fleetbase/core-api", - "version": "1.5.0", + "version": "1.5.1", "description": "Core Framework and Resources for Fleetbase API", "keywords": [ "fleetbase", diff --git a/migrations/2023_04_25_094301_create_users_table.php b/migrations/2023_04_25_094301_create_users_table.php index 5a5240b..d16b729 100644 --- a/migrations/2023_04_25_094301_create_users_table.php +++ b/migrations/2023_04_25_094301_create_users_table.php @@ -51,6 +51,8 @@ public function up() */ public function down() { - Schema::dropIfExists('users'); + Schema::withoutForeignKeyConstraints(function () { + Schema::dropIfExists('users'); + }); } }; diff --git a/migrations/2023_04_25_094305_create_companies_table.php b/migrations/2023_04_25_094305_create_companies_table.php index 3372eaa..4a9f73c 100644 --- a/migrations/2023_04_25_094305_create_companies_table.php +++ b/migrations/2023_04_25_094305_create_companies_table.php @@ -53,6 +53,8 @@ public function up() */ public function down() { - Schema::dropIfExists('companies'); + Schema::withoutForeignKeyConstraints(function () { + Schema::dropIfExists('companies'); + }); } }; diff --git a/migrations/2023_04_25_094308_create_files_table.php b/migrations/2023_04_25_094308_create_files_table.php index 04f724f..c7c15b7 100644 --- a/migrations/2023_04_25_094308_create_files_table.php +++ b/migrations/2023_04_25_094308_create_files_table.php @@ -47,6 +47,8 @@ public function up() */ public function down() { - Schema::dropIfExists('files'); + Schema::withoutForeignKeyConstraints(function () { + Schema::dropIfExists('files'); + }); } }; diff --git a/src/Http/Controllers/Internal/v1/AuthController.php b/src/Http/Controllers/Internal/v1/AuthController.php index 2599ac5..1bf448e 100644 --- a/src/Http/Controllers/Internal/v1/AuthController.php +++ b/src/Http/Controllers/Internal/v1/AuthController.php @@ -71,7 +71,7 @@ public function login(LoginRequest $request) return response()->error('Authentication failed using password provided.', 401, ['code' => 'invalid_password']); } - if ($user->isNotVerified()) { + if ($user->isNotVerified() && $user->isNotAdmin()) { return response()->error('User is not verified.', 400, ['code' => 'not_verified']); } diff --git a/src/Http/Controllers/Internal/v1/OnboardController.php b/src/Http/Controllers/Internal/v1/OnboardController.php index 7339b4c..e630ea1 100644 --- a/src/Http/Controllers/Internal/v1/OnboardController.php +++ b/src/Http/Controllers/Internal/v1/OnboardController.php @@ -74,12 +74,10 @@ public function createAccount(OnboardRequest $request) // assign user to organization $user->assignCompany($company); - // create company user - CompanyUser::create([ - 'user_uuid' => $user->uuid, - 'company_uuid' => $company->uuid, - 'status' => 'active', - ]); + // Create company user record + if (CompanyUser::where(['company_uuid' => $company->uuid, 'user_uuid' => $user->uuid])->doesntExist()) { + CompanyUser::create(['company_uuid' => $company->uuid, 'user_uuid' => $user->uuid, 'status' => $user->status]); + } // send account created event event(new AccountCreated($user, $company)); diff --git a/src/Http/Requests/OnboardRequest.php b/src/Http/Requests/OnboardRequest.php index 2897f46..7c09541 100644 --- a/src/Http/Requests/OnboardRequest.php +++ b/src/Http/Requests/OnboardRequest.php @@ -34,7 +34,7 @@ public function authorize() public function rules() { return [ - 'name' => ['required', 'min:2', 'regex:/^[a-zA-ZÀ-ÿ\'\- ]+$/u', new ExcludeWords($this->excludedWords)], + 'name' => ['required', 'min:2', 'regex:/^[a-zA-ZÀ-ÿ\'\-\. ]+$/u', new ExcludeWords($this->excludedWords)], 'email' => ['required', 'email', Rule::unique('users', 'email')->whereNull('deleted_at'), new EmailDomainExcluded()], 'phone' => ['required', new ValidPhoneNumber(), Rule::unique('users', 'phone')->whereNull('deleted_at')], 'password' => ['required', 'confirmed', 'min:4', 'max:24'], diff --git a/src/Listeners/HandleAccountCreated.php b/src/Listeners/HandleAccountCreated.php index 34a30d7..f8f87f7 100644 --- a/src/Listeners/HandleAccountCreated.php +++ b/src/Listeners/HandleAccountCreated.php @@ -19,7 +19,7 @@ public function handle(AccountCreated $event) // Send user a verification email $user = $event->user; - if ($user) { + if ($user && $user->isNotAdmin()) { // Create and send verification code try { VerificationCode::generateEmailVerificationFor($user);