forked from ASMA-GIT/Digital-Health-Care
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logform.html
94 lines (84 loc) · 2.98 KB
/
logform.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
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>HTML5 Login Form with validation Example</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel="stylesheet" href="style2.css">
</head>
<body>
<!-- partial:index.partial.html -->
<div id="login-form-wrap">
<h2 class="text-uppercase">Login form</h2>
<div id="login-form">
<p>
<input type="text" id="email" name="email" placeholder="email" required><i class="validation"><span></span><span></span></i>
</p>
<p>
<input type="password" id="password" name="password" placeholder="Password" required><i class="validation"><span></span><span></span></i>
</p>
<p>
<button id="login" value="Login" class="login" name="login">Login</button>
</p>
</div>
<div id="create-account-wrap">
<p>Not a member? <a href="regform.html">Create Account</a><p>
</div><!--create-account-wrap-->
</div><!--login-form-wrap-->
<!-- partial -->
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.4/firebase-app.js";
import { getAuth, signInWithEmailAndPassword, signOut} from "https://www.gstatic.com/firebasejs/9.8.4/firebase-auth.js";
import { getDatabase,set,ref, update} from "https://www.gstatic.com/firebasejs/9.8.4/firebase-database.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
const firebaseConfig = {
apiKey: "AIzaSyCcGqW996lHHYUsOMMsK-wTTvdgGKHebMI",
authDomain: "healthierwe-4d9e4.firebaseapp.com",
projectId: "healthierwe-4d9e4",
storageBucket: "healthierwe-4d9e4.appspot.com",
messagingSenderId: "483118630289",
appId: "1:483118630289:web:59140dc8abe27328374630"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const database = getDatabase(app);
login.addEventListener('click',(e) =>{
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
var lgDate=new Date();
update(ref(database, 'users/' + user.uid), {
last_login : lgDate,
})
.then(() => {
// Data saved successfully!
alert('Login Successful Welcome Back to HealthierWe');
window.location.href="index.html";
})
.catch((error) => {
// The write failed...
alert(error);
});
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
alert(errorMessage);
});
signOut(auth).then(() => {
// Sign-out successful.
}).catch((error) => {
// An error happened.
});
});
</script>
</body>
</html>