Skip to content

Commit

Permalink
Merge pull request #1142 from chalettu/password-clear
Browse files Browse the repository at this point in the history
Added ability for login screen to clear password on failed attempt
  • Loading branch information
chriskacerguis authored Oct 24, 2017
2 parents 2b9ba12 + f12dd5a commit 2fd9a01
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
33 changes: 17 additions & 16 deletions client/app/core/authentication-api.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ export function AuthenticationApiFactory ($http, $base64, API_BASE, Session, Not
return service

function login (userLogin, password) {
return $http.get(API_BASE + '/api/auth?requester_type=ui', {
headers: {
'Authorization': 'Basic ' + $base64.encode([userLogin, password].join(':')),
'X-Auth-Token': undefined,
'X-Miq-Group': undefined
}
}).then(loginSuccess, loginFailure)

function loginSuccess (response) {
Session.setAuthToken(response.data.auth_token)
}
return new Promise((resolve, reject) => {
$http.get(API_BASE + '/api/auth?requester_type=ui', {
headers: {
'Authorization': 'Basic ' + $base64.encode([userLogin, password].join(':')),
'X-Auth-Token': undefined,
'X-Miq-Group': undefined
}
}).then(loginSuccess, loginFailure)

function loginFailure (response) {
Session.destroy()
Notifications.message('danger', '', __('Incorrect username or password.'), false)
function loginSuccess (response) {
Session.setAuthToken(response.data.auth_token)
resolve(response)
}

return response
}
function loginFailure (response) {
Session.destroy()
reject(response)
}
})
}
}
10 changes: 6 additions & 4 deletions client/app/core/authentication-api.factory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ describe('Authentication API', () => {
let mockDir = 'tests/mock/authentication-api/'
const errorResponse = readJSON(mockDir + 'failure.json')

it('should fail Login', (done) => {
it('should fail Login', () => {
Session.destroy()
sinon.stub($http, 'get').returns(Promise.reject(errorResponse))
AuthenticationApi.login('test', 'test').then(function (data) {
done()

return AuthenticationApi.login('test', 'test').then(function (data) {
expect(Session.active()).to.eq(false)
}).catch((err) => {
if (err) {
expect(Session.active()).to.eq(false)
}
})
})
})
Expand Down
8 changes: 6 additions & 2 deletions client/app/states/login/login.state.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ function StateController (exception, $state, Text, RBAC, API_LOGIN, API_PASSWORD
Session.destroy()
}
})
.catch(() => {
exception.catch('Login failed, possibly invalid credentials.')
.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()
})
}
Expand Down

0 comments on commit 2fd9a01

Please sign in to comment.