Skip to content

Commit

Permalink
feat: add endpoint to signup
Browse files Browse the repository at this point in the history
  • Loading branch information
LimberHope committed Apr 19, 2024
1 parent e66f1f5 commit c296073
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
45 changes: 45 additions & 0 deletions app/Http/Controllers/V2/User/AdminUserRoleController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Http\Controllers\V2\User;

use App\Http\Controllers\Controller;
use App\Http\Requests\V2\User\StoreUserRequest;
use App\Http\Resources\V2\User\UserResource;
use App\Models\V2\User;
use Illuminate\Support\Facades\Auth;

class AdminUserRoleController extends Controller
{
public function store(StoreUserRequest $request, $id)
{
$this->authorize('create', User::class);

$data = $request->all();
$data = ['role' => $id];
switch ($request->get('primary_role')) {
case 'admin-super':
case 'admin-ppc':
$data['role'] = 'admin';

break;
case 'admin-terrafund':
$data['role'] = 'terrafund_admin';

break;
case 'project-developer':
$data['role'] = 'user';

break;
}

$user = User::create($data);

if (! empty($request->get('primary_role')) && Auth::user()->hasRole('admin-super')) {
$user->syncRoles([$request->get('primary_role')]);
} else {
assignSpatieRole($user);
}

return new UserResource($user);
}
}
2 changes: 2 additions & 0 deletions routes/api_v2.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
use App\Http\Controllers\V2\User\AdminExportUsersController;
use App\Http\Controllers\V2\User\AdminResetPasswordController;
use App\Http\Controllers\V2\User\AdminUserController;
use App\Http\Controllers\V2\User\AdminUserRoleController;
use App\Http\Controllers\V2\User\AdminUserMultiController;
use App\Http\Controllers\V2\User\AdminVerifyUserController;
use App\Http\Controllers\V2\User\CompleteActionController;
Expand Down Expand Up @@ -318,6 +319,7 @@
Route::get('export', AdminExportUsersController::class);
Route::put('reset-password/{user}', AdminResetPasswordController::class);
Route::patch('verify/{user}', AdminVerifyUserController::class);
Route::post('register-user/{id}', AdminUserRoleController::class);
});
Route::resource('users', AdminUserController::class);

Expand Down

0 comments on commit c296073

Please sign in to comment.