tambah change password

This commit is contained in:
Ramadhon Ikhsan Prasetya 2024-08-29 13:34:58 +07:00
parent 603e31b0f4
commit 2f08a4c0ce
9 changed files with 639 additions and 428 deletions

View File

@ -533,6 +533,68 @@ class OthersController extends Controller
}
}
public function user_change_password(Request $request) {
DB::beginTransaction();
try {
$user = User::find(Auth::user()->id);
$oldPassCheck = Hash::check($request->input('oldPassword'), $user->password);
if ($oldPassCheck == false) {
return response()->json([
'rc' => 99,
'data' => 'Password Lama Salah.'
]);
}
if ($request->input('newPassword') != $request->input('confirmPassword')) {
return response()->json([
'rc' => 99,
'data' => 'Password Baru dan Konfirmasi Password Harus Sama'
]);
}
if(Hash::check($request->input('newPassword'), $user->password)) {
return response()->json([
'rc' => 99,
'data' => 'Password tidak boleh sama dengan password existing'
]);
}
$regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$^";
if (preg_match($regexp, $request->input('newPassword'))){
$user->password = Hash::make($request->input('newPassword'));
$user->save();
DB::commit();
return response()->json([
'rc' => 0,
'data' => "Password Baru Berhasil Tersimpan"
]);
} else {
return response()->json([
'rc' => 99,
'data' => "Gagal, Format password baru tidak sesuai dengan ketentuan"
]);
}
} catch (\Throwable $e) {
DB::rollBack();
return response()->json([
'rc' => 99,
'data' => $e->getMessage()
]);
} catch (QueryException $e) {
DB::rollBack();
return response()->json([
'rc' => 500,
'data' => $e->getMessage()
]);
}
}
public function user_change_pp(Request $request) {
DB::beginTransaction();
try {

839
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -48,4 +48,11 @@ html {
td.disabled.day {
background: #ffeeee !important;
color: #ec3333 !important;
}
.warningText {
font-size: 12px;
font-weight: 400;
color: #fb5b5b;
margin-top: 1rem;
}

View File

@ -8,16 +8,16 @@
<!--begin::Copyright-->
<div class="text-dark order-2 order-md-1">
<span class="text-muted font-weight-bold mr-2">2021©</span>
<a href="http://keenthemes.com/metronic" target="_blank" class="text-dark-75 text-hover-primary">Keenthemes</a>
<a href="#" class="text-dark-75 text-hover-primary">BASYS</a>
</div>
<!--end::Copyright-->
<!--begin::Nav-->
<div class="nav nav-dark order-1 order-md-2">
<a href="http://keenthemes.com/metronic" target="_blank" class="nav-link pr-3 pl-0">About</a>
<a href="http://keenthemes.com/metronic" target="_blank" class="nav-link px-3">Team</a>
<a href="http://keenthemes.com/metronic" target="_blank" class="nav-link pl-3 pr-0">Contact</a>
<a href="#" class="nav-link pr-3 pl-0">About</a>
<a href="#" class="nav-link px-3">Team</a>
<a href="#" class="nav-link pl-3 pr-0">Contact</a>
</div>
<!--end::Nav-->

View File

@ -51,6 +51,9 @@
<form action="{{ route('logout') }}" method="POST" id="kt_form_logout">{{ csrf_field() }}</form>
Sign Out
</a>
<button type="button" class="btn btn-sm btn-light-success font-weight-bolder py-2 px-5 mt-3" onclick="changePasswordShow()">
Change Password
</button>
</div>
</div>
</div>

View File

@ -88,6 +88,7 @@
var base_url = "{{ url('/') }}"+"/";
var btnLoader = KTUtil.getById("znBtnLoader");
var validator_change_pass;
var validatorChangePass;
/* var KTSessionTimeoutDemo = function() {
var initDemo = function() {
$.sessionTimeout({
@ -187,6 +188,47 @@
}
}
);
validatorChangePass = FormValidation.formValidation(
KTUtil.getById('mChangePasswordForm'),
{
fields: {
oldPassword: {
validators: {
notEmpty: {
message: 'Wajib diisi!'
}
}
},
newPassword: {
validators: {
notEmpty: {
message: 'Wajib diisi!'
},
stringLength: {
min: 8,
message: 'Minimal 8 karakter'
}
}
},
confirmPassword: {
validators: {
notEmpty: {
message: 'Wajib diisi!'
},
stringLength: {
min: 8,
message: 'Minimal 8 karakter'
}
}
},
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
bootstrap: new FormValidation.plugins.Bootstrap()
}
}
);
});
function reInitForm() {
@ -781,6 +823,56 @@
})
}
function znShowPassword() {
if($('.zn_sh_password input').attr("type") == "text"){
$('.zn_sh_password input').attr('type', 'password');
$('.zn-icon-eye i').addClass( "la-eye-slash" );
$('.zn-icon-eye i').removeClass( "la-eye" );
}
else if($('.zn_sh_password input').attr("type") == "password"){
$('.zn_sh_password input').attr('type', 'text');
$('.zn-icon-eye i').removeClass( "la-eye-slash" );
$('.zn-icon-eye i').addClass( "la-eye" );
}
}
// CHANGE PASSWORD
function changePasswordShow() {
znNotifConfirmClose()
$('#mChangePassword').modal('show');
}
function storeChangePassword() {
validatorChangePass.validate().then(function(status) {
if(status == 'Valid') {
popConfirm("Konfirmasi Proses",
`<div class="mt-2">Yakin Akan Mengubah Password ?</div>`, function () {
let myForm = document.getElementById('mChangePasswordForm');
let formData = new FormData(myForm);
znLoadingModal('mChangePassword')
doPost(base_url+'user/change-password', formData, function (msg, data) {
znLoadingModalEnd('mChangePassword')
if (data == null){
znNotif("danger", msg);
}else {
console.log(data)
if(data.rc == 0){
znNotif('success','Berhasil Mengubah Password');
$('#mChangePassword').modal('hide')
znLoadingPage()
$('#kt_form_logout').submit()
}else{
znNotif("danger", data.data);
}
}
})
});
}
})
}
function modalChangePp() {
var changePp = new KTImageInput('kt_image_2_change_pp');
znModal('mChangePp')

View File

@ -10,14 +10,14 @@
</button>
<a href="#" id="{{$id}}_title" class="card-title font-weight-bold text-dark-75 text-hover-primary font-size-h5">{{$title}}</a>
<div id="{{$id}}_subTitle" class="font-weight-bold text-dark-75 mt-1 mb-8">{{$subTitle}}</div>
<div class="d-flex flex-row align-items-center justify-content-between">
{{--<div class="d-flex flex-row align-items-center justify-content-between">
<p id="{{$id}}_info" class="text-dark-75 font-weight-bolder font-size-h5 m-0">{{$info}}</p>
@if ($action != '')
<div id="{{$id}}_action_head" class="text-right py-3 zn-bg-klt">
{{$action}}
</div>
@endif
</div>
</div>--}}
@if ($separator == 'true')
<div class="separator separator-dashed separator-border-2 mb-5"></div>
@endif

View File

@ -19,4 +19,55 @@
</div>
</form>
</x-slot>
</x-other.modal>
<x-other.modal id="mChangePassword" title="Change Password" subTitle="Change Password {{ Auth::user()->full_name }}" info="" separator="false" size="md">
<x-slot name="action">
<button onclick="storeChangePassword()" type="button" class="btn btn-success font-weight-bold mr-2" id="znBtnLoader">Simpan</button>
</x-slot>
<x-slot name="content">
<form id="mChangePasswordForm">
<div class="separator separator-dashed separator-border-1 mt-5 mb-5"></div>
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Password Lama</label>
<div class="input-group input-group-solid input-group-md mb-2 zn_sh_password">
<input autocomplete="off" type="password" value="" name="oldPassword" id="oldPassword" class="form-control form-control-solid" placeholder="Password Lama..."/>
<div style="cursor: pointer;" onclick="znShowPassword()">
<span class="input-group-text zn-icon-eye"><i class="la la-eye-slash"></i></span>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label>Password Baru</label>
<div class="input-group input-group-solid input-group-md mb-2 zn_sh_password">
<input autocomplete="off" type="password" value="" name="newPassword" id="newPassword" class="form-control form-control-solid" placeholder="Password Baru..."/>
<div style="cursor: pointer;" onclick="znShowPassword()">
<span class="input-group-text zn-icon-eye"><i class="la la-eye-slash"></i></span>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label>Konfirmasi Password Baru</label>
<div class="input-group input-group-solid input-group-md mb-2 zn_sh_password">
<input autocomplete="off" type="password" value="" name="confirmPassword" id="confirmPassword" class="form-control form-control-solid" placeholder="Konfirmasi Password Baru..."/>
<div style="cursor: pointer;" onclick="znShowPassword()">
<span class="input-group-text zn-icon-eye"><i class="la la-eye-slash"></i></span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="warningText">Password Baru Minimal 8 karakter, Mengandung Huruf Besar, Huruf Kecil, Angka, dan Simbol</div>
</form>
</x-slot>
</x-other.modal>

View File

@ -218,6 +218,7 @@ Route::middleware(['auth','revalidate'])->group(function () {
Route::post('/user/delete', 'OthersController@user_delete')->name('user_delete');
Route::post('/user/reset', 'OthersController@user_reset')->name('user_reset');
Route::post('/user/change', 'OthersController@user_change')->name('user_change');
Route::post('/user/change-password', 'OthersController@user_change_password')->name('user_change_password');
Route::post('/user/change_pp', 'OthersController@user_change_pp')->name('user_change_pp');
Route::get('/company', 'OthersController@company')->name('company');