Commit d6023d33 authored by Timothy Andrew's avatar Timothy Andrew

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

parent dbe6cc6e
......@@ -59,6 +59,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';
// EE-only
import ApproversSelect from './approvers_select';
......@@ -134,6 +135,7 @@ import AuditLogs from './audit_logs';
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