Skip to content

Commit 09522a1

Browse files
committed
feat(client): add a bunch of types, use class in auth.service
1 parent fc1fd82 commit 09522a1

File tree

6 files changed

+120
-29
lines changed

6 files changed

+120
-29
lines changed

Diff for: templates/app/client/app/account(auth)/login/login.controller.js

+32-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
11
'use strict';
2+
// @flow
3+
<%_ if(filters.flow) { -%>
4+
type User = {
5+
name: string;
6+
email: string;
7+
password: string;
8+
};
9+
<%_ } -%>
10+
<%_ if(filters.ts) { -%>
11+
interface User {
12+
name: string;
13+
email: string;
14+
password: string;
15+
}
16+
<%_ } -%>
217

318
export default class LoginController {
19+
user: User = {
20+
name: '',
21+
email: '',
22+
password: ''
23+
};
24+
errors = {login: undefined};
25+
submitted = false;
26+
Auth;
27+
<%_ if(filters.ngroute) { -%>
28+
$location;
29+
<%_ } if(filters.uirouter) { -%>
30+
$state;<% } %>
31+
432
/*@ngInject*/
533
constructor(Auth<% if (filters.ngroute) { %>, $location<% } %><% if (filters.uirouter) { %>, $state<% } %>) {
6-
this.user = {};
7-
this.errors = {};
8-
this.submitted = false;
9-
10-
this.Auth = Auth;<% if (filters.ngroute) { %>
11-
this.$location = $location;<% } if (filters.uirouter) { %>
34+
this.Auth = Auth;
35+
<%_ if(filters.ngroute) { -%>
36+
this.$location = $location;
37+
<%_ } if(filters.uirouter) { -%>
1238
this.$state = $state;<% } %>
1339
}
1440

Diff for: templates/app/client/app/account(auth)/settings/settings.controller.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
'use strict';
2+
// @flow
3+
<%_ if(filters.flow) { -%>
4+
type User = {
5+
oldPassword: string;
6+
newPassword: string;
7+
confirmPassword: string;
8+
};
9+
<%_ } -%>
10+
<%_ if(filters.ts) { -%>
11+
interface User {
12+
oldPassword: string;
13+
newPassword: string;
14+
confirmPassword: string;
15+
}
16+
<%_ } -%>
217

318
export default class SettingsController {
4-
errors = {};
19+
user: User = {
20+
oldPassword: '',
21+
newPassword: '',
22+
confirmPassword: ''
23+
};
24+
errors = {other: undefined};
25+
message = '';
526
submitted = false;
27+
Auth;
628

729
/*@ngInject*/
830
constructor(Auth) {
@@ -12,7 +34,7 @@ export default class SettingsController {
1234
changePassword(form) {
1335
this.submitted = true;
1436

15-
if (form.$valid) {
37+
if(form.$valid) {
1638
this.Auth.changePassword(this.user.oldPassword, this.user.newPassword)
1739
.then(() => {
1840
this.message = 'Password successfully changed.';

Diff for: templates/app/client/app/account(auth)/signup/signup.controller.js

+37-12
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,69 @@
11
'use strict';
2+
// @flow
3+
<%_ if(filters.flow) { -%>
4+
type User = {
5+
name: string;
6+
email: string;
7+
password: string;
8+
};
9+
<%_ } -%>
10+
<%_ if(filters.ts) { -%>
11+
interface User {
12+
name: string;
13+
email: string;
14+
password: string;
15+
}
16+
<%_ } -%>
217

318
export default class SignupController {
4-
//start-non-standard
5-
user = {};
19+
user: User = {
20+
name: '',
21+
email: '',
22+
password: ''
23+
};
624
errors = {};
725
submitted = false;
8-
//end-non-standard
26+
Auth;
27+
<%_ if(filters.ngroute) { -%>
28+
$location;
29+
<%_ } if(filters.uirouter) { -%>
30+
$state;<% } %>
931

1032
/*@ngInject*/
1133
constructor(Auth<% if (filters.ngroute) { %>, $location<% } %><% if (filters.uirouter) { %>, $state<% } %>) {
12-
this.Auth = Auth;<% if (filters.ngroute) { %>
13-
this.$location = $location;<% } if (filters.uirouter) { %>
34+
this.Auth = Auth;
35+
<%_ if(filters.ngroute) { -%>
36+
this.$location = $location;
37+
<%_ } if(filters.uirouter) { -%>
1438
this.$state = $state;<% } %>
1539
}
1640

1741
register(form) {
1842
this.submitted = true;
1943

20-
if (form.$valid) {
21-
this.Auth.createUser({
44+
if(form.$valid) {
45+
return this.Auth.createUser({
2246
name: this.user.name,
2347
email: this.user.email,
2448
password: this.user.password
2549
})
2650
.then(() => {
2751
// Account created, redirect to home
28-
<% if (filters.ngroute) { %>this.$location.path('/');<% } %><% if (filters.uirouter) { %>this.$state.go('main');<% } %>
52+
<% if(filters.ngroute) { %>this.$location.path('/');<% } -%>
53+
<% if(filters.uirouter) { %>this.$state.go('main');<% } -%>
2954
})
3055
.catch(err => {
3156
err = err.data;
3257
this.errors = {};
33-
<% if (filters.mongooseModels) { %>
58+
<%_ if(filters.mongooseModels) { -%>
3459
// Update validity of form fields that match the mongoose errors
3560
angular.forEach(err.errors, (error, field) => {
3661
form[field].$setValidity('mongoose', false);
3762
this.errors[field] = error.message;
38-
});<% }
39-
if (filters.sequelizeModels) { %>
63+
});<% } %>
64+
<%_ if(filters.sequelizeModels) { -%>
4065
// Update validity of form fields that match the sequelize errors
41-
if (err.name) {
66+
if(err.name) {
4267
angular.forEach(err.fields, field => {
4368
form[field].$setValidity('mongoose', false);
4469
this.errors[field] = err.message;

Diff for: templates/app/client/app/main/main.component.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ import uiRouter from 'angular-ui-router';<% } _%>
77
import routing from './main.routes';
88

99
export class MainController {
10+
$http;
11+
<%_ if(filters.socketio) { -%>
12+
socket;<% } %>
13+
awesomeThings = [];
14+
<%_ if(filters.models) { -%>
15+
newThing = '';<% } %>
16+
1017
/*@ngInject*/
1118
constructor($http<% if(filters.socketio) { %>, $scope, socket<% } %>) {
12-
this.$http = $http;<% if (filters.socketio) { %>
13-
this.socket = socket;<% } %>
14-
this.awesomeThings = [];
15-
<%_ if (filters.socketio) { _%>
19+
this.$http = $http;
20+
<%_ if(filters.socketio) { -%>
21+
this.socket = socket;
1622

1723
$scope.$on('$destroy', function() {
1824
socket.unsyncUpdates('thing');

Diff for: templates/app/client/components/auth(auth)/auth.service.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
'use strict';
22
// @flow
3+
class User {
4+
_id: string = '';
5+
name: string = '';
6+
email: string = '';
7+
role: string = '';
8+
$promise = undefined;
9+
}
310

411
export function AuthService($location, $http, $cookies, $q, appConfig, Util, User) {
512
'ngInject';
613
var safeCb = Util.safeCb;
7-
var currentUser = {};
14+
var currentUser: User = new User();
815
var userRoles = appConfig.userRoles || [];
916

1017
if ($cookies.get('token') && $location.path() !== '/logout') {
@@ -46,7 +53,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
4653
*/
4754
logout() {
4855
$cookies.remove('token');
49-
currentUser = {};
56+
currentUser = new User();
5057
},
5158

5259
/**

Diff for: templates/app/client/components/navbar/navbar.component.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
'use strict';
22

33
export class NavbarComponent {
4-
//start-non-standard
54
menu = [{
65
'title': 'Home',
76
<% if (filters.uirouter) { %>'state': 'main'<% } else { %>'link': '/'<% } %>
87
}];
9-
8+
<%_ if(!filters.uirouter) { -%>
9+
$location;
10+
<%_ } -%>
11+
<%_ if (filters.auth) { -%>
12+
isLoggedIn: Function;
13+
isAdmin: Function;
14+
getCurrentUser: Function;
15+
<%_ } -%>
1016
isCollapsed = true;
11-
//end-non-standard
1217
<%_ if(filters.ngroute || filters.auth) { _%>
1318

1419
constructor(<% if(!filters.uirouter) { %>$location<% } if(!filters.uirouter && filters.auth) { %>, <% } if (filters.auth) { %>Auth<% } %>) {

0 commit comments

Comments
 (0)