diff options
-rw-r--r-- | app/assets/javascripts/dispatcher.js | 2 | ||||
-rw-r--r-- | app/assets/javascripts/oauth_remember_me.js | 31 | ||||
-rw-r--r-- | app/views/devise/shared/_omniauth_box.html.haml | 14 |
3 files changed, 33 insertions, 14 deletions
diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index 4247540de22..a58d1be68b5 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -56,6 +56,7 @@ import GfmAutoComplete from './gfm_auto_complete'; import ShortcutsBlob from './shortcuts_blob'; import initSettingsPanels from './settings_panels'; import initExperimentalFlags from './experimental_flags'; +import OAuthRememberMe from './oauth_remember_me'; (function() { var Dispatcher; @@ -127,6 +128,7 @@ import initExperimentalFlags from './experimental_flags'; case 'sessions:new': new UsernameValidator(); new ActiveTabMemoizer(); + new OAuthRememberMe({ container: $("#remember_me") }).bindEvents(); break; case 'projects:boards:show': case 'projects:boards:index': diff --git a/app/assets/javascripts/oauth_remember_me.js b/app/assets/javascripts/oauth_remember_me.js new file mode 100644 index 00000000000..3048f6fec90 --- /dev/null +++ b/app/assets/javascripts/oauth_remember_me.js @@ -0,0 +1,31 @@ +/** + * OAuth-based login buttons have a separate "remember me" checkbox. + * + * Toggling this checkbox adds/removes a `remember_me` parameter to the + * login buttons' href, which is passed on to the omniauth callback. + **/ + +export default class OAuthRememberMe { + constructor(opts = {}) { + this.container = opts.container || ''; + this.loginLinkSelector = '.oauth-login'; + } + + bindEvents() { + this.container.on('click', this.toggleRememberMe); + } + + toggleRememberMe(event) { + var rememberMe = $(event.target).is(":checked"); + + $('.oauth-login').each(function(i, element) { + var href = $(element).attr('href'); + + if (rememberMe) { + $(element).attr('href', href + '?remember_me=1'); + } else { + $(element).attr('href', href.replace('?remember_me=1', '')); + } + }); + } +} diff --git a/app/views/devise/shared/_omniauth_box.html.haml b/app/views/devise/shared/_omniauth_box.html.haml index e06b804e349..493e18565c0 100644 --- a/app/views/devise/shared/_omniauth_box.html.haml +++ b/app/views/devise/shared/_omniauth_box.html.haml @@ -10,17 +10,3 @@ %fieldset = check_box_tag :remember_me = label_tag :remember_me, "Remember Me" - -:javascript - $("#remember_me").click(function(event){ - var rememberMe = $(event.target).is(":checked"); - $(".oauth-login").each(function(i, element) { - var href = $(element).attr('href'); - - if (rememberMe) { - $(element).attr('href', href + '?remember_me=1'); - } else { - $(element).attr('href', href.replace('?remember_me=1', '')); - } - }); - }); |