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

Commit 6753076

Browse files
committed
Made properties more enum-like
1 parent 4c510f9 commit 6753076

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

app/account/login/login.controller.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
vm.$stateParams = $stateParams;
1212
vm.passwordReset = false;
1313
vm.currentPasswordDefaultPlaceholder = "Password";
14-
vm.loginErrors = {};
14+
vm.loginErrors = {
15+
USERNAME_NONEXISTANT: false,
16+
WRONG_PASSWORD: false,
17+
SOCIAL_LOGIN_ERROR: false
18+
};
1519

1620
vm.login = login;
1721
vm.socialLogin = socialLogin;
@@ -28,8 +32,8 @@
2832
}
2933

3034
function login() {
31-
vm.loginErrors['username-nonexistant'] = false;
32-
vm.loginErrors['wrong-password'] = false;
35+
vm.loginErrors.USERNAME_NONEXISTANT = false;
36+
vm.loginErrors.WRONG_PASSWORD = false;
3337

3438
// TODO ideally it should be done by dedicated directive to handle all outside clicks
3539
mainVm.menuVisible = false;
@@ -44,14 +48,14 @@
4448
UserService.validateUserEmail(vm.username).then(function(data) {
4549
if (data.valid) {
4650
// email doesn't exist
47-
vm.loginErrors['username-nonexistant'] = true;
51+
vm.loginErrors.USERNAME_NONEXISTANT = true;
4852
} else {
4953
_doLogin(vm.username, vm.currentPassword);
5054
}
5155
}).catch(function(resp) {
5256
// TODO handle error
5357
// assume email exists, login would in any case if it didn't
54-
vm.loginErrors['username-nonexistant'] = false;
58+
vm.loginErrors.USERNAME_NONEXISTANT = false;
5559
_doLogin(vm.username, vm.currentPassword);
5660
});
5761
} else {
@@ -62,7 +66,7 @@
6266
UserService.validateUserHandle(vm.username).then(function(data) {
6367
if (data.valid) {
6468
// username doesn't exist
65-
vm.loginErrors['username-nonexistant'] = true;
69+
vm.loginErrors.USERNAME_NONEXISTANT = true;
6670
} else {
6771
_doLogin(vm.username, vm.currentPassword);
6872
}
@@ -92,7 +96,7 @@
9296
break;
9397
case "UNKNOWN_ERROR":
9498
default:
95-
vm.loginErrors['wrong-password'] = true;
99+
vm.loginErrors.WRONG_PASSWORD = true;
96100
vm.password = '';
97101
}
98102
});
@@ -120,7 +124,7 @@
120124
case "USER_NOT_REGISTERED":
121125
default:
122126
vm.socialLoginError = 401;
123-
vm.loginErrors['social-login-error'] = true;
127+
vm.loginErrors.SOCIAL_LOGIN_ERROR = true;
124128
break;
125129
}
126130
});

app/account/login/login.jade

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
form(name="vm.loginForm", role="form", ng-submit="vm.loginForm.$valid && vm.login()", novalidate)
99
.form-errors(ng-messages="vm.loginErrors")
10-
p.form-error(ng-message="username-nonexistant") We couldn't find a member with that {{vm.emailOrUsername || "username"}}. Please check that you entered it correctly.
10+
p.form-error(ng-message="USERNAME_NONEXISTANT") We couldn't find a member with that {{vm.emailOrUsername || "username"}}. Please check that you entered it correctly.
1111

12-
p.form-error(ng-message="wrong-password") That password is incorrect. Please check that you entered the right one.
12+
p.form-error(ng-message="WRONG_PASSWORD") That password is incorrect. Please check that you entered the right one.
1313

14-
p.form-error(ng-message="social-login-error") User with that profile is not registered.
14+
p.form-error(ng-message="SOCIAL_LOGIN_ERROR") User with that profile is not registered.
1515

16-
div.validation-bar(ng-class="{'error-bar': !vm.usernameExists}")
16+
div.validation-bar(ng-class="{'error-bar': vm.loginErrors.USERNAME_NONEXISTANT}")
1717
input(ng-model="vm.username", name="username", placeholder="Username or Email", type="text", required)
1818

1919
toggle-password

0 commit comments

Comments
 (0)