Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability for login screen to clear password on failed attempt #1142

Merged
merged 3 commits into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should vm.credentials.login also be cleared out?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize ref was for only password to be blank, but if it was an unsuccessful login attempt :-/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RFE just requested password be cleared out.

const message = response.data.error.message
Notifications.message('danger', '', __('Login failed, possibly invalid credentials. ') + `(${message})`, false)
}
Session.destroy()
})
}
Expand Down