first commit
This commit is contained in:
1
js/data.js
Normal file
1
js/data.js
Normal file
@ -0,0 +1 @@
|
||||
data
|
||||
138
js/login.js
Normal file
138
js/login.js
Normal file
@ -0,0 +1,138 @@
|
||||
let level = localStorage.getItem("level");
|
||||
let nik = localStorage.getItem("nik");
|
||||
|
||||
if (level != '' && level != null) {
|
||||
let res = JSON.parse($.ajax({
|
||||
url: url,
|
||||
type: 'post',
|
||||
data: {nik : nik,level : level,proses : 'cek_data'},
|
||||
async : false,
|
||||
}).responseText);
|
||||
|
||||
// console.log(res)
|
||||
switch (res.res) {
|
||||
case 'ok':
|
||||
window.location.href = res.url
|
||||
break;
|
||||
case 'ko':
|
||||
localStorage.removeItem("level");
|
||||
localStorage.removeItem("nik");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function login () {
|
||||
// console.log(url)
|
||||
const username = $("#username").val()
|
||||
const password = $("#password").val()
|
||||
|
||||
// console.log(username)
|
||||
// console.log(password)
|
||||
|
||||
if (username == '') {
|
||||
toastnya('username', 'Username Harus Terisi')
|
||||
}else if (password == '') {
|
||||
toastnya('password', 'Password Harus Terisi')
|
||||
}else{
|
||||
// console.log('jalankan')
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'post',
|
||||
data: {username : username, password : password, proses : 'login'},
|
||||
|
||||
beforeSend: function(res) {
|
||||
|
||||
$.blockUI({
|
||||
message: "Sedang Diproses",
|
||||
css: {
|
||||
border: 'none',
|
||||
padding: '15px',
|
||||
backgroundColor: '#000',
|
||||
'-webkit-border-radius': '10px',
|
||||
'-moz-border-radius': '10px',
|
||||
opacity: .5,
|
||||
color: '#fff'
|
||||
} });
|
||||
},
|
||||
success: function (response) {
|
||||
$.unblockUI();
|
||||
console.log(response)
|
||||
localStorage.setItem("level", response.level);
|
||||
localStorage.setItem('nik', response.nik)
|
||||
swal({
|
||||
title : "Success",
|
||||
text: "Selamat Datang",
|
||||
icon: "success",
|
||||
buttons: {
|
||||
cancel: false,
|
||||
confirm: false,
|
||||
},
|
||||
timer : 1500
|
||||
// dangerMode: true,
|
||||
})
|
||||
.then((hehe) =>{
|
||||
location.reload();
|
||||
});
|
||||
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
console.log(errorThrown)
|
||||
$.unblockUI();
|
||||
switch (errorThrown) {
|
||||
case "Bad Request":
|
||||
toastnya('username',"Username dan Password Salah",)
|
||||
break;
|
||||
case "Internal Server Error":
|
||||
toastnya(null,errorThrown)
|
||||
break;
|
||||
default:
|
||||
swal({
|
||||
text: "Koneksi Gagal, Sila Pastikan Perangkat Terhubung Jaringan Internet",
|
||||
icon: "warning",
|
||||
buttons: {
|
||||
cancel: false,
|
||||
confirm: true,
|
||||
},
|
||||
// dangerMode: true,
|
||||
})
|
||||
.then((hehe) =>{
|
||||
location.reload();
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function toastnya(id,mesej){
|
||||
|
||||
toastr.options = {
|
||||
"closeButton": true,
|
||||
"debug": false,
|
||||
"progressBar": true,
|
||||
"positionClass": "toast-top-right",
|
||||
"showDuration": "300",
|
||||
"hideDuration": "1000",
|
||||
"timeOut": "5000",
|
||||
"extendedTimeOut": "1000",
|
||||
"showEasing": "swing",
|
||||
"hideEasing": "linear",
|
||||
"showMethod": "fadeIn",
|
||||
"hideMethod": "fadeOut"
|
||||
};
|
||||
|
||||
toastr.error("<center>"+mesej+"</center>");
|
||||
|
||||
if (id != null) {
|
||||
$("#"+id).focus();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// localStorage.removeItem('level')
|
||||
// localStorage.removeItem('nik')
|
||||
48
js/main.js
Normal file
48
js/main.js
Normal file
@ -0,0 +1,48 @@
|
||||
let level = localStorage.getItem("level");
|
||||
let nik = localStorage.getItem("nik");
|
||||
let nama;
|
||||
|
||||
if (level != '' || level != null) {
|
||||
let res = JSON.parse($.ajax({
|
||||
url: url,
|
||||
type: 'post',
|
||||
data: {nik : nik,level : level,proses : 'cek_data_detail'},
|
||||
async : false,
|
||||
}).responseText);
|
||||
|
||||
console.log(res)
|
||||
switch (res.res) {
|
||||
case 'ok':
|
||||
// window.location.href = res.url
|
||||
nama = res.nama
|
||||
break;
|
||||
case 'ko':
|
||||
localStorage.removeItem("level");
|
||||
localStorage.removeItem("nik");
|
||||
window.location.href = '../'
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$(".name").html('<a href="#">'+nama+'</a>')
|
||||
$(".position").html(level)
|
||||
|
||||
function logout(){
|
||||
swal({
|
||||
title: "Yakin ingin Logout?",
|
||||
text: "Anda akan keluar dari sistem",
|
||||
icon: "warning",
|
||||
buttons: true,
|
||||
dangerMode: true,
|
||||
})
|
||||
.then((logout) => {
|
||||
if (logout) {
|
||||
localStorage.removeItem("nik");
|
||||
localStorage.removeItem("level");
|
||||
window.location.href ='../index.html';
|
||||
} else {
|
||||
swal("Terima kasih kerana masih di sistem");
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user