BigW Consortium Gitlab

Commit d705a254 by Timothy Andrew

Move OAuth "remember me" javascript logic into a class.

parent 43337c12
......@@ -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':
......
/**
* 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', ''));
}
});
}
}
......@@ -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', ''));
}
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment