<commit_before>import template from './password-prompt-modal.html!text';

export let directiveName = 'tocPasswordPromptModal';
export default /*@ngInject*/ function tocPasswordPromptModal() {
  return {
    restrict: 'E',
    template: template,
    scope: {
      showModal: '&',
      hideModal: '&',
      removeModal: '&',
    },
    controllerAs: 'passwordPromptModal',
    controller: /*@ngInject*/ function PasswordPromptModalController(
      $scope,
      $ionicLoading,
      $ionicModal,
      $log,
      $timeout,
      $window,
      $q,
      session,
      navigation,
      notifications,
      identity,
      state
    ) {
      this.removeModal = $scope.removeModal;
      this.hideModal = $scope.hideModal;
      this.showModal = $scope.showModal;

      let userExistsCursor = state.cloudUnencrypted.cryptography;
      let updateUserExists = () => {
        this.userExists = userExistsCursor.get() !== undefined;
      };
      state.addListener(userExistsCursor, updateUserExists, $scope);

      let staySignedIn = state.local.session.get(['staySignedIn']);
      this.staySignedIn = staySignedIn === undefined ? true : staySignedIn;

      this.begin = function begin(passwordPromptForm) {
        if (passwordPromptForm.$invalid) {
          if (passwordPromptForm.$error.required &&
            passwordPromptForm.$error.required[1]) {
            return notifications.notifySystem('Please enter a password.');
          }
          if (passwordPromptForm.$error.equalTo) {
            return notifications.notifySystem(
              'Please ensure your passwords match.'
            );
          }
          if (passwordPromptForm.$error.required) {
            return notifications.notifySystem('Please enter a password.');
          }

          return notifications.notifyGenericError(passwordPromptForm.$error);
        }

        let updateStaySignedIn = () => staySignedIn === this.staySignedIn ?
          $q.when() :
          state.save(state.local.session, ['staySignedIn'], this.staySignedIn);

        $window.tocResumeLoadingAnimation();
        return this.hideModal()
          .then(() => session.start(
            { password: <PASSWORD> },
            this.staySignedIn
          ))
          .then(() => this.removeModal())
          .catch((error) => {
            this.showModal()
              .then(() => $window.tocResumeLoadingAnimation());
            let showErrorMessage = () => {
              if (error === 'identity: wrong password') {
                return notifications.notifySystem(
                  'The password you entered was incorrect.'
                );
              }

              return notifications.notifyGenericError(error);
            };<commit_msg>Fixed animation not pausing on caught error<commit_after>import template from './password-prompt-modal.html!text';

export let directiveName = 'tocPasswordPromptModal';
export default /*@ngInject*/ function tocPasswordPromptModal() {
  return {
    restrict: 'E',
    template: template,
    scope: {
      showModal: '&',
      hideModal: '&',
      removeModal: '&',
    },
    controllerAs: 'passwordPromptModal',
    controller: /*@ngInject*/ function PasswordPromptModalController(
      $scope,
      $ionicLoading,
      $ionicModal,
      $log,
      $timeout,
      $window,
      $q,
      session,
      navigation,
      notifications,
      identity,
      state
    ) {
      this.removeModal = $scope.removeModal;
      this.hideModal = $scope.hideModal;
      this.showModal = $scope.showModal;

      let userExistsCursor = state.cloudUnencrypted.cryptography;
      let updateUserExists = () => {
        this.userExists = userExistsCursor.get() !== undefined;
      };
      state.addListener(userExistsCursor, updateUserExists, $scope);

      let staySignedIn = state.local.session.get(['staySignedIn']);
      this.staySignedIn = staySignedIn === undefined ? true : staySignedIn;

      this.begin = function begin(passwordPromptForm) {
        if (passwordPromptForm.$invalid) {
          if (passwordPromptForm.$error.required &&
            passwordPromptForm.$error.required[1]) {
            return notifications.notifySystem('Please enter a password.');
          }
          if (passwordPromptForm.$error.equalTo) {
            return notifications.notifySystem(
              'Please ensure your passwords match.'
            );
          }
          if (passwordPromptForm.$error.required) {
            return notifications.notifySystem('Please enter a password.');
          }

          return notifications.notifyGenericError(passwordPromptForm.$error);
        }

        let updateStaySignedIn = () => staySignedIn === this.staySignedIn ?
          $q.when() :
          state.save(state.local.session, ['staySignedIn'], this.staySignedIn);

        $window.tocResumeLoadingAnimation();
        return this.hideModal()
          .then(() => session.start(
            { password: <PASSWORD> },
            this.staySignedIn
          ))
          .then(() => this.removeModal())
          .catch((error) => {
            this.showModal()
              .then(() => $window.tocPauseLoadingAnimation());
            let showErrorMessage = () => {
              if (error === 'identity: wrong password') {
                return notifications.notifySystem(
                  'The password you entered was incorrect.'
                );
              }

              return notifications.notifyGenericError(error);
            };
{'fraction_non_alphanumeric': 0.11756141947224749, 'fraction_numerical': 0.0003639672429481347, 'mean_word_length': 2.1713791113675707, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '3405409', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1423, 'n_words': 276}