This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
log_in.php
73 lines (68 loc) · 2.7 KB
/
log_in.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<head>
<!-- <link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine-ie11.min.js" defer></script> -->
<script src="global.js"></script>
</head>
<div class="w-full max-w-sm mx-auto rounded overflow-hidden shadow-lg p-5" x-data="datanya()">
<div class="text-center font-bold mt-3 text-xl text-teal-500" style=""> Login </div>
<div class="md:flex md:items-center mb-6 mt-6" >
<div class="md:w-1/3">
<label class="block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4" for="inline-full-name">
Username
</label>
</div>
<div class="md:w-2/3">
<input x-model="username" x-on:keyup.enter="submitLogin" class="bg-gray-200 appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500" id="inline-full-name" type="text" placeholder="Jane Doe">
</div>
</div>
<div class="md:flex md:items-center mb-6">
<div class="md:w-1/3">
<label class="block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4" for="inline-username">
Password
</label>
</div>
<div class="md:w-2/3">
<input x-model="password" x-on:keyup.enter="submitLogin" class="bg-gray-200 appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500" type="password" placeholder="******************">
</div>
</div>
<div class="md:flex md:items-center">
<div class="md:w-1/3"></div>
<div class="md:w-2/3">
<button x-on:click="submitLogin" class="shadow bg-green-500 hover:bg-purple-400 focus:shadow-outline focus:outline-none text-white font-bold py-2 px-4 rounded" type="button">
Login
</button>
</div>
</div>
</div>
<script>
function datanya () {
return {
username: '',
password: '',
submitLogin () {
const formData = new FormData();
// const baseUrl = window.location.origin + '/smallBlog';
formData.append('username', this.username);
formData.append('password', this.password);
fetch(baseUrl + '/proses_login.php', {
method: 'POST',
body: formData
})
.then((response) => response.json())
.then((result) => {
console.log('Success:', result);
console.log(result.success);
if(result.success){
localStorage.setItem("token", result.token);
window.location.href = baseUrl + '/admin?pages=';
}else {
alert("Email dan Password salah")
}
})
.catch((error) => {
console.error('Error:', error);
});
}
}
}
</script>