2017-06-15 08:13:30 -04:00
|
|
|
/**
|
|
|
|
* 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() {
|
2017-07-03 12:23:28 -04:00
|
|
|
$('#remember_me', this.container).on('click', this.toggleRememberMe);
|
2017-06-15 08:13:30 -04:00
|
|
|
}
|
|
|
|
|
2017-07-03 12:23:28 -04:00
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
|
|
toggleRememberMe(event) {
|
2017-06-19 09:10:34 -04:00
|
|
|
const rememberMe = $(event.target).is(':checked');
|
2017-06-15 08:13:30 -04:00
|
|
|
|
2017-07-03 12:23:28 -04:00
|
|
|
$('.oauth-login', this.container).each((i, element) => {
|
2017-06-19 09:10:34 -04:00
|
|
|
const href = $(element).attr('href');
|
2017-06-15 08:13:30 -04:00
|
|
|
|
|
|
|
if (rememberMe) {
|
2017-06-19 09:10:34 -04:00
|
|
|
$(element).attr('href', `${href}?remember_me=1`);
|
2017-06-15 08:13:30 -04:00
|
|
|
} else {
|
|
|
|
$(element).attr('href', href.replace('?remember_me=1', ''));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|