<commit_before>/* Copyright 2013-2014 Extended Mind Technologies Oy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 'use strict';

 function UserEditorController($http, $rootScope, $scope, $timeout, AnalyticsService, AuthenticationService,
                               BackendClientService, SwiperService, SynchronizeService, UISessionService,
                               UserSessionService) {

  if ($scope.mode === 'signUp'){
    $scope.user = {};
  }

  $scope.changePassword = function (oldPassword, newPassword) {
    $scope.userEditOffline = false;
    $scope.changePasswordFailed = false;
    AuthenticationService.putChangePassword(UserSessionService.getEmail(), oldPassword, <PASSWORD>)
    .then(function(){
      // Need to relogin with new password
      AuthenticationService.login({username: UserSessionService.getEmail(),
        password: <PASSWORD>,
        remember: UserSessionService.isAuthenticateReplaceable()})
      .then(function(){
        $scope.closeEditor();
      });
    }, function(error){
      if (error.type === 'offline') {
        $scope.userEditOffline = true;
      } else if (error.type === 'forbidden') {
        $scope.changePasswordFailed = true;
      }
    });
  };

  // SIGN UP

  var userEditorEmailInputFocusCallbackFunction;
  $scope.registerUserEditorEmailInputCallbacks = function(focus){
    userEditorEmailInputFocusCallbackFunction = focus;
  };

  function userEditorOpened(){
    if ($scope.mode === 'signUp' && userEditorEmailInputFocusCallbackFunction){
      userEditorEmailInputFocusCallbackFunction();
    }
  }
  $scope.registerFeatureEditorOpenedCallback(userEditorOpened);

  $scope.signUpSwiperSlideChanged = function(slidePath/*, activeIndex*/){
    if (userEditorEmailInputFocusCallbackFunction && slidePath === 'signUp/main'){
      userEditorEmailInputFocusCallbackFunction();
    }
  };

  $scope.swipeToDetails = function(mode) {
    $scope.detailsMode = mode;
    if (mode === 'privacy'){
      $http.get('http://ext.md/privacy.html').then(function(privacyResponse){
        $scope.details = {html: privacyResponse.data};
        SwiperService.swipeTo('signUp/details');
        AnalyticsService.visit('privacy');
      });
    }else if (mode === 'terms') {
      $http.get('http://ext.md/terms.html').then(function(termsResponse){
        $scope.details = {html: termsResponse.data};
        SwiperService.swipeTo('signUp/details');
        AnalyticsService.visit('terms');
      });
    }
  };
  $scope.swipeToMain = function() {
    SwiperService.swipeTo('signUp/main');
  };

  $scope.signUp = function() {
    $scope.signupFailed = false;
    $scope.userEditOffline = false;
    $scope.loginFailed = false;

    // Cohort is a random number between 1 and 128
    var randomCohort = Math.floor(Math.random() * 128) + 1;

    var payload = {email: $scope.user.username,
     password: $<PASSWORD>,
     cohort: randomCohort};

    AuthenticationService.signUp(payload).then(signUpSuccess, signUpFailed);
  };

  function signUpSuccess(response) {
    // Register uuid change
    var oldUUID = UserSessionService.getUserUUID();
    SynchronizeService.notifyOwnerUUIDChange(oldUUID, response.uuid);
    UISessionService.notifyOwnerUUIDChange(oldUUID, response.uuid);
    AnalyticsService.doWithUuid('signUp', oldUUID, response.uuid);
    AuthenticationService.login($scope.user).then(
      function(response) {<commit_msg>Added remember to authentication when persistent storage is enabled<commit_after>/* Copyright 2013-2014 Extended Mind Technologies Oy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 'use strict';

 function UserEditorController($http, $rootScope, $scope, $timeout, AnalyticsService, AuthenticationService,
                               BackendClientService, SwiperService, SynchronizeService, UISessionService,
                               UserSessionService) {

  if ($scope.mode === 'signUp'){
    $scope.user = {};
  }

  $scope.changePassword = function (oldPassword, newPassword) {
    $scope.userEditOffline = false;
    $scope.changePasswordFailed = false;
    AuthenticationService.putChangePassword(UserSessionService.getEmail(), oldPassword, newPassword)
    .then(function(){
      // Need to relogin with new password
      AuthenticationService.login({username: UserSessionService.getEmail(),
        password: <PASSWORD>,
        remember: UserSessionService.isAuthenticateReplaceable()})
      .then(function(){
        $scope.closeEditor();
      });
    }, function(error){
      if (error.type === 'offline') {
        $scope.userEditOffline = true;
      } else if (error.type === 'forbidden') {
        $scope.changePasswordFailed = true;
      }
    });
  };

  // SIGN UP

  var userEditorEmailInputFocusCallbackFunction;
  $scope.registerUserEditorEmailInputCallbacks = function(focus){
    userEditorEmailInputFocusCallbackFunction = focus;
  };

  function userEditorOpened(){
    if ($scope.mode === 'signUp' && userEditorEmailInputFocusCallbackFunction){
      userEditorEmailInputFocusCallbackFunction();
    }
  }
  $scope.registerFeatureEditorOpenedCallback(userEditorOpened);

  $scope.signUpSwiperSlideChanged = function(slidePath/*, activeIndex*/){
    if (userEditorEmailInputFocusCallbackFunction && slidePath === 'signUp/main'){
      userEditorEmailInputFocusCallbackFunction();
    }
  };

  $scope.swipeToDetails = function(mode) {
    $scope.detailsMode = mode;
    if (mode === 'privacy'){
      $http.get('http://ext.md/privacy.html').then(function(privacyResponse){
        $scope.details = {html: privacyResponse.data};
        SwiperService.swipeTo('signUp/details');
        AnalyticsService.visit('privacy');
      });
    }else if (mode === 'terms') {
      $http.get('http://ext.md/terms.html').then(function(termsResponse){
        $scope.details = {html: termsResponse.data};
        SwiperService.swipeTo('signUp/details');
        AnalyticsService.visit('terms');
      });
    }
  };
  $scope.swipeToMain = function() {
    SwiperService.swipeTo('signUp/main');
  };

  $scope.signUp = function() {
    $scope.signupFailed = false;
    $scope.userEditOffline = false;
    $scope.loginFailed = false;

    // Cohort is a random number between 1 and 128
    var randomCohort = Math.floor(Math.random() * 128) + 1;

    var payload = {email: $scope.user.username,
     password: $<PASSWORD>,
     cohort: randomCohort};

    AuthenticationService.signUp(payload).then(signUpSuccess, signUpFailed);
  };

  function signUpSuccess(response) {
    // Register uuid change
    var oldUUID = UserSessionService.getUserUUID();
    SynchronizeService.notifyOwnerUUIDChange(oldUUID, response.uuid);
    UISessionService.notifyOwnerUUIDChange(oldUUID, response.uuid);
    AnalyticsService.doWithUuid('signUp', oldUUID, response.uuid);
    if (UserSessionService.isPersistentStorageEnabled()){
      $scope.user.remember = true;
    }
    AuthenticationService.login($scope.user).then(
      function(response) {
{'fraction_non_alphanumeric': 0.11917876815222835, 'fraction_numerical': 0.005007511266900351, 'mean_word_length': 3.6179190751445085, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5832604', 'n_tokens_mistral': 2284, 'n_tokens_neox': 2212, 'n_words': 492}