115 lines
4.8 KiB
PHP
115 lines
4.8 KiB
PHP
<script>
|
|
var validation;
|
|
validation = FormValidation.formValidation(
|
|
KTUtil.getById('kt_login_signin_form'),
|
|
{
|
|
fields: {
|
|
username: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Username wajib diisi'
|
|
}
|
|
}
|
|
},
|
|
password: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Password wajib diisi'
|
|
}
|
|
}
|
|
}
|
|
},
|
|
plugins: {
|
|
trigger: new FormValidation.plugins.Trigger(),
|
|
submitButton: new FormValidation.plugins.SubmitButton(),
|
|
//defaultSubmit: new FormValidation.plugins.DefaultSubmit(), // Uncomment this line to enable normal button submit after form validation
|
|
bootstrap: new FormValidation.plugins.Bootstrap()
|
|
}
|
|
}
|
|
);
|
|
|
|
$('#password, #username').on('keypress', function(e) {
|
|
var key = e.which;
|
|
if(key == 13) // the enter key code
|
|
{
|
|
$('#kt_login_signin_submit').trigger('click')
|
|
}
|
|
});
|
|
|
|
$('#kt_login_signin_submit').on('click', function (e) {
|
|
// e.preventDefault();
|
|
validation.validate().then(function(status) {
|
|
if (status == 'Valid') {
|
|
var myForm = document.getElementById('kt_login_signin_form')
|
|
var formData = new FormData(myForm)
|
|
formData.set('password',encrypt($('#password').val()))
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: base_url + 'act_login',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
beforeSend: function() {
|
|
$('#'+e.target.id).addClass('spinner spinner-darker-success spinner-right')
|
|
$('#'+e.target.id).attr('disabled', true)
|
|
},
|
|
success: function(res) {
|
|
$('#'+e.target.id).removeClass('spinner spinner-darker-success spinner-right')
|
|
$('#'+e.target.id).prop('disabled', false)
|
|
if(res.rc==0) {
|
|
KTApp.blockPage({
|
|
overlayColor: '#000000',
|
|
state: 'primary',
|
|
});
|
|
if(res.role==7) {
|
|
window.location.href = base_url + 'company';
|
|
} else {
|
|
window.location.href = base_url + 'home';
|
|
}
|
|
} else {
|
|
swal.fire({
|
|
text: res.rm,
|
|
icon: "error",
|
|
buttonsStyling: false,
|
|
confirmButtonText: "Close",
|
|
customClass: {
|
|
confirmButton: "btn font-weight-bold btn-light-danger"
|
|
}
|
|
}).then(function() {
|
|
KTUtil.scrollTop();
|
|
});
|
|
}
|
|
}
|
|
}).fail(function(xhr, ajaxOptions, thrownErrors) {
|
|
$('#'+e.target.id).removeClass('spinner spinner-darker-success spinner-right')
|
|
$('#'+e.target.id).prop('disabled', false)
|
|
swal.fire({
|
|
text: "Failed " + thrownErrors + " Tell the developer for this issue",
|
|
icon: "error",
|
|
buttonsStyling: false,
|
|
confirmButtonText: "Close",
|
|
customClass: {
|
|
confirmButton: "btn font-weight-bold btn-light-danger"
|
|
}
|
|
}).then(function() {
|
|
KTUtil.scrollTop();
|
|
});
|
|
})
|
|
}
|
|
});
|
|
});
|
|
|
|
function encrypt(text) {
|
|
var valueToEncrypt = text // this could also be object/array/whatever
|
|
var password = 'pmo123456'
|
|
var encrypted = CryptoJSAesJson.encrypt(valueToEncrypt, password)
|
|
return encrypted;
|
|
}
|
|
|
|
function decrypt(text) {
|
|
var encrypted = text
|
|
var password = 'pmo123456'
|
|
var decrypted = CryptoJSAesJson.decrypt(encrypted, password)
|
|
return decrypted;
|
|
}
|
|
</script> |