From 465c2a2ba8d987e1474417f6442540030d0f7c86 Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Fri, 15 Aug 2014 12:57:29 +1000
Subject: [PATCH] FEATURE: logout redirect support

Allow users to also logout on an external site after logging out locally
---
 app/assets/javascripts/discourse.js | 9 ++++++++-
 config/locales/server.en.yml        | 1 +
 config/site_settings.yml            | 3 +++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js
index 8c8d72538..2d58c7737 100644
--- a/app/assets/javascripts/discourse.js
+++ b/app/assets/javascripts/discourse.js
@@ -81,7 +81,14 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
     Discourse.User.logout().then(function() {
       // Reloading will refresh unbound properties
       Discourse.KeyValueStore.abandonLocal();
-      window.location.pathname = Discourse.getURL('/');
+
+      var redirect = Discourse.SiteSettings.logout_redirect;
+      if(redirect.length === 0){
+        window.location.pathname = Discourse.getURL('/');
+      } else {
+        window.location.href = redirect;
+      }
+
     });
   },
 
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index c40c33b7f..36bcb666a 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -923,6 +923,7 @@ en:
     delete_all_posts_max: "The maximum number of posts that can be deleted at once with the Delete All Posts button. If a user has more than this many posts, the posts cannot all be deleted at once and the user can't be deleted."
     username_change_period: "The number of days after registration that accounts can change their username (0 to disallow username change)."
     email_editable: "Allow users to change their e-mail address after registration."
+    logout_redirect: "Location to redirect browser to after logout EG: (http://somesite.com/logout)"
 
     allow_uploaded_avatars: "Allow users to upload custom avatars."
     allow_animated_avatars: "Allow users to use animated gif avatars. WARNING: run the avatars:refresh rake task after changing this setting."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 19580ce14..10820894d 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -255,6 +255,9 @@ users:
   username_change_period: 3
   auto_track_topics_after: 240000
   email_editable: true
+  logout_redirect:
+    client: true
+    default: ''
   enable_names:
     client: true
     default: true