-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.ejs
114 lines (106 loc) · 3.92 KB
/
signup.ejs
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
<!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">
<link rel="stylesheet" href="signup.css">
<title>Sign Up</title>
</head>
<body>
<section class="forms-section">
<h1 class="section-title">Join Us Today!!</h1>
<div class="forms">
<div class="form-wrapper is-active">
<button type="button" class="switcher switcher-login">
Sign Up
<span class="underline"></span>
</button>
<form class="form form-login" action="/signup" >
<legend>Please, enter your email and password for login.</legend>
<div class="input-block">
<label for="login-email">Name</label>
<input
id="signup-email"
name="name"
placeholder="Name"
type="name"
required
/>
</div>
<div class="input-block">
<label for="email">E-mail</label>
<input
id="signup-email"
name="email"
placeholder="email"
type="text"
required
/>
<div class="email error"></div>
</div>
<div class="input-block">
<label for="password">Password</label>
<input
id="signup-password"
name="password"
placeholder="password"
type="password"
required
/>
<div class="password error"></div>
</div>
<div class="input-block">
<label for="login-password">Phone No.</label>
<input
id="signup-password-confirm"
type="phno"
name="phno"
required
/>
</div>
<div class="form-control">
<label class="header">Profile Photo:</label>
<input id="image" type="file" name="profile_photo" placeholder="Photo" required="" capture>
</div>
<button type="submit" class="btn-login">
Sign Up
</button>
</form>
</div>
<div class="form-wrapper">
<script>
const form = document.querySelector('form');
const emailError = document.querySelector('.email.error');
const passwordError = document.querySelector('.password.error');
form.addEventListener('submit', async (e) => {
e.preventDefault();
// reset errors
emailError.textContent = '';
passwordError.textContent = '';
// get values
const email = form.email.value;
const password = form.password.value;
try {
const res = await fetch('/signup', {
method: 'POST',
body: JSON.stringify({ email, password }),
headers: {'Content-Type': 'application/json'}
});
const data = await res.json();
console.log(data);
if (data.errors) {
emailError.textContent = data.errors.email;
passwordError.textContent = data.errors.password;
}
if (data.user) {
location.assign('/');
}
}
catch (err) {
console.log(err);
}
});
</script>
</body>
</html>