diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php new file mode 100644 index 00000000..da9159fd --- /dev/null +++ b/app/Http/Controllers/ProfileController.php @@ -0,0 +1,60 @@ +user(); + $result = $this->profileService->updateProfile($user, $request->validated()); + + if ($result) { + return response()->json([ + 'success' => true, + 'message' => '프로필이 수정되었습니다.', + ]); + } + + return response()->json([ + 'success' => false, + 'message' => '프로필 수정에 실패했습니다.', + ], 500); + } + + /** + * 비밀번호 변경 + */ + public function changePassword(ChangePasswordRequest $request): JsonResponse + { + $user = auth()->user(); + $result = $this->profileService->changePassword( + $user, + $request->current_password, + $request->password + ); + + return response()->json($result, $result['success'] ? 200 : 422); + } +} diff --git a/app/Http/Requests/ChangePasswordRequest.php b/app/Http/Requests/ChangePasswordRequest.php new file mode 100644 index 00000000..8dde7492 --- /dev/null +++ b/app/Http/Requests/ChangePasswordRequest.php @@ -0,0 +1,56 @@ +|string> + */ + public function rules(): array + { + return [ + 'current_password' => 'required|string', + 'password' => 'required|string|min:8|confirmed', + ]; + } + + /** + * Get custom attributes for validator errors. + * + * @return array + */ + public function attributes(): array + { + return [ + 'current_password' => '현재 비밀번호', + 'password' => '새 비밀번호', + 'password_confirmation' => '새 비밀번호 확인', + ]; + } + + /** + * Get custom messages for validator errors. + * + * @return array + */ + public function messages(): array + { + return [ + 'password.confirmed' => '새 비밀번호가 일치하지 않습니다.', + 'password.min' => '비밀번호는 최소 8자 이상이어야 합니다.', + ]; + } +} diff --git a/app/Http/Requests/UpdateProfileRequest.php b/app/Http/Requests/UpdateProfileRequest.php new file mode 100644 index 00000000..87feec04 --- /dev/null +++ b/app/Http/Requests/UpdateProfileRequest.php @@ -0,0 +1,42 @@ +|string> + */ + public function rules(): array + { + return [ + 'name' => 'required|string|max:100', + 'phone' => 'nullable|string|max:20', + ]; + } + + /** + * Get custom attributes for validator errors. + * + * @return array + */ + public function attributes(): array + { + return [ + 'name' => '이름', + 'phone' => '연락처', + ]; + } +} diff --git a/app/Services/ProfileService.php b/app/Services/ProfileService.php new file mode 100644 index 00000000..d71d6e12 --- /dev/null +++ b/app/Services/ProfileService.php @@ -0,0 +1,53 @@ +name = $data['name']; + $user->phone = $data['phone'] ?? null; + $user->updated_by = $user->id; + + return $user->save(); + } + + /** + * 비밀번호 변경 + */ + public function changePassword(User $user, string $currentPassword, string $newPassword): array + { + // 현재 비밀번호 확인 + if (! Hash::check($currentPassword, $user->password)) { + return [ + 'success' => false, + 'message' => '현재 비밀번호가 일치하지 않습니다.', + ]; + } + + // 새 비밀번호가 현재 비밀번호와 동일한지 확인 + if (Hash::check($newPassword, $user->password)) { + return [ + 'success' => false, + 'message' => '새 비밀번호는 현재 비밀번호와 다르게 설정해주세요.', + ]; + } + + // 비밀번호 업데이트 + $user->password = Hash::make($newPassword); + $user->updated_by = $user->id; + $user->save(); + + return [ + 'success' => true, + 'message' => '비밀번호가 변경되었습니다.', + ]; + } +} diff --git a/resources/views/partials/header.blade.php b/resources/views/partials/header.blade.php index e0fb8934..e036a039 100644 --- a/resources/views/partials/header.blade.php +++ b/resources/views/partials/header.blade.php @@ -86,12 +86,9 @@ class="flex items-center gap-2 px-3 py-2 text-sm font-medium text-gray-700 hover - + 프로필 설정 - - 계정 설정 -
diff --git a/resources/views/profile/index.blade.php b/resources/views/profile/index.blade.php new file mode 100644 index 00000000..f7dbe44a --- /dev/null +++ b/resources/views/profile/index.blade.php @@ -0,0 +1,222 @@ +@extends('layouts.app') + +@section('title', '프로필 설정') + +@section('content') +
+ +
+

프로필 설정

+
+ + +
+

+ + + + 기본 정보 +

+ +
+
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+
+ + +
+ +
+
+
+ + +
+

+ + + + 비밀번호 변경 +

+ +
+
+ +
+ + +
+ + +
+ + +

최소 8자 이상 입력해주세요.

+
+ + +
+ + +
+
+ + +
+ +
+
+
+
+@endsection + +@push('scripts') + +@endpush \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 88d07ce7..afbd3c03 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,6 +11,7 @@ use App\Http\Controllers\ProjectManagementController; use App\Http\Controllers\RoleController; use App\Http\Controllers\RolePermissionController; +use App\Http\Controllers\ProfileController; use App\Http\Controllers\TenantController; use App\Http\Controllers\UserController; use Illuminate\Support\Facades\Route; @@ -40,6 +41,13 @@ // 테넌트 전환 Route::post('/tenant/switch', [TenantController::class, 'switch'])->name('tenant.switch'); + // 프로필 설정 + Route::prefix('profile')->name('profile.')->group(function () { + Route::get('/', [ProfileController::class, 'index'])->name('index'); + Route::post('/update', [ProfileController::class, 'update'])->name('update'); + Route::post('/password', [ProfileController::class, 'changePassword'])->name('password'); + }); + // 테넌트 관리 (Blade 화면만) Route::prefix('tenants')->name('tenants.')->group(function () { Route::get('/', [TenantController::class, 'index'])->name('index');