fix(user): moved enum in its own file, fixed permission permission issue with register route
This commit is contained in:
parent
6ffd52d38d
commit
6e02efd164
3 changed files with 20 additions and 9 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Actions\Fortify;
|
||||
|
||||
use App\Enums\UserType;
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
@ -9,13 +10,6 @@ use Illuminate\Support\Facades\Validator;
|
|||
use Illuminate\Validation\Rule;
|
||||
use Laravel\Fortify\Contracts\CreatesNewUsers;
|
||||
|
||||
enum UserType: string
|
||||
{
|
||||
case A = 'admin';
|
||||
case H = 'dj';
|
||||
case P = 'editor';
|
||||
}
|
||||
|
||||
class CreateNewUser implements CreatesNewUsers
|
||||
{
|
||||
use PasswordValidationRules;
|
||||
|
@ -24,9 +18,10 @@ class CreateNewUser implements CreatesNewUsers
|
|||
/**
|
||||
* Validate and create a newly registered user.
|
||||
*
|
||||
* @param array{name: string, email: string, password: string} $userInfos An associative array containing user information.
|
||||
* @param array{username: string, email: string, password: string, type: string} $userInfos An associative array containing user information.
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection PhpParameterNameChangedDuringInheritanceInspection
|
||||
*/
|
||||
public function create(array $userInfos): User|Exception
|
||||
{
|
||||
|
|
16
app/Enums/UserType.php
Normal file
16
app/Enums/UserType.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum UserType: string
|
||||
{
|
||||
case A = 'admin';
|
||||
case H = 'dj';
|
||||
case P = 'editor';
|
||||
|
||||
public static function fromName(string $name)
|
||||
{
|
||||
|
||||
return constant("self::$name");
|
||||
}
|
||||
}
|
|
@ -7,6 +7,6 @@ use Laravel\Fortify\Http\Controllers\AuthenticatedSessionController;
|
|||
|
||||
Route::post('/login', [AuthenticatedSessionController::class, 'store']);
|
||||
|
||||
Route::middleware('auth:sanctum')->middleware(['permission:manage_users'])->post('/register', [RegistrationController::class, 'create']);
|
||||
Route::middleware('auth:sanctum')->middleware(['permission:users.manageAll'])->post('/register', [RegistrationController::class, 'create']);
|
||||
|
||||
Route::post('/registerToken', [ApiToken::class, 'registerToken']);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue