<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/. */

// a very light wrapper around the real FxaClient to reduce boilerplate code
// and to allow us to develop to features that are not yet present in the real
// client.

'use strict';

define([
  'fxaClient',
  'jquery',
  'p'
],
function (FxaClient, $, p) {
  var client;

  function FxaClientWrapper() {
    // nothing to do here.
  }

  FxaClientWrapper.prototype = {
    _getClientAsync: function () {
      var defer = p.defer();

      if (client) {
        defer.resolve(client);
      } else {
        $.getJSON('/config', function (data) {
          client = new FxaClient(data.fxaccountUrl);
          defer.resolve(client);
        });
      }

      return defer.promise;
    },

    signIn: function (email, password) {
      return this._getClientAsync().then(function (client) {
                return client.signIn(email, password, { keys: true });
              });
    },

    signUp: function (email, password) {
      return this._getClientAsync().then(function (client) {
        return client.signUp(email, password, { keys: true })
               .then(function () {
                  return client.signIn(email, password, { keys: true });
                });

      });
    },

    verifyCode: function (uid, code) {
      return this._getClientAsync().then(function (client) {
                return client.verifyCode(uid, code);
              });
    },

    requestPasswordReset: function (email) {
      return this._getClientAsync().then(function (client) {
                return client.passwordForgotSendCode(email);
              });
    },<commit_msg>Save account data to the Session when signing 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/. */

// a very light wrapper around the real FxaClient to reduce boilerplate code
// and to allow us to develop to features that are not yet present in the real
// client.

'use strict';

define([
  'fxaClient',
  'jquery',
  'p',
  'lib/session'
],
function (FxaClient, $, p, Session) {
  var client;

  function FxaClientWrapper() {
    // nothing to do here.
  }

  FxaClientWrapper.prototype = {
    _getClientAsync: function () {
      var defer = p.defer();

      if (client) {
        defer.resolve(client);
      } else {
        $.getJSON('/config', function (data) {
          client = new FxaClient(data.fxaccountUrl);
          defer.resolve(client);
        });
      }

      return defer.promise;
    },

    signIn: function (email, password) {
      return this._getClientAsync().then(function (client) {
                return client.signIn(email, password, { keys: true });
              })
             .then(function(accountData) {
                Session.email = email;
                Session.sessionToken = accountData.sessionToken;
                Session.keyFetchToken = accountData.keyFetchToken;
                Session.unwrapBKey = accountData.unwrapBKey;
                Session.uid = accountData.uid;

                return accountData;
              });

    },

    signUp: function (email, password) {
      var self = this;
      return this._getClientAsync().then(function (client) {
        return client.signUp(email, password, { keys: true })
               .then(function () {
                  return self.signIn(email, password);
                });

      });
    },

    verifyCode: function (uid, code) {
      return this._getClientAsync().then(function (client) {
                return client.verifyCode(uid, code);
              });
    },

    requestPasswordReset: function (email) {
      return this._getClientAsync().then(function (client) {
                return client.passwordForgotSendCode(email);
              });
    },
{'fraction_non_alphanumeric': 0.11679012345679013, 'fraction_numerical': 0.0019753086419753087, 'mean_word_length': 2.101837672281776, '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': '1050865', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1093, 'n_words': 320}