This commit is contained in:
Ahmad Firdaus Tarmidzi 2023-11-05 20:38:44 +07:00
parent cf996d1152
commit a779f454a7
3 changed files with 72 additions and 29 deletions

View File

@ -5,6 +5,7 @@
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class ProfileController extends Controller
{
@ -40,4 +41,25 @@ public function update(Request $request)
return redirect('/dashboard')->with('success', 'Profile updated successfully');
}
public function changePassword(Request $request){
$request->validate([
'current_password' => 'required',
'new_password' => 'required|string|min:8|confirmed',
]);
$user = Auth::user();
// Verify the current password using the fully qualified namespace
if (!\Illuminate\Support\Facades\Hash::check($request->input('current_password'), $user->password)) {
return redirect()->back()->with('error', 'Current password is incorrect');
}
// Update the password
$user->password = \Illuminate\Support\Facades\Hash::make($request->input('new_password'));
$user->save();
return redirect()->back()->with('success', 'Password changed successfully');
}
}

View File

@ -55,22 +55,38 @@
<div class="row">
<div class="col-lg-3 col-md-4 label ">{{ __('Nama Lengkap') }}</div>
<div class="col-lg-9 col-md-8">Raditya Arief Pratama</div>
<div class="col-lg-9 col-md-8">
@if(Auth::user())
{{ Auth::user()->nama_lengkap }}
@endif
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">{{ __('NIM') }}</div>
<div class="col-lg-9 col-md-8">E4212423</div>
<div class="col-lg-9 col-md-8">
@if(Auth::user())
{{ Auth::user()->nim }}
@endif
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">{{ __('Semester') }}</div>
<div class="col-lg-9 col-md-8">5</div>
<div class="col-lg-9 col-md-8">
@if(Auth::user())
{{ Auth::user()->semester }}
@endif
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">{{ __('Angkatan') }}</div>
<div class="col-lg-9 col-md-8">2021</div>
<div class="col-lg-9 col-md-8">
@if(Auth::user())
{{ Auth::user()->angkatan }}
@endif
</div>
</div>
<div class="row">
@ -131,34 +147,36 @@
<div class="tab-pane fade pt-3" id="profile-change-password">
<!-- Change Password Form -->
<form>
<!-- Change Password Form -->
<form method="POST" action="{{ route('profile.changePassword') }}">
@csrf
<div class="row mb-3">
<label for="currentPassword" class="col-md-4 col-lg-3 col-form-label">Current Password</label>
<div class="col-md-8 col-lg-9">
<input name="password" type="password" class="form-control" id="currentPassword">
</div>
</div>
<div class="row mb-3">
<label for="current_password" class="col-md-4 col-lg-3 col-form-label">Current Password</label>
<div class="col-md-8 col-lg-9">
<input name="current_password" type="password" class="form-control" id="current_password">
</div>
</div>
<div class="row mb-3">
<label for="newPassword" class="col-md-4 col-lg-3 col-form-label">New Password</label>
<div class="col-md-8 col-lg-9">
<input name="newpassword" type="password" class="form-control" id="newPassword">
</div>
</div>
<div class="row mb-3">
<label for="new_password" class="col-md-4 col-lg-3 col-form-label">New Password</label>
<div class="col-md-8 col-lg-9">
<input name="new_password" type="password" class="form-control" id="new_password">
</div>
</div>
<div class="row mb-3">
<label for="renewPassword" class="col-md-4 col-lg-3 col-form-label">Re-enter New Password</label>
<div class="col-md-8 col-lg-9">
<input name="renewpassword" type="password" class="form-control" id="renewPassword">
</div>
</div>
<div class="row mb-3">
<label for="new_password_confirmation" class="col-md-4 col-lg-3 col-form-label">Re-enter New Password</label>
<div class="col-md-8 col-lg-9">
<input name="new_password_confirmation" type="password" class="form-control" id="new_password_confirmation">
</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary">Change Password</button>
</div>
</form><!-- End Change Password Form -->
<div class="text-center">
<button type="submit" class="btn btn-primary">Change Password</button>
</div>
</form>
<!-- End Change Password Form -->
</div>

View File

@ -39,7 +39,10 @@
Route::get('instruction', 'UiController@instruction')->name('user.questionnaire.instruction');
Route::get('check-questionnaire', 'UiController@checkQuestionnaire')->name('user.questionnaire.check');
Route::get('closed-questionnaire', 'UiController@closedQuestionnaire')->name('user.questionnaire.closed');
Route::post('/profile/update', 'Backend\ProfileController@update');
Route::post('/profile/update', 'ProfileController@update');
Route::get('/profile/change-password', 'ProfileController@changePasswordForm')->name('profile.changePasswordForm');
Route::post('/profile/change-password', 'ProfileController@changePassword')->name('profile.changePassword');
});
});