From eb9eada894d53ffb9ff5a814c7cdf65756b34254 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Tue, 18 Nov 2014 21:17:38 +0530 Subject: [PATCH] FEATURE: log out user everywhere and refresh/redirect --- .../discourse/initializers/logout.js.es6 | 23 +++++++++++++++++++ app/controllers/admin/users_controller.rb | 1 + config/locales/client.en.yml | 2 ++ 3 files changed, 26 insertions(+) create mode 100644 app/assets/javascripts/discourse/initializers/logout.js.es6 diff --git a/app/assets/javascripts/discourse/initializers/logout.js.es6 b/app/assets/javascripts/discourse/initializers/logout.js.es6 new file mode 100644 index 00000000000..a65de91d7a2 --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/logout.js.es6 @@ -0,0 +1,23 @@ +/** + Subscribe to "logout" change events via the Message Bus +**/ +export default { + name: "logout", + after: "message-bus", + + initialize: function () { + if (!Discourse.MessageBus) { return; } + + Discourse.MessageBus.subscribe("/logout", function (user_id) { + var refresher = function() { + var redirect = Discourse.SiteSettings.logout_redirect; + if(redirect.length === 0){ + window.location.pathname = Discourse.getURL('/'); + } else { + window.location.href = redirect; + } + }; + bootbox.dialog(I18n.t("logout"), {label: I18n.t("refresh"), callback: refresher}, {onEscape: refresher, backdrop: 'static'}) + }); + } +}; diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index ed69ad463fa..c43622ba3ab 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -68,6 +68,7 @@ class Admin::UsersController < Admin::AdminController def log_out @user.auth_token = nil @user.save! + MessageBus.publish "/logout", @user.id, user_ids: [@user.id] render nothing: true end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 5e5810ef192..f54a95c06e2 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -535,6 +535,8 @@ en: fixed: "Load Page" close: "Close" assets_changed_confirm: "This site was just updated. Refresh now for the latest version?" + logout: "You were logged out." + refresh: "Refresh" read_only_mode: enabled: "An administrator enabled read-only mode. You can continue to browse the site but interactions may not work." login_disabled: "Login is disabled while the site is in read only mode."