Browse Source

update menu setting

master
Gunawan19621 11 months ago
parent
commit
d7f34038e7
  1. 40
      app/Http/Controllers/Auth/PasswordController.php
  2. 28
      app/Http/Controllers/ProfileController.php
  3. 2
      app/Http/Requests/ProfileUpdateRequest.php
  4. 218
      resources/views/profil/setting.blade.php

40
app/Http/Controllers/Auth/PasswordController.php

@ -2,28 +2,48 @@
namespace App\Http\Controllers\Auth; namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Http\RedirectResponse;
use Illuminate\Validation\Rules\Password; use Illuminate\Validation\Rules\Password;
use Illuminate\Validation\ValidationException;
class PasswordController extends Controller class PasswordController extends Controller
{ {
/** /**
* Update the user's password. * 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 public function update(Request $request): RedirectResponse
{ {
$validated = $request->validateWithBag('updatePassword', [ try {
'current_password' => ['required', 'current_password'], $validated = $request->validateWithBag('updatePassword', [
'password' => ['required', Password::defaults(), 'confirmed'], 'current_password' => ['required', 'current_password'],
]); 'password' => ['required', Password::defaults(), 'confirmed'],
]);
$request->user()->update([ $request->user()->update([
'password' => Hash::make($validated['password']), '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.');
}
} }
} }

28
app/Http/Controllers/ProfileController.php

@ -82,16 +82,32 @@ class ProfileController extends Controller
} }
//Proses update Profile Informasi //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 public function update(ProfileUpdateRequest $request): RedirectResponse
{ {
$request->user()->fill($request->validated()); try {
$request->user()->fill($request->validated());
if ($request->user()->isDirty('email')) { if ($request->user()->isDirty('email')) {
$request->user()->email_verified_at = null; $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.');
}
} }
} }

2
app/Http/Requests/ProfileUpdateRequest.php

@ -16,7 +16,7 @@ class ProfileUpdateRequest extends FormRequest
public function rules(): array public function rules(): array
{ {
return [ return [
'name' => ['string', 'max:255'], 'fullname' => ['string', 'max:255'],
'email' => ['email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)], 'email' => ['email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)],
]; ];
} }

218
resources/views/profil/setting.blade.php

@ -3,6 +3,17 @@
<!-- Informasi Akun --> <!-- Informasi Akun -->
<div class="card mb-2"> <div class="card mb-2">
<div class="card-body"> <div class="card-body">
@if (Session::has('success'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>{{ Session::get('success') }}</strong>
</div>
@endif
@if (Session::has('error'))
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>{{ Session::get('error') }}</strong>
</div>
@endif
<header> <header>
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100"> <h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
Informasi Akun Informasi Akun
@ -20,7 +31,7 @@
@csrf @csrf
@method('patch') @method('patch')
<div class="mb-4"> <div class="mb-1">
<div class="row"> <div class="row">
<div class="col-2"> <div class="col-2">
<label for="fullname" class="block text-gray-700 text-sm font-bold mt-2 ml-3">Full <label for="fullname" class="block text-gray-700 text-sm font-bold mt-2 ml-3">Full
@ -28,7 +39,7 @@
</div> </div>
<div class="col-10"> <div class="col-10">
<input id="fullname" name="fullname" type="text" <input id="fullname" name="fullname" type="text"
class="p-2 w-full border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500" class="p-1 w-full border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500"
value="{{ old('fullname', $user->fullname) }}" required autofocus value="{{ old('fullname', $user->fullname) }}" required autofocus
autocomplete="fullname"> autocomplete="fullname">
@if ($errors->has('fullname')) @if ($errors->has('fullname'))
@ -44,7 +55,7 @@
</div> </div>
<div class="col-10"> <div class="col-10">
<input id="email" name="email" type="email" <input id="email" name="email" type="email"
class="mt-1 p-2 w-full border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500" class="p-1 w-full border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500"
value="{{ old('email', $user->email) }}" required autocomplete="email"> value="{{ old('email', $user->email) }}" required autocomplete="email">
@if ($errors->has('email')) @if ($errors->has('email'))
<p class="text-red-500 text-sm mt-1">{{ $errors->first('email') }}</p> <p class="text-red-500 text-sm mt-1">{{ $errors->first('email') }}</p>
@ -68,19 +79,10 @@
</div> </div>
</div> </div>
<div class="flex items-center space-x-4 mt-2"> <button type="submit"
<button type="submit" class="btn btn-sm btn-primary hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded">
class="btn btn-sm btn-primary hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded"> Simpan
Simpan </button>
</button>
@if (session('status') === 'profile-updated')
<p x-data="{ show: true }" x-show="show" x-transition x-init="setTimeout(() => show = false, 2000)"
class="text-gray-600">
Tersimpan.
</p>
@endif
</div>
</form> </form>
</div> </div>
</div> </div>
@ -89,6 +91,17 @@
<!-- Ganti Password--> <!-- Ganti Password-->
<div class="card mb-2"> <div class="card mb-2">
<div class="card-body"> <div class="card-body">
@if (Session::has('success-password'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>{{ Session::get('success-password') }}</strong>
</div>
@endif
@if (Session::has('error-password'))
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>{{ Session::get('error-password') }}</strong>
</div>
@endif
<header> <header>
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100"> <h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
Ubah Password Ubah Password
@ -100,46 +113,64 @@
<form method="post" action="{{ route('password.update') }}" class="mt-6 space-y-6"> <form method="post" action="{{ route('password.update') }}" class="mt-6 space-y-6">
@csrf @csrf
@method('put') @method('put')
<div class="mb-2">
<div> <div class="row">
<label for="current_password" class="block font-semibold text-gray-800"> <div class="col-2">
kata sandi saat ini <label for="current_password" class="block text-gray-700 text-sm font-bold mt-2 ml-3">kata sandi
</label> saat ini</label>
<input id="current_password" name="current_password" type="password" class="mt-1 block w-full" </div>
autocomplete="current-password"> <div class="col-10">
@if ($errors->has('updatePassword.current_password')) <input id="current_password" name="current_password" type="password"
<p class="text-red-500">{{ $errors->first('updatePassword.current_password') }}</p> class="p-1 w-full border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500"
@endif autocomplete="current-password">
@if ($errors->has('updatePassword.current_password'))
<p class="text-red-500">{{ $errors->first('updatePassword.current_password') }}</p>
@endif
</div>
</div>
</div> </div>
<div> <div class="mb-2">
<label for="password" class="block font-semibold text-gray-800"> <div class="row">
kata sandi baru <div class="col-2">
</label> <label for="password" class="block text-gray-700 text-sm font-bold mt-2 ml-3">kata sandi
<input id="password" name="password" type="password" class="mt-1 block w-full" baru</label>
autocomplete="new-password"> </div>
@if ($errors->has('updatePassword.password')) <div class="col-10">
<p class="text-red-500">{{ $errors->first('updatePassword.password') }}</p> <input id="password" name="password" type="password"
@endif class="p-1 w-full border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500"
autocomplete="new-password">
@if ($errors->has('updatePassword.password'))
<p class="text-red-500">{{ $errors->first('updatePassword.password') }}</p>
@endif
</div>
</div>
</div> </div>
<div> <div class="mb-2">
<label for="password_confirmation" class="block font-semibold text-gray-800"> <div class="row">
konfirmasi sandi <div class="col-2">
</label> <label for="password_confirmation"
<input id="password_confirmation" name="password_confirmation" type="password" class="mt-1 block w-full" class="block text-gray-700 text-sm font-bold mt-2 ml-3">konfirmasi sandi</label>
autocomplete="new-password"> </div>
@if ($errors->has('updatePassword.password_confirmation')) <div class="col-10">
<p class="text-red-500">{{ $errors->first('updatePassword.password_confirmation') }}</p> <input id="password_confirmation" name="password_confirmation" type="password"
@endif class="p-1 w-full border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500"
autocomplete="new-password">
@if ($errors->has('updatePassword.password_confirmation'))
<p class="text-red-500">{{ $errors->first('updatePassword.password_confirmation') }}</p>
@endif
</div>
</div>
</div> </div>
<div class="flex items-center space-x-4"> <div class="flex items-center space-x-4 mt-2">
<button type="submit" <button type="submit"
class="btn btn-sm btn-primary hover:bg-blue-800 text-white font-semibold py-2 px-4 rounded"> class="btn btn-sm btn-primary hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded">
Save Simpan
</button> </button>
@if (session('status') === 'password-updated') @if (session('status') === 'password-updated')
<p x-data="{ show: true }" x-show="show" x-transition x-init="setTimeout(() => show = false, 2000)" <p x-data="{ show: true }" x-show="show" x-transition x-init="setTimeout(() => show = false, 2000)"
class="text-sm text-gray-600"> class="text-gray-600">
Saved. Tersimpan.
</p> </p>
@endif @endif
</div> </div>
@ -147,83 +178,14 @@
</div> </div>
</div> </div>
{{-- <div class="card mb-2"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<div class="card-body"> <script>
<form method="POST" action="{{ route('profile.destroy') }}" class="mt-6 space-y-6"> $(document).ready(function() {
@csrf setTimeout(function() {
@method('DELETE') $(".alert.alert-danger, .alert.alert-success").fadeOut(500, function() {
$(this).remove();
<div> });
<x-danger-button type="submit">Delete Account</x-danger-button> }, 3000); // 5 detik
</div> });
</form> --}} </script>
{{-- <header>
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
Delete Account
</h2>
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
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.
</p>
</header>
<button x-data="" x-on:click.prevent="$dispatch('open-modal', 'confirm-user-deletion')"
class="bg-red-500 hover:bg-red-700 text-white font-semibold py-2 px-4 rounded">
Delete Account
</button>
<div x-data="{ show: false }">
<div x-on:confirm-user-deletion.window="show = true"></div>
<div x-show="show" x-transition:enter="transition ease-out duration-300"
x-transition:enter-start="opacity-0" x-transition:enter-end="opacity-100"
x-transition:leave="transition ease-in duration-200" x-transition:leave-start="opacity-100"
x-transition:leave-end="opacity-0"
class="fixed inset-0 flex items-center justify-center z-50 bg-black bg-opacity-50">
<form method="post" action="{{ route('profile.destroy') }}" class="bg-white p-6 rounded-lg shadow-xl">
@csrf
@method('delete')
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
Are you sure you want to delete your account?
</h2>
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
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.
</p>
<div class="mt-6">
<label for="password" class="block font-semibold text-gray-800 sr-only">
Password
</label>
<input id="password" name="password" type="password" class="mt-1 block w-3/4"
placeholder="Password">
<div class="text-red-500 mt-2">
@if ($errors->has('userDeletion.password'))
{{ $errors->first('userDeletion.password') }}
@endif
</div>
</div>
<div class="mt-6 flex justify-end">
<button type="button" x-on:click="show = false"
class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-semibold py-2 px-4 rounded">
Cancel
</button>
<button type="submit"
class="bg-red-500 hover:bg-red-700 text-white font-semibold py-2 px-4 rounded ml-3">
Delete Account
</button>
</div>
</form>
</div>
</div> --}}
{{-- @include('profile.partials.delete-user-form') --}}
{{-- </div>
</div> --}}
@endsection @endsection

Loading…
Cancel
Save