<commit_before>'use strict';

angular.module('impactApp')
  .controller('LoginCtrl', function($rootScope, $scope, Auth, $location, $state, currentMdph) {
    $scope.user = {};
    $scope.error = null;

    $scope.login = function(form) {
      if (form.$valid) {
        Auth.login({
          email: form.email.$modelValue,
          password: form.password.$modelValue
        })
        .then(function(user) {
          if (Auth.hasRole(user, 'admin')) {
            return $state.go('dashboard.workflow', {codeDepartement: currentMdph.zipcode}, {reload: true});
          }

          if (Auth.hasRole(user, 'adminMdph')) {
            return $state.go('dashboard.workflow', {codeDepartement: user.mdph  && user.mdph.zipcode}, {reload: true});
          }

          return $state.go('mon_compte', {}, {reload: true});

        })
        .catch(function(err) {
          $scope.error = err.message;
        });
      }
    };
  });<commit_msg>When the user is logged, move to profile if only one is set.<commit_after>'use strict';

angular.module('impactApp')
  .controller('LoginCtrl', function($rootScope, $scope, Auth, $location, $state, currentMdph, ProfileResource) {
    $scope.user = {};
    $scope.error = null;

    $scope.login = function(form) {
      if (form.$valid) {
        Auth.login({
          email: form.email.$modelValue,
          password: form.password.$modelValue
        })
        .then(function(user) {
          if (Auth.hasRole(user, 'admin')) {
            return $state.go('dashboard.workflow', {codeDepartement: currentMdph.zipcode}, {reload: true});
          }

          if (Auth.hasRole(user, 'adminMdph')) {
            return $state.go('dashboard.workflow', {codeDepartement: user.mdph  && user.mdph.zipcode}, {reload: true});
          }

          // When the user is logged, move to profile if only one is set.
          ProfileResource.query({userId: user._id}).$promise.then(function(profiles){
            if(profiles && (profiles.length === 1)){
              return $state.go('profil', {profileId: profiles[0]._id});
            }
            else{
              console.log('LoginCtrl multicomptes');
              return $state.go('mon_compte', {}, {reload: true});
            }
          })

        })
        .catch(function(err) {
          $scope.error = err.message;
        });
      }
    };
  });
{'fraction_non_alphanumeric': 0.16052520118593816, 'fraction_numerical': 0.0008470986869970351, 'mean_word_length': 2.196211096075778, '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': '1779028', 'n_tokens_mistral': 718, 'n_tokens_neox': 710, 'n_words': 136}