feat: user account setting
This commit is contained in:
parent
9abf7707b3
commit
63b5a5f7e3
@ -3,6 +3,8 @@
|
||||
namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\AccountSettingRequest;
|
||||
use App\Http\Requests\ChangePasswordRequest;
|
||||
use App\Http\Requests\ResetPasswordRequest;
|
||||
use App\Http\Requests\UserRequest;
|
||||
use App\Models\LoginHistory;
|
||||
@ -101,6 +103,7 @@ public function resetPassword($id){
|
||||
|
||||
return view('dashboard.users.reset-password',[
|
||||
'title' => 'Reset Password',
|
||||
'page' => 'reset',
|
||||
'user' => $user
|
||||
]);
|
||||
}
|
||||
@ -246,5 +249,53 @@ public function process($id, $type, $process){
|
||||
return view('dashboard.users.profiles.journalists', $data);
|
||||
}
|
||||
}
|
||||
public function setting(){
|
||||
$user = Auth::user();
|
||||
|
||||
return view('dashboard.users.setting', [
|
||||
'title' => 'Pengaturan Akun',
|
||||
'user' => $user,
|
||||
]);
|
||||
}
|
||||
|
||||
public function settingAction(AccountSettingRequest $request){
|
||||
$validatedData = $request->validated();
|
||||
|
||||
$user = User::findOrFail(Auth::id());
|
||||
$updatedUser = $user->update([
|
||||
'name' => $validatedData['name'],
|
||||
'email' => $validatedData['email'],
|
||||
]);
|
||||
|
||||
if($updatedUser){
|
||||
return redirect()->back()->with('success-status', 'Berhasil mengubah data akun.');
|
||||
}else{
|
||||
return redirect()->back()->with('failed-status', 'Gagal mengubah data akun.');
|
||||
}
|
||||
}
|
||||
|
||||
public function changePassword(){
|
||||
$user = User::with(['role'])->findOrFail(Auth::id());
|
||||
|
||||
return view('dashboard.users.reset-password',[
|
||||
'title' => 'Ubah Password',
|
||||
'page' => 'change',
|
||||
'user' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
public function changePasswordAction(ChangePasswordRequest $request){
|
||||
$validatedData = $request->validated();
|
||||
|
||||
$updatedUser = User::findOrFail(Auth::id())->update([
|
||||
'password' => $validatedData['password']
|
||||
]);
|
||||
|
||||
if($updatedUser){
|
||||
return redirect()->route('dashboard.users.setting')->with('success-status', 'Berhasil mengubah password.');
|
||||
}else{
|
||||
return redirect()->back()->with('failed-status', 'Gagal mengubah password.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
42
app/Http/Requests/AccountSettingRequest.php
Normal file
42
app/Http/Requests/AccountSettingRequest.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AccountSettingRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'max:100'],
|
||||
'email' => ['required', 'email', 'max:100'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'name.required' => 'Nama wajib diisi.',
|
||||
'name.max' => 'Nama tidak boleh lebih dari 100 karakter.',
|
||||
|
||||
'email.required' => 'Email wajib diisi.',
|
||||
'email.email' => 'Email harus menggunakan format email yang valid.',
|
||||
'email.max' => 'Email tidak boleh lebih dari 100 karakter.',
|
||||
];
|
||||
}
|
||||
}
|
||||
57
app/Http/Requests/ChangePasswordRequest.php
Normal file
57
app/Http/Requests/ChangePasswordRequest.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Rules\MatchCurrentPasswordRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class ChangePasswordRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'password' => ['required', 'confirmed', Password::min(8)
|
||||
->mixedCase()
|
||||
->numbers()
|
||||
->symbols()],
|
||||
'my_password' => ['required', Password::min(8)
|
||||
->mixedCase()
|
||||
->numbers()
|
||||
->symbols(), new MatchCurrentPasswordRule()],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'password.required' => 'Password baru wajib diisi.',
|
||||
'password.confirmed' => 'Konfirmasi password baru tidak cocok.',
|
||||
'password.min' => 'Password baru harus memiliki minimal 8 karakter.',
|
||||
'password.mixedCase' => 'Password baru harus mengandung huruf besar dan huruf kecil.',
|
||||
'password.numbers' => 'Password baru harus mengandung angka.',
|
||||
'password.symbols' => 'Password baru harus mengandung simbol.',
|
||||
|
||||
'my_password.required' => 'Password Anda wajib diisi.',
|
||||
'my_password.confirmed' => 'Konfirmasi password Anda tidak cocok.',
|
||||
'my_password.min' => 'Password Anda harus memiliki minimal 8 karakter.',
|
||||
'my_password.mixedCase' => 'Password Anda harus mengandung huruf besar dan huruf kecil.',
|
||||
'my_password.numbers' => 'Password Anda harus mengandung angka.',
|
||||
'my_password.symbols' => 'Password Anda harus mengandung simbol.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -11,13 +11,13 @@
|
||||
<div class="card-inner card-inner-lg">
|
||||
<div class="nk-block-head">
|
||||
<div class="nk-block-head-content">
|
||||
<h5 class="nk-block-title">Reset Kata Sandi</h5>
|
||||
<h5 class="nk-block-title">{{$page === 'reset' ? 'Reset' : 'Ganti'}} Kata Sandi</h5>
|
||||
<div class="nk-block-des">
|
||||
<p>Ubah kata sandi akun dan login menggunakan kata sandi baru.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form action="{{route('dashboard.users.reset.password.action', ['id' => encrypt_id($user->id)])}}" method="post">
|
||||
<form action="{{$page === 'reset' ? route('dashboard.users.reset.password.action', ['id' => encrypt_id($user->id)]) : route('dashboard.users.setting.change.password.action')}}" method="post" id="myForm">
|
||||
@csrf
|
||||
<div class="form-group">
|
||||
<div class="form-label-group">
|
||||
@ -51,7 +51,7 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="form-label-group">
|
||||
<label class="form-label" for="your-password">Kata Sandi Anda ({{Auth::user()->name}})</label>
|
||||
<label class="form-label" for="your-password">Kata Sandi Anda ({{$page === 'reset' ? Auth::user()->name : 'Saat Ini'}})</label>
|
||||
</div>
|
||||
<div class="form-control-wrap">
|
||||
<input type="password" class="form-control form-control-lg" id="your-password" placeholder="Kata sandi Anda" name="my_password">
|
||||
@ -61,11 +61,11 @@
|
||||
@enderror
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button class="btn btn-lg btn-primary btn-block">Reset Kata Sandi</button>
|
||||
<button type="button" class="btn btn-lg btn-primary btn-block" id="submitButton">{{$page === 'reset' ? 'Reset' : 'Ganti'}} Kata Sandi</button>
|
||||
</div>
|
||||
</form>
|
||||
<div class="form-note-s2 text-center pt-4">
|
||||
<a href="{{route('dashboard.users.index')}}"><strong>Kembali</strong></a>
|
||||
<a href="{{$page === 'reset' ? route('dashboard.users.index') : route('dashboard.users.setting')}}"><strong>Kembali</strong></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
86
resources/views/dashboard/users/setting.blade.php
Normal file
86
resources/views/dashboard/users/setting.blade.php
Normal file
@ -0,0 +1,86 @@
|
||||
@include('partials.dashboard.head')
|
||||
@include('partials.dashboard.sidebar', ['page' => 'users'])
|
||||
@include('partials.dashboard.header')
|
||||
<!-- content @s -->
|
||||
<div class="nk-content ">
|
||||
<div class="container-fluid">
|
||||
<div class="nk-content-inner">
|
||||
<div class="nk-content-body">
|
||||
{{-- <div class="nk-block-head nk-block-head-sm">
|
||||
<div class="nk-block-between">
|
||||
<div class="nk-block-head-content">
|
||||
<h3 class="nk-block-title page-title">Settings</h3>
|
||||
</div><!-- .nk-block-head-content -->
|
||||
</div><!-- .nk-block-between -->
|
||||
</div><!-- .nk-block-head --> --}}
|
||||
<div class="nk-block">
|
||||
<div class="card">
|
||||
<div class="card-inner">
|
||||
<h5 class="card-title">Pengaturan Akun</h5>
|
||||
<p>Kelola pengaturan dasar akun Anda disini.</p>
|
||||
<form action="{{route('dashboard.users.setting.action')}}" class="gy-3 form-settings" id="myForm" method="post">
|
||||
@csrf
|
||||
<div class="row g-3 align-center">
|
||||
<div class="col-lg-5">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="site-name">Username</label>
|
||||
<span class="form-note">Nama lengkap Anda</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-7">
|
||||
<div class="form-group">
|
||||
<div class="form-control-wrap">
|
||||
<input type="text" class="form-control" id="site-name" value="{{$user->name}}" name="name">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row g-3 align-center">
|
||||
<div class="col-lg-5">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="site-email">Email</label>
|
||||
<span class="form-note">Email yang Anda gunakan untuk login</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-7">
|
||||
<div class="form-group">
|
||||
<div class="form-control-wrap">
|
||||
<input type="text" class="form-control" id="site-email" value="{{$user->email}}" name="email">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row g-3 align-center">
|
||||
<div class="col-lg-5">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="site-off">Keamanan</label>
|
||||
<span class="form-note">Selalu ubah kata sandi Anda secara berkala</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-7">
|
||||
<div class="form-group">
|
||||
<div>
|
||||
<a href="{{route('dashboard.users.setting.change.password')}}" class="btn btn-primary"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-shield-lock" style="margin-right: 0.3rem;"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 3a12 12 0 0 0 8.5 3a12 12 0 0 1 -8.5 15a12 12 0 0 1 -8.5 -15a12 12 0 0 0 8.5 -3" /><path d="M12 11m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" /><path d="M12 12l0 2.5" /></svg> Ubah Kata Sandi</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="nk-divider divider md"></div>
|
||||
<div class="row" style="margin-top: -1.1rem;">
|
||||
<div class="col-lg-7" style="display: flex; justify-content: end;">
|
||||
<div class="form-group">
|
||||
<a href="{{route('dashboard.overview')}}" class="btn btn-white btn-dim btn-outline-light mx-1">Kembali</a>
|
||||
<button type="button" class="btn btn-primary" id="submitButton">Simpan</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div><!-- .card-inner -->
|
||||
</div><!-- .card -->
|
||||
</div><!-- .nk-block -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- content @e -->
|
||||
@include('partials.dashboard.footer', ['rich_editor' => false])
|
||||
@ -136,7 +136,7 @@
|
||||
<div class="dropdown-inner">
|
||||
<ul class="link-list">
|
||||
<li><a href="{{route('dashboard.users.profile', ['type' => 'account'])}}"><em class="icon ni ni-user-alt"></em><span>Profile</span></a></li>
|
||||
<li><a href="javascript:void(0);"><em class="icon ni ni-setting-alt"></em><span>Pengaturan Akun</span></a></li>
|
||||
<li><a href="{{route('dashboard.users.setting')}}"><em class="icon ni ni-setting-alt"></em><span>Pengaturan Akun</span></a></li>
|
||||
<li><a class="dark-switch" href="#"><em class="icon ni ni-moon"></em><span>Mode Gelap</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -478,6 +478,11 @@
|
||||
});
|
||||
|
||||
Route::get('/profile/{type}', 'profile')->name('profile');
|
||||
|
||||
Route::get('/settings', 'setting')->name('setting');
|
||||
Route::post('/settings', 'settingAction')->name('setting.action');
|
||||
Route::get('/settings/change-password', 'changePassword')->name('setting.change.password');
|
||||
Route::post('/settings/change-password', 'changePasswordAction')->name('setting.change.password.action');
|
||||
});
|
||||
|
||||
Route::get('/data', [DatatableController::class, 'user'])->name('data');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user