-
Notifications
You must be signed in to change notification settings - Fork 4
/
signup.html
221 lines (166 loc) · 7.61 KB
/
signup.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<!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 | Sign Up Page</title>
<link rel="icon" href="./components/icons/image.png">
<link rel="stylesheet" href="./style/signUp.css">
</head>
<body >
<div id="main_div" >
<div id="block" >
<div id="flex">
<div id="text">
<h1>Sign Up</h1>
<div id="p_tag">
<p>Learn on your own time from top</p>
<p>universities and businesses.</p>
</div>
</div>
<div>
<a href="./index.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>FULL NAME</strong></h4>
<input type="text" id="name" class="control" placeholder="Enter your full name" onclick="setbordercolor()">
</div>
<div class="broder">
<h4> <strong>EMAIL</strong> </h4>
<input type="email" id="email" class="control" placeholder="[email protected]" onclick="setbordercolor()">
</div>
<div class="broder">
<h5> <strong>PASSWORD</strong> </h5>
<input type="password" id="password" class="control" placeholder="Create Password" onclick="setbordercolor()">
<p>Between 8 and 72 characters</p>
<br>
<button class="join_btn">Join for Free</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> -->
<button id="google_ouath"> <p> <img class="google_img" src="./components/icons/download.jfif" alt="" > <span class="google_text">Continue with Google</span> </p></button>
</div>
<div class="img">
<button id="facebookoauth"> <p> <img class="google_img" src="./components/icons/facebook.jpg" alt="" > <span class="google_text">Continue with Facebook</span> </p></button>
<!-- <img class="google_img" src="./components/icons/facebook.jpg" alt="">
<p class="google_text"><strong>Continue with Facebook</strong></p> -->
</div>
<div class="flex">
<p>Already on Coursera?</p>
<a href="./login.html">Login</a>
</div>
<br>
<hr>
<div class="text_para">
<p class="para">I accept Coursera's <a href="">Terms of Use</a> and <a href="">Privacy Notice</a> . 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>
</body>
</html>
<script>
//--------------------------------google ouath code start here-------------------------------------------------
let google_ouath = document.getElementById("google_ouath").addEventListener("click" , google_auth);
let google_url = `https://coursera-backend-nodejs.herokuapp.com/auth/google/callback`;
async function google_auth(event){
event.preventDefault()
try {
let res= await fetch(google_url)
console.log(res.url)
window.location.href=res.url;
} catch (error) {
console.log(error)
}
}
//--------------------------------google ouath code ends here-------------------------------------------------
// facebook
async function facebookOauth(event){
event.preventDefault()
try {
let res= await fetch(facebookurl)
window.location.href=res.url
console.log(data)
} catch (error) {
console.log(error)
}
}
///facebook end
//---------------------------------------sign up and login code --------------------------------------
function setbordercolor(){
document.getElementById("name").style.border= "1px solid blue"
}
function removebordercolor(){
document.querySelector(":not(input)").style.border="1px solid gray"
}
document.querySelector(".join_btn").addEventListener("click",signUp);
document.querySelector("#facebookoauth").addEventListener("click",facebookOauth);
let SignUpurl=`https://coursera-backend-nodejs.herokuapp.com/register`;
let facebookurl=`https://coursera-backend-nodejs.herokuapp.com/auth/facebook/callback`;
async function signUp(event){
event.preventDefault()
// console.log("hi")
let diverror= document.getElementById("error")
if(diverror){
diverror= document.getElementById("error").remove()
}
try {
const username=document.getElementById("name").value
const email=document.getElementById("email").value
const password=document.getElementById("password").value
console.log(username,email,password)
const result= await fetch(SignUpurl,{
method:"POST",
headers:{
'Content-Type':'application/json',
},
body:
JSON.stringify({
username,
email,
password
})
}).then((res)=>{
return res.json()
})
console.log(result)
if(result.error){
console.log({res:result.error})
var error= document.createElement("div")
error.setAttribute("id","error")
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=="username"){
p.textContent=("Please enter username")
}
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>2){
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"
}
} catch (error) {
console.log({error:error})
}
}
//---------------------------------till here --------------------------------------------------------
</script>