BigW Consortium Gitlab

oauth_remember_me.js 909 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/**
 * 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() {
15
    $('#remember_me', this.container).on('click', this.toggleRememberMe);
16 17
  }

18 19
  // eslint-disable-next-line class-methods-use-this
  toggleRememberMe(event) {
20
    const rememberMe = $(event.target).is(':checked');
21

22
    $('.oauth-login', this.container).each((i, element) => {
23
      const href = $(element).attr('href');
24 25

      if (rememberMe) {
26
        $(element).attr('href', `${href}?remember_me=1`);
27 28 29 30 31 32
      } else {
        $(element).attr('href', href.replace('?remember_me=1', ''));
      }
    });
  }
}