Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 5131f3b

Browse files
committedJul 15, 2015
Merge pull request #17 from appirio-tech/login-validation
Add error bar to username field and check username after clicking login
2 parents 4853004 + 85d289b commit 5131f3b

File tree

4 files changed

+61
-27
lines changed

4 files changed

+61
-27
lines changed
 

‎app/account/login/login.controller.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
angular.module('tc.account').controller('LoginController', LoginController);
55

6-
LoginController.$inject = ['$log', '$state', '$stateParams', 'tcAuth', 'authtoken'];
6+
LoginController.$inject = ['$log', '$state', '$stateParams', 'tcAuth', 'authtoken', 'UserService'];
77

8-
function LoginController($log, $state, $stateParams, tcAuth, authtoken) {
8+
function LoginController($log, $state, $stateParams, tcAuth, authtoken, UserService) {
99
var vm = this;
1010
vm.passwordReset = false;
11-
11+
vm.usernameExists = true;
1212

1313
var redirect = function() {
1414
// check if the user is already logged in
@@ -50,20 +50,30 @@
5050
);
5151
}
5252

53-
vm.doLogin = function() {
54-
// TODO placeholder, validate form etc
55-
tcAuth.login(vm.username, vm.password).then(
56-
function(data) {
57-
// success
58-
$log.debug('logged in');
59-
redirect(true);
60-
},
61-
function(err) {
62-
// handle error
63-
vm.wrongPassword = true;
64-
vm.password = '';
65-
}
66-
);
53+
vm.login = function() {
54+
UserService.validateUserHandle(vm.username)
55+
.then(function() {
56+
// User does not exist
57+
vm.usernameExists = false;
58+
})
59+
.catch(function() {
60+
// User exists
61+
vm.usernameExists = true;
62+
tcAuth.login(vm.username, vm.password).then(
63+
function(data) {
64+
// success
65+
$log.debug('logged in');
66+
redirect(true);
67+
},
68+
function(err) {
69+
// handle error
70+
vm.wrongPassword = true;
71+
vm.password = '';
72+
}
73+
);
74+
});
75+
76+
6777
};
6878

6979
vm.socialLogin = function(backend) {

‎app/account/login/login.jade

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
.login-container
22
h1 Login
33

4-
form(name="loginForm", role="form", ng-submit="loginForm.$valid && vm.doLogin()", novalidate)
4+
form(name="loginForm", role="form", ng-submit="loginForm.$valid && vm.login()", novalidate)
55
.form-errors
66

7-
p.login-error(ng-show="loginForm.username.$error.usernameExists") This user does not exist.
7+
p.login-error(ng-hide="vm.usernameExists") This user does not exist.
88

9-
p.login-error(ng-if="vm.wrongPassword") That password doesn't match the one we have on file. Please try again.
9+
p.login-error(ng-show="vm.wrongPassword") That password doesn't match the one we have on file. Please try again.
1010

11-
p.login-error(ng-if="vm.socialLoginError === 401") User with that profile is not registered.
11+
p.login-error(ng-show="vm.socialLoginError === 401") User with that profile is not registered.
1212

13-
div(ng-if="loginForm.$submitted")
14-
p.login-error(ng-if="loginForm.username.$error.required") Please enter your username or email.
13+
div(ng-show="loginForm.$submitted")
14+
p.login-error(ng-show="loginForm.username.$error.required") Please enter your username or email.
1515

16-
input(ng-model="vm.username", ng-model-options="{debounce: {'default': 500}}", name="username", placeholder="Username or Email", type="text", required, username-exists)
16+
div.validation-bar(ng-class="{'error-bar': !vm.usernameExists}")
17+
input(ng-model="vm.username", ng-blur="vm.usernameExists = true", name="username", placeholder="Username or Email", type="text", required)
1718

1819
input(ng-model="vm.password", name="password", placeholder="Password", type="password", required)
1920

‎assets/css/account/account.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ body, .view-container {
3434
input {
3535
height: 40px;
3636
width: 290px;
37-
padding-left: 10px;
37+
padding-left: 15px;
3838
border: 0;
3939
@include source-sans;
4040
font-size: 16px;

‎assets/css/account/login.scss

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,31 @@
1313
justify-content: space-between;
1414
}
1515

16-
.form-errors p {
17-
margin-bottom: 10px;
16+
.form-errors {
17+
width: 300px;
18+
19+
p {
20+
margin-bottom: 10px;
21+
}
22+
}
23+
24+
.validation-bar {
25+
position: relative;
26+
27+
&:before {
28+
content: '';
29+
display: none;
30+
position: absolute;
31+
top: 0;
32+
left: 0;
33+
height: 42px;
34+
width: 5px;
35+
background-color: red;
36+
}
37+
38+
&.error-bar:before {
39+
display: block;
40+
}
1841
}
1942

2043
.forgot-password {

0 commit comments

Comments
 (0)