Marked as 0.2.8

This commit is contained in:
Wu Cheng-Han 2015-05-15 12:58:13 +08:00
parent 2d36d7ce84
commit 4e64583a0b
96 changed files with 3281 additions and 22102 deletions

53
public/js/common.js Normal file
View 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();
}
}