From d7f34038e73c8c217d787f5f4a8e5bcdd2e37d14 Mon Sep 17 00:00:00 2001 From: Gunawan19621 Date: Wed, 20 Dec 2023 20:39:25 +0700 Subject: [PATCH] update menu setting --- .../Controllers/Auth/PasswordController.php | 40 +++- app/Http/Controllers/ProfileController.php | 28 ++- app/Http/Requests/ProfileUpdateRequest.php | 2 +- resources/views/profil/setting.blade.php | 218 ++++++++---------- 4 files changed, 143 insertions(+), 145 deletions(-) diff --git a/app/Http/Controllers/Auth/PasswordController.php b/app/Http/Controllers/Auth/PasswordController.php index 6916409..948bd9d 100644 --- a/app/Http/Controllers/Auth/PasswordController.php +++ b/app/Http/Controllers/Auth/PasswordController.php @@ -2,28 +2,48 @@ namespace App\Http\Controllers\Auth; -use App\Http\Controllers\Controller; -use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Hash; +use Illuminate\Http\RedirectResponse; use Illuminate\Validation\Rules\Password; +use Illuminate\Validation\ValidationException; class PasswordController extends Controller { /** * Update the user's password. */ + // public function update(Request $request): RedirectResponse + // { + // $validated = $request->validateWithBag('updatePassword', [ + // 'current_password' => ['required', 'current_password'], + // 'password' => ['required', Password::defaults(), 'confirmed'], + // ]); + + // $request->user()->update([ + // 'password' => Hash::make($validated['password']), + // ]); + + // return back()->with('status', 'password-updated'); + // } public function update(Request $request): RedirectResponse { - $validated = $request->validateWithBag('updatePassword', [ - 'current_password' => ['required', 'current_password'], - 'password' => ['required', Password::defaults(), 'confirmed'], - ]); + try { + $validated = $request->validateWithBag('updatePassword', [ + 'current_password' => ['required', 'current_password'], + 'password' => ['required', Password::defaults(), 'confirmed'], + ]); - $request->user()->update([ - 'password' => Hash::make($validated['password']), - ]); + $request->user()->update([ + 'password' => Hash::make($validated['password']), + ]); - return back()->with('status', 'password-updated'); + return back()->with('success-password', 'Password berhasil diperbarui.'); + } catch (ValidationException $e) { + return back()->withErrors($e->errors(), 'updatePassword')->with('error-password', 'Gagal memperbarui password. Silakan periksa kembali masukan Anda.'); + } catch (\Exception $e) { + return back()->with('error-password', 'Gagal memperbarui password. Silakan coba lagi.'); + } } } diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index c36e0cf..8fb882c 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -82,16 +82,32 @@ class ProfileController extends Controller } //Proses update Profile Informasi + // public function update(ProfileUpdateRequest $request): RedirectResponse + // { + // $request->user()->fill($request->validated()); + + // if ($request->user()->isDirty('email')) { + // $request->user()->email_verified_at = null; + // } + + // $request->user()->save(); + + // return Redirect::back()->with('status', 'profile-updated'); + // } public function update(ProfileUpdateRequest $request): RedirectResponse { - $request->user()->fill($request->validated()); + try { + $request->user()->fill($request->validated()); - if ($request->user()->isDirty('email')) { - $request->user()->email_verified_at = null; - } + if ($request->user()->isDirty('email')) { + $request->user()->email_verified_at = null; + } - $request->user()->save(); + $request->user()->save(); - return Redirect::back()->with('status', 'profile-updated'); + return Redirect::back()->with('success', 'Akun berhasil diupdate.'); + } catch (\Exception $e) { + return Redirect::back()->with('error', 'Gagal mengupdate akun. Silakan coba lagi.'); + } } } diff --git a/app/Http/Requests/ProfileUpdateRequest.php b/app/Http/Requests/ProfileUpdateRequest.php index 327ce6f..58b85b9 100644 --- a/app/Http/Requests/ProfileUpdateRequest.php +++ b/app/Http/Requests/ProfileUpdateRequest.php @@ -16,7 +16,7 @@ class ProfileUpdateRequest extends FormRequest public function rules(): array { return [ - 'name' => ['string', 'max:255'], + 'fullname' => ['string', 'max:255'], 'email' => ['email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)], ]; } diff --git a/resources/views/profil/setting.blade.php b/resources/views/profil/setting.blade.php index 549ffa4..a124c8a 100644 --- a/resources/views/profil/setting.blade.php +++ b/resources/views/profil/setting.blade.php @@ -3,6 +3,17 @@
+ @if (Session::has('success')) + + @endif + + @if (Session::has('error')) + + @endif

Informasi Akun @@ -20,7 +31,7 @@ @csrf @method('patch') -
+
@if ($errors->has('fullname')) @@ -44,7 +55,7 @@
@if ($errors->has('email'))

{{ $errors->first('email') }}

@@ -68,19 +79,10 @@
-
- - - @if (session('status') === 'profile-updated') -

- Tersimpan. -

- @endif -
+
@@ -89,6 +91,17 @@
+ @if (Session::has('success-password')) + + @endif + + @if (Session::has('error-password')) + + @endif

Ubah Password @@ -100,46 +113,64 @@
@csrf @method('put') - -
- - - @if ($errors->has('updatePassword.current_password')) -

{{ $errors->first('updatePassword.current_password') }}

- @endif +
+
+
+ +
+
+ + @if ($errors->has('updatePassword.current_password')) +

{{ $errors->first('updatePassword.current_password') }}

+ @endif +
+
-
- - - @if ($errors->has('updatePassword.password')) -

{{ $errors->first('updatePassword.password') }}

- @endif +
+
+
+ +
+
+ + @if ($errors->has('updatePassword.password')) +

{{ $errors->first('updatePassword.password') }}

+ @endif +
+
-
- - - @if ($errors->has('updatePassword.password_confirmation')) -

{{ $errors->first('updatePassword.password_confirmation') }}

- @endif +
+
+
+ +
+
+ + @if ($errors->has('updatePassword.password_confirmation')) +

{{ $errors->first('updatePassword.password_confirmation') }}

+ @endif +
+
-
+
+ @if (session('status') === 'password-updated')

- Saved. + class="text-gray-600"> + Tersimpan.

@endif
@@ -147,83 +178,14 @@
- {{--
-
- - @csrf - @method('DELETE') - -
- Delete Account -
- --}} - {{--
-

- Delete Account -

- -

- Once your account is deleted, all of its resources and data will be permanently deleted. Before deleting - your account, please download any data or information that you wish to retain. -

-
- - - -
-
- -
-
- @csrf - @method('delete') - -

- Are you sure you want to delete your account? -

- -

- Once your account is deleted, all of its resources and data will be permanently deleted. Please - enter your password to confirm you would like to permanently delete your account. -

- -
- - - - -
- @if ($errors->has('userDeletion.password')) - {{ $errors->first('userDeletion.password') }} - @endif -
-
- -
- - - -
-
-
-
--}} - {{-- @include('profile.partials.delete-user-form') --}} - {{--
-
--}} + + @endsection