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 2 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)
}
})
}
}
8 changes: 4 additions & 4 deletions client/app/core/authentication-api.factory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ 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) => {
expect(Session.active()).to.eq(false)
})
})
Expand Down
7 changes: 5 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,11 @@ 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.

Notifications.message('danger', '', __('Incorrect username or password.'), false)
Copy link
Member

Choose a reason for hiding this comment

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

If the response has a server message we should probably display that here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We probably could but a couple of thoughts. The message that comes back just says "Authentication failed". At a minimum the message we display is a little more specific and it is also translated vs the raw message from the server. Keep in mind, I didn't add this notification message, merely moved it from the factory up to the state that it pertains to.

Copy link
Member

Choose a reason for hiding this comment

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

So a compromise if displaying the original text, 'Login failed, possibly invalid credentials.' augmented with the server feedback (which might provide additional detail depending on error)?

Copy link
Member

Choose a reason for hiding this comment

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

And normally I wouldn't press on this matter, but my 👃 is in a bz right now where not showing the full error message issssssss no bueno https://bugzilla.redhat.com/show_bug.cgi?id=1498984

}
Session.destroy()
})
}
Expand Down