-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
122 lines (110 loc) · 5.52 KB
/
index.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
<!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, shrink-to-fit=no">
<title>Login</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="assets/css/Google-Stylel-Login.css">
<link rel="stylesheet" href="assets/css/Navigation-Dark-Clean.css">
<link rel="stylesheet" href="assets/css/styles.css">
</head>
<body>
<div class="login-card" id="login_page">
<img class="profile-img-card" src="assets/img/logo.png" alt="">
<p class="profile-name-card"> </p>
<form id ="form" action="index.php" method="post" class="form-signin">
<span class="reauth-email"> </span>
<input id="inputEmail" name="email" class="form-control" type="email" required="" autofocus="" placeholder="Email address">
<input id="inputPassword" name="password" class="form-control" type="password" required="" placeholder="Password">
<div class="checkbox">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="formCheck-2">
<label class="form-check-label" for="formCheck-2">
Remember me
</label>
</div>
</div>
<!-- <input type="submit" class="btn btn-primary btn-block btn-lg btn-signin" value="Login" id="sign_in"/> -->
<button type="submit" class="btn btn-primary accordion-body btn-lg btn-signin" value="Login" id="sign_in">Sign in</button>
</form>
<!-- <a href="#" class="forgot-password">
Forgot your password?
</a> -->
</div>
<div class="footer">
<footer class="ps_footer_text" >Copyright © 2020, Internet Explorers, University of The Witwatersrand, Johannesburg. All rights reserved.</footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.all.min.js"></script>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.11/firebase-app.js";
import {getAuth, onAuthStateChanged, signInWithEmailAndPassword} from "https://www.gstatic.com/firebasejs/9.6.11/firebase-auth.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.11/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: "AIzaSyAZVQZO8XWR0UTPoSMLrRN7nSltUDW9Xzs",
authDomain: "dfmpc-student-placement-system.firebaseapp.com",
databaseURL: "https://dfmpc-student-placement-system-default-rtdb.europe-west1.firebasedatabase.app",
projectId: "dfmpc-student-placement-system",
storageBucket: "dfmpc-student-placement-system.appspot.com",
messagingSenderId: "295214875936",
appId: "1:295214875936:web:546dcdb4f822d1c4c84345",
measurementId: "G-1JPG0HXVWQ"
};
// Initialize Firebase and variables
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const auth = getAuth();
const login_page = document.getElementById("login_page");
const form = document.getElementById("form");
onAuthStateChanged(auth, (user) => {
if (user)
//user is signed in
// alert ("Login successful");
//
return false;
})
//add event listener to submit button in form so that once User logs in, page redirects to HomePage.
form.addEventListener("submit", (event) =>{
event.preventDefault();
//create js variables from html email and password
const email = document.getElementById("inputEmail").value;
const password = document.getElementById("inputPassword").value;
//print user entered email and password to console
console.log(email," ", password)
var attempt = 1; // Variable to count number of attempts.
//use firebase authentication to check if user exists
signInWithEmailAndPassword(auth, email, password)
.then((user) => {
if (user) {
//if user exists, the login is successful, redirect to homepage
window.location = "home.html";
}
})
.catch((error) => {
console.log("error", error);
Swal.fire({
toast: true,
icon: 'error',
title: 'Login Failed. Check your email or password.',
animation: false,
position: 'top-right',
showConfirmButton: false,
timer: 1500,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer)
toast.addEventListener('mouseleave', Swal.resumeTimer)
}
}) //Alert if user entered details are incorrect
});
})
</script>
<script src="node_modules/bootstrap/dist/js/bootstrap.bundle.js"></script>
</body>
</html>