-
Notifications
You must be signed in to change notification settings - Fork 4
/
login.html
180 lines (132 loc) · 6.23 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Coursera | Log In Page</title>
<link rel="icon" href="./components/icons/image.png">
<link rel="stylesheet" href="./style/log_in.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
</head>
<body>
<div id="main_div">
<div id="block">
<div id="flex">
<div id="text">
<h1>Welcome Back</h1>
</div>
<div>
<a href="signUp.html"><svg class="cross" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M310.6 361.4c12.5 12.5 12.5 32.75 0 45.25C304.4 412.9 296.2 416 288 416s-16.38-3.125-22.62-9.375L160 301.3L54.63 406.6C48.38 412.9 40.19 416 32 416S15.63 412.9 9.375 406.6c-12.5-12.5-12.5-32.75 0-45.25l105.4-105.4L9.375 150.6c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0L160 210.8l105.4-105.4c12.5-12.5 32.75-12.5 45.25 0s12.5 32.75 0 45.25l-105.4 105.4L310.6 361.4z"/></svg></a>
</div>
</div>
<div class="form_div">
<form>
<div class="broder">
<h4> <strong>EMAIL</strong> </h4>
<input type="email" id="email" class="control" placeholder="[email protected]">
</div>
<div class="broder">
<h5> <strong>PASSWORD</strong> </h5>
<input type="password" id="password" class="control" placeholder="Create Password">
<a href="./forget pasword/forget_pass.html" class="forget_pass" >Forget Password?</a>
<br>
<button class="btn">Login</button>
</div>
</form>
<div class="img">
<img class="google_img" src="./components/icons/download.jfif" alt="">
<p class="google_text"><strong>Continue with Google</strong></p>
</div>
<div class="img">
<img class="google_img" src="./components/icons/facebook.jpg" alt="">
<p class="google_text"><strong>Continue with Facebook</strong></p>
</div>
<div class="img">
<img class="google_img" src="./components/icons/apple.jpg" alt="">
<p class="google_text"><strong>Continue with Apple</strong></p>
</div>
<div id="newSignup">
<p>New to Coursera? <a href="signup.html">Sign up</a> </p>
</div>
<hr class="line">
<div id="link_div">
<a class="link" href="signup.html">Log in with your organization</a>
<p class="para">Having trouble logging in? <a href="">Learner help center</a> </p>
<p class="para">This site is protected by reCAPTCHA Enterprise and the Google <a href="">Privacy Policy</a> and <a href="">Terms of Service</a> apply.</p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<script>
// -------------------------------login code goes here---------------------------------
document.querySelector(".btn").addEventListener("click", signIn);
let url=`https://coursera-backend-nodejs.herokuapp.com/login`
async function signIn(event){
event.preventDefault();
let diverror= document.getElementById("error")
if(diverror){
diverror= document.getElementById("error").remove()
document.getElementById("block").style.height= "800px"
}
try {
const email=document.getElementById("email").value
const password= document.getElementById("password").value
const result= await fetch(url,{
method:"POST",
headers:{
'Content-Type':'application/json'
},
body:
JSON.stringify({
email,
password
})
}).then((res)=>{
return res.json()
});
if(result.error){
console.log({res:result.error})
var error= document.createElement("div")
error.setAttribute("id","error")
document.getElementById("block").style.height= "900px"
var p=document.createElement("p")
console.log(result.error[0].param)
for(let i=0;i<result.error.length;i++){
if(result.error[i].param=="email"){
p.textContent=("Invalid email. Please enter email as [email protected]")
}
if(result.error[i].param=="password"){
p.textContent=("Password must contain between 8 and 72 characters.")
break;
}
}
if(result.error.length>1){
p.textContent=("Full name is required.Invalid email. Please enter email as [email protected]. Password must contain between 8 and 72 characters.")
}
error.append(p)
document.getElementById("text").append(error)
}
// else{
// window.location.href="login.html"
// }
else{
localStorage.setItem("userID",JSON.stringify(result.user._id))
localStorage.setItem("Course-eraToken",JSON.stringify(`Bearer ${result.token}`))
localStorage.setItem("CurrentUser",JSON.stringify(result.user))
window.location.href="index.html"
}
} catch (error) {
console.log(error)
}
}
// -------------------------------login code goes here---------------------------------
function deletToken() {
localStorage.setItem("Course-eraToken",null);
}
deletToken();
</script>