mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 22:54:42 -04:00
Marked as 0.2.8
This commit is contained in:
parent
2d36d7ce84
commit
4e64583a0b
96 changed files with 3281 additions and 22102 deletions
53
public/js/common.js
Normal file
53
public/js/common.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
//common
|
||||
var domain = 'change this';
|
||||
var checkAuth = false;
|
||||
var profile = null;
|
||||
var lastLoginState = getLoginState();
|
||||
var loginStateChangeEvent = null;
|
||||
|
||||
function resetCheckAuth() {
|
||||
checkAuth = false;
|
||||
}
|
||||
|
||||
function setLoginState(bool) {
|
||||
Cookies.set('loginstate', bool, {
|
||||
expires: 14
|
||||
});
|
||||
if (loginStateChangeEvent && bool != lastLoginState)
|
||||
loginStateChangeEvent();
|
||||
lastLoginState = bool;
|
||||
}
|
||||
|
||||
function getLoginState() {
|
||||
return Cookies.get('loginstate') === "true";
|
||||
}
|
||||
|
||||
function clearLoginState() {
|
||||
Cookies.remove('loginstate');
|
||||
}
|
||||
|
||||
function checkIfAuth(yesCallback, noCallback) {
|
||||
var cookieLoginState = getLoginState();
|
||||
if (!checkAuth || typeof cookieLoginState == 'undefined') {
|
||||
$.get('/me')
|
||||
.done(function (data) {
|
||||
if (data && data.status == 'ok') {
|
||||
profile = data;
|
||||
yesCallback(profile);
|
||||
setLoginState(true);
|
||||
} else {
|
||||
noCallback();
|
||||
setLoginState(false);
|
||||
}
|
||||
})
|
||||
.fail(function () {
|
||||
noCallback();
|
||||
setLoginState(false);
|
||||
});
|
||||
checkAuth = true;
|
||||
} else if (cookieLoginState) {
|
||||
yesCallback(profile);
|
||||
} else {
|
||||
noCallback();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue