-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.html
102 lines (90 loc) · 4.44 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Register</title>
</head>
<body>
<form id="mainform" class="w-25 m-4 position-absolute top-50 start-50 translate-middle">
<h2>Register</h2>
<div class="form-floating ">
<input type="email" class="form-control mb-3" id="emailInp" placeholder="[email protected]">
<label for="emailInp">Email address</label>
</div>
<div class="form-floating ">
<input type="password" class="form-control mb-3" id="passInp" placeholder="Password">
<label for="passInp">Password</label>
</div>
<div class="form-floating ">
<input type="text" class="form-control mb-3" id="fname" placeholder="First Name">
<label for="fname">First Name</label>
</div>
<div class="form-floating">
<input type="text" class="form-control mb-3" id="lname" placeholder="Last Name">
<label for="lname">Last Name</label>
</div>
<div class="mx-auto" style="width: fit-content;">
<button type="submit" class="btn btn-primary ">Register</button>
<a href="./login.html"><button type="button" class="btn btn-primary">Login</button></a>
</div>
</form>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.7.2/firebase-app.js";
import { getDatabase, set, ref } from "https://www.gstatic.com/firebasejs/10.7.2/firebase-database.js";
import { getAuth, createUserWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/10.7.2/firebase-auth.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/10.7.2/firebase-analytics.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyAVNio0Mf21sxjq5zjR3Cou1F0-fy_fGao",
authDomain: "digi-stick.firebaseapp.com",
projectId: "digi-stick",
storageBucket: "digi-stick.appspot.com",
messagingSenderId: "451586743771",
appId: "1:451586743771:web:acf64e6759f9098b969bfe",
measurementId: "G-WQHZ9018ZE"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const db = getDatabase();
const auth = getAuth(app);
let EmailInp = document.getElementById('emailInp')
let PassInp = document.getElementById('passInp')
let FirstNInp = document.getElementById('fname')
let LastNInp = document.getElementById('lname')
let MainForm = document.getElementById('mainform')
let RegUser = evt => {
evt.preventDefault();
createUserWithEmailAndPassword(auth, EmailInp.value, PassInp.value)
.then((credentials) => {
// console.log(credentials);
set(ref(db, 'UserAuthList/' + credentials.user.uid), {
firstname: FirstNInp.value,
lastname: LastNInp.value
})
const items = ['earlybird', 'nightowl', 'engineer'];
const currentUserUid = credentials.user.uid;
items.forEach((item) => {
set(ref(db, `items/${item}/owners/${currentUserUid}`), false);
});
})
.catch((error) => {
alert(error.message);
console.log(error.message);
console.log(error.code);
})
}
MainForm.addEventListener('submit', RegUser);
</script>
</body>
</html>