From f88789856be8a484bb1800a1b1695c2ac4b8a3b1 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 13 May 2015 12:32:27 +0200 Subject: Logout --- src/js/Botleagues.js | 5 +++++ src/js/BotleaguesFrontend.js | 11 +++++++++++ src/js/main.js | 29 ++++++++++++++++++++--------- 3 files changed, 36 insertions(+), 9 deletions(-) (limited to 'src/js') 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(); - $('
  • ').append( - $('') - .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(); + $('
  • ').append( + $('') + .attr('role', 'presentation') + .attr('title', 'User profile') + .attr('href', '/profile') + .text(email)) + .appendTo($('#nav')); + $('
  • ').append( + $('') + .attr('role', 'presentation') + .attr('title', 'Logout') + .attr('href', '/logout') + .text('Logout')) + .appendTo($('#nav')); +} \ No newline at end of file -- cgit v1.2.3