-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
70 lines (62 loc) · 2.09 KB
/
script.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
document.querySelector('#signup-submit').onclick = function (event) {
event.preventDefault();
let name = document.querySelector('#signup-name').value;
let pass = document.querySelector('#signup-pass').value;
let email = document.querySelector('#signup-email').value;
let birthday = document.querySelector('#signup-birthday').value;
let sex = document.querySelectorAll('.sex');
for (let i = 0; i < sex.length; i++) {
if (sex[i].checked) {
sex = sex[i].value;
break;
}
}
let data = {
"name": name,
"pass": pass,
"email": email,
"birthday": birthday,
"sex": sex,
}
ajax('core/signup.php', 'POST', signup, data);
function signup(result) {
console.log(result);
if (result == 2) {
M.toast({html: 'Заповни всі поля'})
}
else if (result == 1) {
M.toast({html: 'Юху! Тепер можеш увійти'})
}
else {
M.toast({html: 'Помилка 404!'})
}
}
}
document.querySelector('#login-submit').onclick = function (event) {
event.preventDefault();
let pass = document.querySelector('#login-pass').value;
let email = document.querySelector('#login-email').value;
let data = {
"pass": pass,
"email": email
}
ajax('core/login.php', 'POST', login, data);
function login(result) {
//console.log(result);
if (result == 2) {
M.toast({html: 'Заповни всі поля'})
}
else if (result == 0) {
M.toast({html: 'Користувач не знайдений'})
}
else {
console.log(result);
result = JSON.parse(result);
var d = new Date();
d.setTime(d.getTime() + (10 * 60 * 1000));
var expires = d.toUTCString();
document.cookie = `email=${result.email}; expires=${expires}; path=/`;
location.href = "cabinet.php";
}
}
}