forked from AyatsujiTsukasa/Ant-Planner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.js
65 lines (58 loc) · 1.75 KB
/
utility.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
function getCookie(c_name){
if (document.cookie.length>0){
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1){
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) {
c_end=document.cookie.length;
}
return unescape(document.cookie.substring(c_start,c_end).replace(/\+/g, " "));
}
}
return "";
}
$("#usernameSide").html(getCookie("username"));
$('#logOut').on("click", function () {
clearCookie();
window.location = 'login.html';
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
});
function onLoad() {
gapi.load('auth2', function() {
gapi.auth2.init();
});
}
$('#changePW').on("click", function () {
var _this = $(this).parent(),
action = _this.attr("action");
$.post(action, _this.serialize()+"&id="+getCookie("ownerId"), function (data) {
$('.ajaxMsg').html(data).show();
if(/Password Changed!/.test(data)){
clearCookie();
$('#redirect').html("Redirecting to login page...3");
setTimeout(function () {$('#redirect').html("Redirecting to login page...2");}, 1000);
setTimeout(function () {$('#redirect').html("Redirecting to login page...1");}, 2000);
setTimeout(function () {
$('#redirect').html("Redirecting to login page...0");
window.location = 'login.html';
}, 3000);
}
});
});
function confirm(e) {
if (e.keyCode === 13) {
$("#changePW").click();
}
}
$(".reset").on("click", function() {
$("#changePW-form")[0].reset();
})
function clearCookie() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++)
document.cookie=cookies[i].split("=")[0]+"=; path=/";
}