diff --git a/lang/en/messages.php b/lang/en/messages.php index 0f47cea..248ff02 100644 --- a/lang/en/messages.php +++ b/lang/en/messages.php @@ -22,6 +22,7 @@ 'update_password' => 'New password updated successfully.', 'update_pin' => 'New pin updated successfully.', 'update_photo' => 'New profile photo updated successfully.', + 'user_profile_update' => 'User :field updated successfully.', 'reset' => [ 'success' => 'Your account password reset successful.', 'temporary_password' => 'We have send you a temporary password. Please log into you account with credentials.', diff --git a/routes/api.php b/routes/api.php index 92ecd14..8063a1e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -16,6 +16,7 @@ use Fintech\RestApi\Http\Controllers\Auth\RolePermissionController; use Fintech\RestApi\Http\Controllers\Auth\SettingController; use Fintech\RestApi\Http\Controllers\Auth\UserController; +use Fintech\RestApi\Http\Controllers\Auth\ProfileController; use Fintech\RestApi\Http\Controllers\Auth\VerifyIdDocumentController; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Route; @@ -74,14 +75,15 @@ Route::middleware(config('fintech.auth.middleware'))->group(function () { - Route::post('update-password', [PasswordController::class, 'update']) + Route::post('update-password', [PasswordController::class, 'updatePassword']) ->name('update-password'); Route::post('update-pin', [PasswordController::class, 'updatePin']) ->name('update-pin'); - Route::post('update-photo', [UserController::class, 'photo']) - ->name('update-photo'); + Route::get('profile', [ProfileController::class, 'show'])->name('profile.show'); + + Route::patch('profile', [ProfileController::class, 'update'])->name('profile.update'); Route::apiResource('users', UserController::class); // Route::post('users/{user}/restore', [UserController::class, 'restore'])->name('users.restore'); @@ -94,10 +96,8 @@ ->whereIn('field', ['pin', 'password', 'both']); Route::apiResource('roles', RoleController::class); - // Route::post('roles/{role}/restore', [RoleController::class, 'restore'])->name('roles.restore'); Route::apiResource('permissions', PermissionController::class); - // Route::post('permissions/{permission}/restore', [PermissionController::class, 'restore'])->name('permissions.restore'); Route::apiResource('role-permissions', RolePermissionController::class) ->only(['show', 'update']); diff --git a/src/Middlewares/LastLoggedIn.php b/src/Middlewares/LastLoggedIn.php index e4ce54b..44f410e 100644 --- a/src/Middlewares/LastLoggedIn.php +++ b/src/Middlewares/LastLoggedIn.php @@ -30,7 +30,7 @@ public function terminate(Request $request, $response): void $user = \Illuminate\Support\Facades\Auth::user(); if ($user) { - Auth::user()->updateRaw($user->getKey(), ['logged_in_at' => now()]); + Auth::user()->update($user->getKey(), ['logged_in_at' => now()]); } } } diff --git a/src/Middlewares/LastLoggedOut.php b/src/Middlewares/LastLoggedOut.php index b599039..158830b 100644 --- a/src/Middlewares/LastLoggedOut.php +++ b/src/Middlewares/LastLoggedOut.php @@ -19,7 +19,7 @@ public function handle(Request $request, Closure $next) $user = \Illuminate\Support\Facades\Auth::user(); if ($user) { - Auth::user()->updateRaw($user->getKey(), ['logged_out_at' => now()]); + Auth::user()->update($user->getKey(), ['logged_out_at' => now()]); } return $next($request); diff --git a/src/Services/UserService.php b/src/Services/UserService.php index c935122..df3746a 100644 --- a/src/Services/UserService.php +++ b/src/Services/UserService.php @@ -128,7 +128,10 @@ private function formatDataFromInput($inputs, bool $forCreate = false) return $data; } - public function updateRaw($id, array $inputs = []) + /** + * @throws \ErrorException + */ + public function update($id, array $inputs = []): ?BaseModel { DB::beginTransaction(); @@ -154,11 +157,14 @@ public function updateRaw($id, array $inputs = []) } catch (Exception $exception) { DB::rollBack(); - throw new PDOException($exception->getMessage(), 0, $exception); + throw new \ErrorException($exception->getMessage(), 0, $exception); } } - public function update($id, array $inputs = []) + /** + * @throws \ErrorException + */ + public function updateFromAdmin($id, array $inputs = []): ?BaseModel { DB::beginTransaction(); @@ -176,7 +182,7 @@ public function update($id, array $inputs = []) } catch (Exception $exception) { DB::rollBack(); - throw new PDOException($exception->getMessage(), 0, $exception); + throw new \ErrorException($exception->getMessage(), 0, $exception); } }