Browse Source

update menu setting

master
Gunawan19621 1 year 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;
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.');
}
}
}

28
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.');
}
}
}

2
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)],
];
}

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

@ -3,6 +3,17 @@
<!-- Informasi Akun -->
<div class="card mb-2">
<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>
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
Informasi Akun
@ -20,7 +31,7 @@
@csrf
@method('patch')
<div class="mb-4">
<div class="mb-1">
<div class="row">
<div class="col-2">
<label for="fullname" class="block text-gray-700 text-sm font-bold mt-2 ml-3">Full
@ -28,7 +39,7 @@
</div>
<div class="col-10">
<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
autocomplete="fullname">
@if ($errors->has('fullname'))
@ -44,7 +55,7 @@
</div>
<div class="col-10">
<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">
@if ($errors->has('email'))
<p class="text-red-500 text-sm mt-1">{{ $errors->first('email') }}</p>
@ -68,19 +79,10 @@
</div>
</div>
<div class="flex items-center space-x-4 mt-2">
<button type="submit"
class="btn btn-sm btn-primary hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded">
Simpan
</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>
<button type="submit"
class="btn btn-sm btn-primary hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded">
Simpan
</button>
</form>
</div>
</div>
@ -89,6 +91,17 @@
<!-- Ganti Password-->
<div class="card mb-2">
<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>
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
Ubah Password
@ -100,46 +113,64 @@
<form method="post" action="{{ route('password.update') }}" class="mt-6 space-y-6">
@csrf
@method('put')
<div>
<label for="current_password" class="block font-semibold text-gray-800">
kata sandi saat ini
</label>
<input id="current_password" name="current_password" type="password" class="mt-1 block w-full"
autocomplete="current-password">
@if ($errors->has('updatePassword.current_password'))
<p class="text-red-500">{{ $errors->first('updatePassword.current_password') }}</p>
@endif
<div class="mb-2">
<div class="row">
<div class="col-2">
<label for="current_password" class="block text-gray-700 text-sm font-bold mt-2 ml-3">kata sandi
saat ini</label>
</div>
<div class="col-10">
<input id="current_password" name="current_password" type="password"
class="p-1 w-full border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500"
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>
<label for="password" class="block font-semibold text-gray-800">
kata sandi baru
</label>
<input id="password" name="password" type="password" class="mt-1 block w-full"
autocomplete="new-password">
@if ($errors->has('updatePassword.password'))
<p class="text-red-500">{{ $errors->first('updatePassword.password') }}</p>
@endif
<div class="mb-2">
<div class="row">
<div class="col-2">
<label for="password" class="block text-gray-700 text-sm font-bold mt-2 ml-3">kata sandi
baru</label>
</div>
<div class="col-10">
<input id="password" name="password" type="password"
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>
<label for="password_confirmation" class="block font-semibold text-gray-800">
konfirmasi sandi
</label>
<input id="password_confirmation" name="password_confirmation" type="password" class="mt-1 block w-full"
autocomplete="new-password">
@if ($errors->has('updatePassword.password_confirmation'))
<p class="text-red-500">{{ $errors->first('updatePassword.password_confirmation') }}</p>
@endif
<div class="mb-2">
<div class="row">
<div class="col-2">
<label for="password_confirmation"
class="block text-gray-700 text-sm font-bold mt-2 ml-3">konfirmasi sandi</label>
</div>
<div class="col-10">
<input id="password_confirmation" name="password_confirmation" type="password"
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 class="flex items-center space-x-4">
<div class="flex items-center space-x-4 mt-2">
<button type="submit"
class="btn btn-sm btn-primary hover:bg-blue-800 text-white font-semibold py-2 px-4 rounded">
Save
class="btn btn-sm btn-primary hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded">
Simpan
</button>
@if (session('status') === 'password-updated')
<p x-data="{ show: true }" x-show="show" x-transition x-init="setTimeout(() => show = false, 2000)"
class="text-sm text-gray-600">
Saved.
class="text-gray-600">
Tersimpan.
</p>
@endif
</div>
@ -147,83 +178,14 @@
</div>
</div>
{{-- <div class="card mb-2">
<div class="card-body">
<form method="POST" action="{{ route('profile.destroy') }}" class="mt-6 space-y-6">
@csrf
@method('DELETE')
<div>
<x-danger-button type="submit">Delete Account</x-danger-button>
</div>
</form> --}}
{{-- <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> --}}
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
setTimeout(function() {
$(".alert.alert-danger, .alert.alert-success").fadeOut(500, function() {
$(this).remove();
});
}, 3000); // 5 detik
});
</script>
@endsection

Loading…
Cancel
Save