mutu-rsab/resources/views/auth/login.blade.php
2025-11-28 15:44:00 +07:00

147 lines
5.5 KiB
PHP

@extends('layouts.template_auth')
@section('title', 'Login | SIMPATIK RSAB Harapan Kita')
@section('custom_css')
<style>
@media (min-width: 768px) {
.w-md-40 {
width: 40% !important;
}
}
</style>
@endsection
@section('content')
<div class="container-fluid bg-primary vh-100 vw-100 d-flex align-items-center justify-content-center">
<div class="card w-100 w-md-40">
<div class="card-body">
<div class="text-center">
<img src="{{ asset('assets/img/logo-fullname.png') }}" class="card-img-top w-100 w-md-40" alt="...">
</div>
</div>
<div class="card-body">
<h5 class="card-title text-center fw-bold">Login Survey Mutu</h5>
<form id="form">
<div class="mb-3">
<label for="username">Username</label>
<input type="text" class="form-control" id="user_name" name="user_name" aria-describedby="user_name" />
<span id="user_name_error" class="form-label text-danger"></span>
</div>
<div class="form-password-toggle">
<label class="" for="password">Password</label>
<div class="input-group">
<input type="password" class="form-control" id="password" name="password" aria-describedby="password2" />
<span id="password2" class="input-group-text cursor-pointer"><i
class="icon-base ti tabler-eye-off"></i></span>
</div>
<span id="password_error" class="form-label text-danger"></span>
</div>
</form>
</div>
<div class="card-body">
<button class="btn btn-primary" id="button_login">Login</button>
</div>
</div>
@endsection
@section('custom_js')
<script>
$(document).ready(function(){
$('#button_login').on('click', function(){
login();
})
})
function login() {
const formData = new FormData($('#form')[0]);
$('#button_login').attr('disabled', 'true');
const username = $('#user_name').val();
if(username == 'admin_pembelajaran'){
$.ajax({
url: "{{ url('admin/login/action') }}",
type: "GET",
success: function(res) {
$.cookie("token", res.data, { expires: 7, path: "/" });
Swal.fire({
position: "top-end",
icon: "success",
text: "Berhasil Login",
showConfirmButton: false,
timer: 1500
}).then((result) => {
window.location.href = '{{ url("/admin") }}';
}).catch((err) => {
});
},
error: function(err) {
console.log(err.responseJSON);
$('#button_login').removeAttr('disabled');
Swal.fire({
position: "top-end",
icon: "error",
text: err?.responseJSON?.message ?? 'oops something wrong!',
showConfirmButton: false,
timer: 1500
});
if(err.status == 422){
const dataErrors = err.responseJSON.errors;
for (let field in dataErrors) {
$(`#${field}_error`).html(dataErrors[field].join(", "));
}
}
}
});
} else {
$.ajax({
url: "{{ getenv('URL_BE') }}publik/login/pegawai",
type: "POST",
data: formData,
processData: false,
contentType: false,
headers: {
"x-klien": 1
},
success: function(res) {
$.cookie("token", res.response.access_token, { expires: 7, path: "/" });
Swal.fire({
position: "top-end",
icon: "success",
text: "Berhasil Login",
showConfirmButton: false,
timer: 1500
}).then((result) => {
window.location.href = '{{ url("/") }}';
// window.location.href = '{{ url("/admin") }}';
}).catch((err) => {
});
},
error: function(err) {
console.log(err.responseJSON);
$('#button_login').removeAttr('disabled');
Swal.fire({
position: "top-end",
icon: "error",
text: err?.responseJSON?.message ?? 'oops something wrong!',
showConfirmButton: false,
timer: 1500
});
if(err.status == 422){
const dataErrors = err.responseJSON.errors;
for (let field in dataErrors) {
$(`#${field}_error`).html(dataErrors[field].join(", "));
}
}
}
});
}
}
</script>
@endsection