<commit_before>import templateUrl from './login.html'

/** @ngInject */
export function LoginState (routerHelper) {
  routerHelper.configureStates(getStates())
}

function getStates () {
  return {
    'login': {
      parent: 'blank',
      url: '/login',
      templateUrl,
      controller: StateController,
      controllerAs: 'vm',
      title: N_('Login'),
      data: {
        layout: 'blank'
      }
    }
  }
}

/** @ngInject */
function StateController (exception, $state, Text, RBAC, API_LOGIN, API_PASSWORD, AuthenticationApi, Session,
                          $rootScope, Notifications, Language, ApplianceInfo, $window) {
  const vm = this

  vm.text = Text.login
  vm.credentials = {
    login: API_LOGIN,
    password: <PASSWORD>
  }
  vm.onSubmit = onSubmit

  if ($window.location.href.includes('?timeout')) {
    Notifications.message('danger', '', __('Your session has timed out.'), true)
    Session.destroy()
  }

  if ($window.location.href.includes('?pause')) {
    const params = (new URL($window.document.location)).searchParams
    const pauseLength = params.get('pause')
    Session.setPause(pauseLength)
  }

  if (Session.privilegesError) {
    Notifications.error(__('User does not have privileges to login.'))
    Session.destroy()
  }

  function onSubmit () {
    Session.timeoutNotified = false
    Session.privilegesError = false

    return AuthenticationApi.login(vm.credentials.login, vm.credentials.password)
    .then(Session.loadUser)
    .then(Session.requestWsToken)
    .then((response) => {
      if (angular.isDefined(response)) {
        Language.onLogin(response)
        ApplianceInfo.set(response)
        RBAC.setRole(response.identity.role)
      }

      if (RBAC.suiAuthorized()) {
        if (angular.isDefined($rootScope.notifications) && $rootScope.notifications.data.length > 0) {
          $rootScope.notifications.data.splice(0, $rootScope.notifications.data.length)
        }
        $window.location.href = $state.href('dashboard')
      } else {
        Session.privilegesError = true
        Notifications.error(__('You do not have permission to view the Service UI. Contact your administrator to update your group permissions.'))
        Session.destroy()
      }
    })
    .catch((response) => {
      if (response.status === 401) {
        vm.credentials.password = ''
        const message = response.data.error.message
        Notifications.message('danger', '', __('Login failed, possibly invalid credentials. ') + `(${message})`, false)
      }
      Session.destroy()
    })
  }
}
<commit_msg>clear user name field on failed login<commit_after>import templateUrl from './login.html'

/** @ngInject */
export function LoginState (routerHelper) {
  routerHelper.configureStates(getStates())
}

function getStates () {
  return {
    'login': {
      parent: 'blank',
      url: '/login',
      templateUrl,
      controller: StateController,
      controllerAs: 'vm',
      title: N_('Login'),
      data: {
        layout: 'blank'
      }
    }
  }
}

/** @ngInject */
function StateController (exception, $state, Text, RBAC, API_LOGIN, API_PASSWORD, AuthenticationApi, Session,
                          $rootScope, Notifications, Language, ApplianceInfo, $window) {
  const vm = this

  vm.text = Text.login
  vm.credentials = {
    login: API_LOGIN,
    password: <PASSWORD>
  }
  vm.onSubmit = onSubmit

  if ($window.location.href.includes('?timeout')) {
    Notifications.message('danger', '', __('Your session has timed out.'), true)
    Session.destroy()
  }

  if ($window.location.href.includes('?pause')) {
    const params = (new URL($window.document.location)).searchParams
    const pauseLength = params.get('pause')
    Session.setPause(pauseLength)
  }

  if (Session.privilegesError) {
    Notifications.error(__('User does not have privileges to login.'))
    Session.destroy()
  }

  function onSubmit () {
    Session.timeoutNotified = false
    Session.privilegesError = false

    return AuthenticationApi.login(vm.credentials.login, vm.credentials.password)
    .then(Session.loadUser)
    .then(Session.requestWsToken)
    .then((response) => {
      if (angular.isDefined(response)) {
        Language.onLogin(response)
        ApplianceInfo.set(response)
        RBAC.setRole(response.identity.role)
      }

      if (RBAC.suiAuthorized()) {
        if (angular.isDefined($rootScope.notifications) && $rootScope.notifications.data.length > 0) {
          $rootScope.notifications.data.splice(0, $rootScope.notifications.data.length)
        }
        $window.location.href = $state.href('dashboard')
      } else {
        Session.privilegesError = true
        Notifications.error(__('You do not have permission to view the Service UI. Contact your administrator to update your group permissions.'))
        Session.destroy()
      }
    })
    .catch((response) => {
      if (response.status === 401) {
        vm.credentials.login = ''
        vm.credentials.password = ''
        const message = response.data.error.message
        Notifications.message('danger', '', __('Login failed, possibly invalid credentials. ') + `(${message})`, false)
      }
      Session.destroy()
    })
  }
}

{'fraction_non_alphanumeric': 0.13337182448036952, 'fraction_numerical': 0.001924557351809084, 'mean_word_length': 2.919306184012066, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '7305129', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1514, 'n_words': 311}