-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
57 lines (48 loc) · 1.37 KB
/
index.js
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
var database = firebase.database();
$(document).ready(function () {
$(".sign-up-button").click(signUpClick);
$(".sign-in-button").click(signInClick);
});
function signUpClick(event) {
event.preventDefault();
var email = $(".sign-email").val();
var password = $(".sign-password").val();
createUser(email, password);
}
function createUser(email, password) {
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(function (response) {
var userId = response.user.uid;
database.ref("users/" + userId).set({
email: email
});
alert("Cadastro concluido com sucesso !!!\n " + email);
window.location = "main.html?id=" + userId;
})
.catch(function(error) {
handleError(error);
});
}
function signInClick(event) {
event.preventDefault();
var email = $(".sign-email").val();
var password = $(".sign-password").val();
signInUser(email, password);
}
function signInUser(email, password) {
firebase.auth().signInWithEmailAndPassword(email, password)
.then(function(response) {
var userId = response.user.uid;
redirectToTasks(userId);
})
.catch(function(error) {
handleError(error)
});
}
function handleError(error) {
var errorMessage = error.message;
alert(errorMessage);
}
function redirectToTasks(userId) {
window.location = "main.html?id=" + userId;
}