-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
113 lines (103 loc) · 3.83 KB
/
main.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
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
// $(document).ready(function() {
// $("#error").hide();
// });
function remainSignIn(){
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)
.then(function() {
// Existing and future Auth states are now persisted in the current
// session only. Closing the window would clear any existing state even
// if a user forgets to sign out.
// ...
// New sign-in will be persisted with session persistence.
return signIn();
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
});
}
function signUp() {
let id = document.getElementById('email').value;
let pw = document.getElementById('password').value;
let cf = document.getElementById('checkpw').value;
if(pw !== cf) {
alert("Password does not match the confirm password.");
return;
}
firebase.auth().createUserWithEmailAndPassword(id, pw)
.then(function() {
alert("가입 완료!!");
document.getElementById('email').value = "";
document.getElementById('password').value = "";
document.getElementById('checkpw').value = "";
document.getElementById('name').value = "";
})
.catch(function(e) {
$("#error #errmsg").html(e.message);
$("#error").show();
$("#signUp").hide();
return;
});
}
function signIn() {
let id = document.getElementById('ID').value;
let pw = document.getElementById('PW').value;
firebase.auth().signInWithEmailAndPassword(id, pw)
.then(function() {
alert("로그인 되었습니당")
document.getElementById('sign_up').style.height = '0';
document.getElementById('SignInForm').style.height = '0';
document.getElementById('forgot').style.height = '0';
document.getElementById('SignedForm').style.height = '70px';
document.getElementById('SignOut').style.height = '150px';
})
.catch(function(e) {
lastWork = "signIn";
$("#error #errmsg").html(e.message);
$("#error").show();
$("#signIn").hide();
return;
});
}
// Sign out
function signOut() {
if(!confirm("진짜 로그아웃 하실거에요?")) {
return;
}
firebase.auth().signOut().then(function() {
location.reload();
document.getElementById('sign_up').style.height = '55px';
document.getElementById('SignInForm').style.height = '70px';
document.getElementById('forgot').style.height = '150px';
document.getElementById('SignedForm').style.height = '0';
document.getElementById('SignOut').style.height = '0';
}, function(e) {
lastWork = "authorized";
$("#error #errmsg").html(e.message)
$("#error").show();
$("#authorized").hide();
});
}
//check login
function checkLogin(){
let user = firebase.auth().currentUser;
if(user){
document.getElementById('sign_up').style.height = '0';
document.getElementById('SignInForm').style.height = '0px';
document.getElementById('forgot').style.height = '0px';
document.getElementById('SignedForm').style.height = '70px';
document.getElementById('SignOut').style.height = '150px';
}
else{
document.getElementById('sign_up').style.height = '55px';
document.getElementById('SignInForm').style.height = '70px';
document.getElementById('forgot').style.height = '150px';
document.getElementById('SignedForm').style.height = '0';
document.getElementById('SignOut').style.height = '0';
}
}
// function back() {
// $("#" + lastWork).show();
// $("#error").hide();
// }