-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathfirebase.js
More file actions
84 lines (71 loc) · 2.34 KB
/
firebase.js
File metadata and controls
84 lines (71 loc) · 2.34 KB
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
var user;
function signUp(){
var mail = document.getElementById("mail").value
var pwd = document.getElementById("password").value
var type = document.getElementById("type").value
firebase.auth().createUserWithEmailAndPassword(mail,pwd).then((userCredential) => {
var user = firebase.auth().currentUser;
var uid;
if (user != null) {
uid = user.uid;
}
var firebaseRef = firebase.database().ref();
var userData = {
userEmail: mail,
userPassword: pwd,
userType:type,
}
firebaseRef.child(uid).set(userData);
if(type == "Teacher"){
window.location = "main.html";
}
else{
//
}
}).catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
});
}
function logIn(){
var mail = document.getElementById("mail").value
var pwd = document.getElementById("password").value
var type = document.getElementById("type").value
firebase.auth().signInWithEmailAndPassword(mail,pwd).then((userCredential) => {
const user = userCredential.user;
if(type == "Teacher"){
window.location = "main.html";
}
else{
//
}
}).catch((error)=>{
var errorCode = error.code;
var errorMessage = error.message;
});
}
function google(){
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Google Access Token. You can use it to access the Google API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
if(type == "Teacher"){
window.location = "main.html";
}
else{
//
}
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
}