-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.html
233 lines (229 loc) · 8.94 KB
/
register.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!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" />
<!-- Encryption -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
<title>Document</title>
<!-- Font Awesome -->
<link
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
rel="stylesheet"
/>
<!-- Google Fonts -->
<link
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
rel="stylesheet"
/>
<!-- MDB -->
<link
href="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/6.1.0/mdb.min.css"
rel="stylesheet"
/>
</head>
<body>
<section class="vh-100" style="background-color: #eee">
<div class="container h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col-lg-12 col-xl-11">
<div class="card text-black" style="border-radius: 25px">
<div class="card-body p-md-5">
<div class="row justify-content-center">
<div class="col-md-10 col-lg-6 col-xl-5 order-2 order-lg-1">
<p class="text-center h1 fw-bold mb-5 mx-1 mx-md-4 mt-4">
Sign up
</p>
<form class="mx-1 mx-md-4">
<div class="d-flex flex-row align-items-center mb-4">
<i class="fas fa-user fa-lg me-3 fa-fw"></i>
<div class="form-outline flex-fill mb-0">
<input
type="text"
id="nameInp"
class="form-control"
/>
<label class="form-label" for="form3Example1c"
>Your Name</label
>
</div>
</div>
<div class="d-flex flex-row align-items-center mb-4">
<i class="fas fa-envelope fa-lg me-3 fa-fw"></i>
<div class="form-outline flex-fill mb-0">
<input
type="email"
id="emailInp"
class="form-control"
/>
<label class="form-label" for="form3Example3c"
>Your Email</label
>
</div>
</div>
<div class="d-flex flex-row align-items-center mb-4">
<i class="fas fa-lock fa-lg me-3 fa-fw"></i>
<div class="form-outline flex-fill mb-0">
<input
type="text"
id="userInp"
class="form-control"
/>
<label class="form-label" for="form3Example4c"
>Usename</label
>
</div>
</div>
<div class="d-flex flex-row align-items-center mb-4">
<i class="fas fa-key fa-lg me-3 fa-fw"></i>
<div class="form-outline flex-fill mb-0">
<input
type="password"
id="passInp"
class="form-control"
/>
<label class="form-label" for="form3Example4cd"
>Password</label
>
</div>
</div>
<a href="/login.html">Already have an account?</a>
<div
class="d-flex justify-content-center mx-4 mt-2 mb-3 mb-lg-4"
>
<button type="button" class="btn btn-primary btn-lg" id="sub_btn">
Register
</button>
</div>
</form>
</div>
<div
class="col-md-10 col-lg-6 col-xl-7 d-flex align-items-center order-1 order-lg-2"
>
<img
src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-registration/draw1.webp"
class="img-fluid"
alt="Sample image"
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- ----------------FIREBASE------------------->
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.16.0/firebase-app.js";
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyBXtCjMez8dw82Oqux39X2AFSeba6p-w60",
authDomain: "kshitijtask.firebaseapp.com",
databaseURL: "https://kshitijtask-default-rtdb.firebaseio.com",
projectId: "kshitijtask",
storageBucket: "kshitijtask.appspot.com",
messagingSenderId: "941950928310",
appId: "1:941950928310:web:4265c56ad67e5c78552d17",
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
import {
getStorage,
ref as sRef,
uploadBytesResumable,
getDownloadURL,
} from "https://www.gstatic.com/firebasejs/9.16.0/firebase-storage.js";
import {
getDatabase,
ref,
set,
child,
get,
update,
remove,
} from "https://www.gstatic.com/firebasejs/9.16.0/firebase-database.js";
const db = getDatabase();
// -------------REFERENCES----------------
const name = document.getElementById("nameInp");
const email = document.getElementById("emailInp");
const username = document.getElementById("userInp");
const pass = document.getElementById("passInp");
const submit = document.getElementById("sub_btn");
// ---------------VALIDATION---------------
function isEmptyOrSpaces(str) {
return str === null || str.match(/^ *$/) !== null;
}
function Validation() {
let nameregex = /^[a-zA-Z\s]+$/;
let emailregex = /^[a-zA-Z0-9]+@(gmail|yahoo|outlook)\.com$/;
let userregex = /^[a-zA-Z0-9]{5,}$/;
if (
isEmptyOrSpaces(name.value) ||
isEmptyOrSpaces(email.value) ||
isEmptyOrSpaces(username.value) ||
isEmptyOrSpaces(pass.value)
) {
alert("You cannot leave any field empty!");
return false;
}
if (!nameregex.test(name.value)) {
alert("The name should only contain alphabets!");
return false;
}
if (!emailregex.test(email.value)) {
alert("Enter a valid email!");
return false;
}
if (!userregex.test(username.value)) {
alert(
"Username can only be alphanumeric\nUsername must be at least 5 characters"
);
return false;
}
return true;
}
// ----------------REGISTER USER TO FIREBASE----------------
function RegisterUser() {
if (!Validation()) {
return;
}
const dbRef = ref(db);
get(child(dbRef, "UsersList/" + username.value)).then((snapshot) => {
if (snapshot.exists()) {
alert("Account Already Exist!");
window.location="register.html";
} else {
set(ref(db, "UsersList/" + username.value), {
fullname: name.value,
email: email.value,
username: username.value,
password: encPass(),
})
.then(() => {
alert("user added successfully");
window.location = "login.html";
})
.catch((error) => {
alert("error" + error);
});
}
});
}
// -----------------ENCRYPTION-----------------
function encPass() {
var pass12 = CryptoJS.AES.encrypt(pass.value, pass.value);
return pass12.toString();
}
// ---------------ASSIGN THE EVENT-----------------
submit.addEventListener("click", RegisterUser);
</script>
<!-- MDB -->
<script
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/6.1.0/mdb.min.js"
></script>
</body>
</html>