<commit_before>'use strict';

angular.module('cpZenPlatform').controller('login', ['$state', '$scope', '$location', '$window', 'auth', 'alertService', '$translate','$cookies', 'cdLanguagesService', loginCtrl]);

function loginCtrl($state, $scope, $location, $window, auth, alertService, $translate, $cookies, cdLanguagesService) {
  $scope.referer = $state.params.referer ? $state.params.referer : '/dojo-list';
  
  var msgmap = {
    'unknown': $translate.instant('login.msgmap.unknown'),
    'user-not-found': $translate.instant('login.msgmap.user-not-found'),
    'invalid-password': $translate.instant('login.msgmap.invalid-password'),
    'reset-sent': $translate.instant('login.msgmap.reset-sent')
  }

  var path = window.location.pathname

  $scope.login = {}
  $scope.forgot = {}

  $scope.isVisible = function(view) {
    return $scope.currentView === view
  }

  $scope.show = function(view) {
    $scope.message = ''
    $scope.errorMessage = ''

    $scope.currentView = view
  }

  $scope.doRegister = function(user) {
    auth.register(user, function(data) {
      if(data.ok) {
        alertService.showAlert($translate.instant('login.register.success'), function() {
          auth.login(user, function(data) {
            $window.location.href = '/dashboard' + $scope.referer;
          });
        });
      } else {
        var reason = data.why === 'nick-exists' ? $translate.instant('user name already exists') : $translate.instant('server error');
        alertService.showAlert($translate.instant('login.register.failure')+ ' ' + reason);
      }
    }, function() {
      
    });
  }

  $scope.doLogin = function() {
    $scope.message = ''
    $scope.errorMessage = ''

    if (!$scope.loginForm.$valid) {
      return
    }

    auth.login($scope.login,
      function(data){
        $window.location.href = '/dashboard' + $scope.referer;
      },
      function(){
        $scope.errorMessage = $translate.instant('Invalid email or password');
      }
    )
  }

    $scope.sendPasswordResetEmail = function() {
      $scope.message = ''
      $scope.errorMessage = ''

      if (!$scope.forgotPasswordForm.$valid) {
        return
      }

      auth.reset({
        email:$scope.forgot.email
      }, function() {
        $scope.message = msgmap['reset-sent'];
      }, function(out) {
        $scope.errorMessage = msgmap[out.why] || msgmap.unknown
      })
    }

    $scope.logout = function(){
      auth.logout(function(data){
        $window.location.href = '/'
      })
    }

    $scope.goHome = function() {
      window.location.href = '/'
    }


    auth.instance(function(data){
      if( data.user ) {
        $scope.user = data.user;
        if (path==='/') {
          $window.location.href = 'dashboard'
        }
      }
      else {
        $scope.show('login')
      }
    });
  }<commit_msg>Fix indentation<commit_after>'use strict';

angular.module('cpZenPlatform').controller('login', ['$state', '$scope', '$location', '$window', 'auth', 'alertService', '$translate','$cookies', 'cdLanguagesService', loginCtrl]);

function loginCtrl($state, $scope, $location, $window, auth, alertService, $translate, $cookies, cdLanguagesService) {
  $scope.referer = $state.params.referer ? $state.params.referer : '/dojo-list';
  
  var msgmap = {
    'unknown': $translate.instant('login.msgmap.unknown'),
    'user-not-found': $translate.instant('login.msgmap.user-not-found'),
    'invalid-password': $translate.instant('login.msgmap.invalid-password'),
    'reset-sent': $translate.instant('login.msgmap.reset-sent')
  }

  var path = window.location.pathname

  $scope.login = {}
  $scope.forgot = {}

  $scope.isVisible = function(view) {
    return $scope.currentView === view
  }

  $scope.show = function(view) {
    $scope.message = ''
    $scope.errorMessage = ''

    $scope.currentView = view
  }

  $scope.doRegister = function(user) {
    auth.register(user, function(data) {
      if(data.ok) {
        alertService.showAlert($translate.instant('login.register.success'), function() {
          auth.login(user, function(data) {
            $window.location.href = '/dashboard' + $scope.referer;
          });
        });
      } else {
        var reason = data.why === 'nick-exists' ? $translate.instant('user name already exists') : $translate.instant('server error');
        alertService.showAlert($translate.instant('login.register.failure')+ ' ' + reason);
      }
    }, function() {
      
    });
  }

  $scope.doLogin = function() {
    $scope.message = ''
    $scope.errorMessage = ''

    if (!$scope.loginForm.$valid) {
      return
    }

    auth.login($scope.login,
      function(data){
        $window.location.href = '/dashboard' + $scope.referer;
      },
      function(){
        $scope.errorMessage = $translate.instant('Invalid email or password');
      }
    )
  }

  $scope.sendPasswordResetEmail = function() {
    $scope.message = ''
    $scope.errorMessage = ''

    if (!$scope.forgotPasswordForm.$valid) {
      return
    }

    auth.reset({
      email:$scope.forgot.email
    }, function() {
      $scope.message = msgmap['reset-sent'];
    }, function(out) {
      $scope.errorMessage = msgmap[out.why] || msgmap.unknown
    })
  }

  $scope.logout = function(){
    auth.logout(function(data){
      $window.location.href = '/'
    })
  }

  $scope.goHome = function() {
    window.location.href = '/'
  }


  auth.instance(function(data){
    if( data.user ) {
      $scope.user = data.user;
      if (path==='/') {
        $window.location.href = 'dashboard'
      }
    }
    else {
      $scope.show('login')
    }
  });
}
{'fraction_non_alphanumeric': 0.17609391675560299, 'fraction_numerical': 0.0, 'mean_word_length': 2.714002642007926, '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': '2131673', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1758, 'n_words': 261}