-
Notifications
You must be signed in to change notification settings - Fork 3
/
login.html
95 lines (62 loc) · 2.37 KB
/
login.html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login Page</title>
<script src="https://kit.fontawesome.com/8f856e9bb7.js" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css2?family=Lato:wght@100;300&family=Oswald:wght@300&display=swap" rel="stylesheet">
<link rel="stylesheet" href="./styles/login.css">
<link rel="stylesheet" href="./styles/common.css">
<link rel="stylesheet" href="./styles/navbar.css">
<!-- icon -->
<link rel="icon" href="https://assets.lybrate.com/q_auto,f_auto,h_20,w_20/imgs/product/d2d/PatientGoldMembership/lybrate_icon_red_large.png">
<!-- -->
</head>
<body>
<!----------------------------------- navbar starting --------------------------- -->
<div id="snav"></div>
<!---------------------------------------------- navbar ending----------------------- -------------------- -->
<div id="login">
</div>
</body>
</html>
<script type="module">
import navbar from "./componants/navbar.js"
document.querySelector("#snav").innerHTML=navbar()
import Login from "./componants/login.js";
document.getElementById("login").innerHTML = Login();
document.getElementById("login_btn").addEventListener("click",LoginFunction);
async function LoginFunction(e){
e.preventDefault();
let login_data = {
username: document.getElementById("name1").value,
password: document.getElementById("password1").value,
};
login_data = JSON.stringify(login_data);
console.log(login_data);
let login_api = "https://masai-api-mocker.herokuapp.com/auth/login";
let res = await fetch(login_api,{
method: "POST",
body: login_data,
headers: {
"Content-Type": "application/json"
},
});
let data = await res.json();
console.log(data);
let mobile = document.getElementById("name1").value;
getProfile(mobile,data.token);
localStorage.setItem("username",JSON.stringify(mobile))
}
async function getProfile(mobile,token){
let user_api = `https://masai-api-mocker.herokuapp.com/user/${mobile}`;
let resp = await fetch(user_api,{
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
},
});
let dataLogin = await resp.json();
console.log(dataLogin);
window.location.href = "./Project/Home.html";
}
</script>