-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
84 lines (68 loc) · 2.47 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const serverAddress = "https://camping.sebtota.com:5000"
const nav_signIn = document.getElementById('nav_sign-in')
const nav_signOut = document.getElementById('nav_sign-out')
const nav_profile = document.getElementById('nav_profile')
const warning_incorrectPass = document.getElementById('label_incorrect-password');
const warning_recaptchaErrorSignIn = document.getElementById('label_recaptcha-error-signin');
const warning_recaptchaErrorSignUp = document.getElementById('label_recaptcha-error-signup');
const warning_passwordConfirmation = document.getElementById('label__pass_conf');
const input_signupPass = document.getElementById("input_user-pass");
const input_signupPassConf = document.getElementById("input_user-confirm-pass");
async function createRequest(route, method='POST', data = undefined) {
let response;
if (data === undefined) {
response = await fetch(serverAddress + route, {
method: method,
redirect: 'follow',
credentials: 'include'
});
} else {
response = await fetch(serverAddress + route, {
method: method,
redirect: 'follow',
credentials: 'include',
body: JSON.stringify(data)
});
}
return await response.json();
}
// Split and iterate over the cookie string, returning the cookie value if found
function getCookie(cookieName) {
const cookies = document.cookie.split("; ");
// Iterate over every cookie in the cookie string
for (let i = 0; i < cookies.length; i++) {
let cookieObj = cookies[i].split("=");
if (cookieObj[0] === cookieName) {
// Remove double quotes from string if they exist
let retCookie = cookieObj[1];
if (retCookie[0] === '"') {
return retCookie.substring(1, retCookie.length - 1);
} else {
return retCookie;
}
}
}
// No cookie found with that name
return null;
}
//--- Sign Out Process ---//
async function signOutPost() {
const response = await fetch(serverAddress + '/logout', {
method: 'POST',
redirect: 'follow',
credentials: 'include'
});
return await response.json();
}
function signOut() {
signOutPost().then(ret => {
console.log(ret);
console.log("signed out");
$("#loader").hide();
window.location.href="index.html";
})
}
$('#nav_sign-out').on('click',function (e){
e.preventDefault();
signOut();
});