diff options
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/Botleagues.js | 5 | ||||
-rw-r--r-- | src/js/BotleaguesFrontend.js | 11 | ||||
-rw-r--r-- | src/js/main.js | 29 |
3 files changed, 36 insertions, 9 deletions
diff --git a/src/js/Botleagues.js b/src/js/Botleagues.js index f11c995..21dd5d7 100644 --- a/src/js/Botleagues.js +++ b/src/js/Botleagues.js @@ -40,4 +40,9 @@ Botleagues.login = function(email, password) { }); $.cookie(BotleaguesFrontend.cookie_login_email, email); +}; + +Botleagues.logout = function(){ + BotleaguesFrontend.clearLoginCookies(); + BotleaguesFrontend.redirect('/'); };
\ No newline at end of file diff --git a/src/js/BotleaguesFrontend.js b/src/js/BotleaguesFrontend.js index 752cd7a..b94708e 100644 --- a/src/js/BotleaguesFrontend.js +++ b/src/js/BotleaguesFrontend.js @@ -29,4 +29,15 @@ BotleaguesFrontend.error = function(user_options) { BotleaguesFrontend.refresh = function() { location.reload(); +}; + +BotleaguesFrontend.redirect = function(location) { + window.location = location; +} + +BotleaguesFrontend.clearLoginCookies = function() { + $.removeCookie(BotleaguesFrontend.cookie_login_email); + $.removeCookie(BotleaguesFrontend.cookie_login_user_id); + $.removeCookie(BotleaguesFrontend.cookie_login_token); + $.removeCookie(BotleaguesFrontend.cookie_login_valid_till); };
\ No newline at end of file diff --git a/src/js/main.js b/src/js/main.js index d3ab688..4444273 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -3,13 +3,24 @@ $(document).ready(function(){ // Show profile link instead of login if user is logged in var email = $.cookie(BotleaguesFrontend.cookie_login_email); if (typeof email != 'undefined' && $.cookie(BotleaguesFrontend.cookie_login_valid_till) > (new Date()).getTime()) { - $('#nav .login-link').remove(); - $('<li>').append( - $('<a>') - .attr('role', 'presentation') - .attr('title', 'User profile') - .attr('href', '/profile') - .text(email)) - .appendTo($('#nav')); + setupLoginMenu(email); } -});
\ No newline at end of file +}); + +function setupLoginMenu(email) { + $('#nav .login-link').remove(); + $('<li>').append( + $('<a>') + .attr('role', 'presentation') + .attr('title', 'User profile') + .attr('href', '/profile') + .text(email)) + .appendTo($('#nav')); + $('<li>').append( + $('<a>') + .attr('role', 'presentation') + .attr('title', 'Logout') + .attr('href', '/logout') + .text('Logout')) + .appendTo($('#nav')); +}
\ No newline at end of file |