-
Notifications
You must be signed in to change notification settings - Fork 0
/
Register.html
132 lines (113 loc) · 4.37 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>Secure Folder 📁</title>
<!-- Font Awesome -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
/>
<!-- Google Fonts Roboto -->
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700;900&display=swap"
/>
<!-- MDB -->
<link rel="stylesheet" href="mdb.min.css" />
</head>
<body>
<h1 class="text-center my-4">Welcome Back 🎉</h1>
<h3 class="text-center">Sign Up Now</h3>
<div class="container my-4">
<form id="register-form">
<div class="row mb-4">
<div class="col">
<div class="form-outline">
<input type="text" id="firstName" class="form-control" />
<label class="form-label" for="firstName">First name</label>
</div>
</div>
<div class="col">
<div class="form-outline">
<input type="text" id="lastName" class="form-control" />
<label class="form-label" for="lastName">Last name</label>
</div>
</div>
</div>
<div class="form-outline mb-4">
<input type="number" id="email" min="0" max="9999999999" class="form-control" />
<label class="form-label" for="email" >Mobile Number</label>
</div>
<div class="form-outline mb-4">
<input type="password" id="password" class="form-control" />
<label class="form-label" for="password">Password</label>
</div>
<button type="submit" class="btn btn-primary btn-block mb-4" id="submit">Sign up</button>
<div class="text-center">
<p>Already Have An Account? <a href="index.html">Login Now</a></p>
</div>
</form>
</div>
<script type="text/javascript" src="mdb.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.1.0/firebase-auth.js"></script>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.1.0/firebase-app.js";
import { getAuth, createUserWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/10.1.0/firebase-auth.js";
import { getDatabase, ref, set, push } from "https://www.gstatic.com/firebasejs/10.1.0/firebase-database.js";
const firebaseConfig = {
apiKey: "AIzaSyBhc0fk_t5q6xo4FySI9XXGHdEfLssCru8",
authDomain: "folder-24d4a.firebaseapp.com",
projectId: "folder-24d4a",
storageBucket: "folder-24d4a.appspot.com",
messagingSenderId: "256440210644",
appId: "1:256440210644:web:244b521bde9a1aa728d741",
measurementId: "G-32LGWTYVNN"
};
const firebaseApp = initializeApp(firebaseConfig);
const auth = getAuth(firebaseApp);
const database = getDatabase();
const registerForm = document.getElementById('register-form');
registerForm.addEventListener('submit', async (e) => {
e.preventDefault();
const firstName = document.getElementById('firstName');
const lastName = document.getElementById('lastName');
const email = document.getElementById('email');
const password = document.getElementById('password');
try {
const userCredential = await createUserWithEmailAndPassword(auth, email.value + "@gmail.com", password.value);
setTimeout(() => {
const FirstNameVal = firstName.value;
const LasNameVal = lastName.value;
const EmailVal = email.value;
const PasswordVal = password.value;
if (EmailVal && PasswordVal) {
const usersRef = push(ref(database, "Users/"+EmailVal));
set(usersRef, {
FirstName: FirstNameVal,
LastName: LasNameVal,
Email: EmailVal,
Password: PasswordVal
})
.then(() => {
alert("Account Created Successfully 🥰 Please Go To Login Page");
window.open("index.html")
})
.catch((error) => {
console.error("Account Not Created 😥");
});
} else {
alert("Please Enter All Details");
}
}, 500);
// You can redirect or perform other actions here after successful registration.
} catch (error) {
alert('Registration error:' + error.massage);
// Handle registration error here.
}
});
</script>
</body>
</html>