<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';

define([
  'underscore',
  'views/base',
  'stache!templates/sign_in',
  'lib/session',
  'lib/fxa-client',
  'lib/password-mixin'
],
function (_, BaseView, SignInTemplate, Session, FxaClient, PasswordMixin) {
  var View = BaseView.extend({
    template: SignInTemplate,
    className: 'sign-in',

    events: {
      'submit form': 'signIn',
      'keyup input': 'enableButtonWhenValid',
      'change input': 'enableButtonWhenValid',
      'change .show-password': 'onPasswordVisibilityChange'
    },

    signIn: function (event) {
      event.preventDefault();

      if (! (this.isValid())) {
        return;
      }

      var email = this.$('.email').val();
      var password = this.$('.password').val();

      var client = new FxaClient();
      client.signIn(email, password)
            .then(function (accountData) {
              Session.channel.send('login', {
                email: email,
                uid: accountData.uid,
                sessionToken: accountData.sessionToken,
                unwrapBKey: accountData.unwrapBKey,
                keyFetchToken: accountData.keyFetchToken
              });
              router.navigate('settings', { trigger: true });
            })
            .done(null, function (err) {
              this.$('.error').html(err.message);

              console.error('Error?', err);
            }.bind(this));
    },

    isValid: function () {
      return this._validateEmail() && this._validatePassword();
    },

    _validateEmail: function () {
      return this._isElementValid('.email');
    },

    _validatePassword: function () {
      return this._isElementValid('.password');
    },

    _isElementValid: function (selector) {
      var el = this.$(selector);
      var value = el.val();
      return value && el[0].validity.valid;
    }
  });<commit_msg>Added displayError to sign in.<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';

define([
  'underscore',
  'views/base',
  'stache!templates/sign_in',
  'lib/session',
  'lib/fxa-client',
  'lib/password-mixin'
],
function (_, BaseView, SignInTemplate, Session, FxaClient, PasswordMixin) {
  var View = BaseView.extend({
    template: SignInTemplate,
    className: 'sign-in',

    events: {
      'submit form': 'signIn',
      'keyup input': 'enableButtonWhenValid',
      'change input': 'enableButtonWhenValid',
      'change .show-password': 'onPasswordVisibilityChange'
    },

    signIn: function (event) {
      event.preventDefault();

      if (! (this.isValid())) {
        return;
      }

      var email = this.$('.email').val();
      var password = this.$('.password').val();

      var client = new FxaClient();
      client.signIn(email, password)
            .then(function (accountData) {
              Session.channel.send('login', {
                email: email,
                uid: accountData.uid,
                sessionToken: accountData.sessionToken,
                unwrapBKey: accountData.unwrapBKey,
                keyFetchToken: accountData.keyFetchToken
              });
              router.navigate('settings', { trigger: true });
            })
            .done(null, _.bind(function (err) {
              this.displayError(err.message);
            }, this));
    },

    isValid: function () {
      return this._validateEmail() && this._validatePassword();
    },

    _validateEmail: function () {
      return this._isElementValid('.email');
    },

    _validatePassword: function () {
      return this._isElementValid('.password');
    },

    _isElementValid: function (selector) {
      var el = this.$(selector);
      var value = el.val();
      return value && el[0].validity.valid;
    }
  });
{'fraction_non_alphanumeric': 0.1409723918885903, 'fraction_numerical': 0.002443195699975568, 'mean_word_length': 2.2936444086886563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6931740', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1155, 'n_words': 276}