Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #253 from alexpelan/alexpelan/issue-250
Browse files Browse the repository at this point in the history
Issue #250: Provide feedback on failed login
Closes #250
  • Loading branch information
jkleinsc committed Jan 4, 2016
2 parents 6acadef + 832626b commit a5b128a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ To install the frontend please do the following:
- Clone this repo with `git clone https://github.com/HospitalRun/hospitalrun-frontend`, go to the cloned folder and:
1. `npm install` to install needed node modules.
2. `bower install` to install needed bower modules.
3. `npm install -g phantomjs2` to install PhantomJS2, which is needed to run tests.
- Install ands configure [CouchDB](http://couchdb.apache.org/)
1. Download and install CouchDB from http://couchdb.apache.org/#download
2. Create admin user:
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var LoginController = Ember.Controller.extend({
this.get('session').authenticate('authenticator:custom', {
identification: identification,
password: password
}).catch((reason) => {
this.set('errorMessage', reason.error);
}).catch((error) => {
this.set('errorMessage', error.reason);
});
}
}
Expand Down
5 changes: 5 additions & 0 deletions app/styles/_sign_in_screen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@
color: $navy_drk2;
}

.form-signin-alert {
margin-top: 15px;
margin-bottom: 0;
}

input { background: white; }
}
5 changes: 5 additions & 0 deletions app/templates/login.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<div class="form-group">
{{input id='password' type='password' value=password placeholder='Password' class='form-control'}}
</div>

<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>

{{#if errorMessage}}
<div class="alert alert-danger form-signin-alert" role="alert">{{errorMessage}}</div>
{{/if}}
</form>
</div> <!-- /container -->
23 changes: 23 additions & 0 deletions tests/acceptance/login-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,26 @@ test('visiting / redirects user to login', function(assert) {
click('button:contains(Sign in)');
});
});

test('incorrect credentials shows an error message on the screen', function(assert) {
assert.expect(2);
runWithPouchDump('default', function() {
visit('/');

let errorMessage = 'Name or password is incorrect.';

stubRequest('post', '/db/_session', function(request) {
assert.equal(request.requestBody, 'name=hradmin&password=tset', 'credential are sent to the server');
request.error({ 'error': 'unauthorized', 'reason': errorMessage });
});

fillIn('#identification', 'hradmin');
fillIn('#password', 'tset');
click('button:contains(Sign in)');

andThen(function() {
assert.equal(find('.form-signin-alert').text(), errorMessage, 'Error reason is shown');
});

});
});

0 comments on commit a5b128a

Please sign in to comment.