Skip to content

Commit f4c5471

Browse files
committed
fix(client): fix some outstanding client bugs
+cleanup
1 parent d88a530 commit f4c5471

File tree

10 files changed

+41
-27
lines changed

10 files changed

+41
-27
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// @flow
12
import { Component } from '@angular/core';
23
<%_ if(filters.uirouter) { -%>
34
import { StateService } from 'ui-router-ng2';<% } %>
45
<%_ if(filters.ngroute) { -%>
56
import { Router } from '@angular/router';<% } %>
67
import { AuthService } from '../../../components/auth/auth.service';
78

8-
// @flow
99
<%_ if(filters.flow) { -%>
1010
type User = {
1111
name: string;
@@ -48,8 +48,8 @@ export class LoginComponent {
4848
this.StateService = _StateService_;<% } %>
4949
}
5050

51-
login() {
52-
this.submitted = true;
51+
login(form) {
52+
if(form.invalid) return;
5353

5454
return this.AuthService.login({
5555
email: this.user.email,
@@ -63,7 +63,7 @@ export class LoginComponent {
6363
this.StateService.go('main');<% } %>
6464
})
6565
.catch(err => {
66-
this.errors.login = err.message;
66+
this.errors.login = err.json().message;
6767
});
6868
}
6969
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ <h1>Login</h1>
66
<p>Admin account is <code>[email protected]</code> / <code>admin</code></p>
77
</div>
88
<div class="col-sm-12">
9-
<form class="form" name="loginForm" (ngSubmit)="login()" novalidate #loginForm="ngForm">
9+
<form class="form" name="loginForm" (ngSubmit)="login(loginForm)" novalidate #loginForm="ngForm">
1010

1111
<div class="form-group">
1212
<label>Email</label>

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

+15-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { StateService } from 'ui-router-ng2';<% } %>
55
<%_ if(filters.ngroute) { -%>
66
import { Router } from '@angular/router';<% } %>
77
import { AuthService } from '../../../components/auth/auth.service';
8+
import template from './signup.html';
89

910
<%_ if(filters.flow) { -%>
1011
type User = {
1112
name: string;
1213
email: string;
1314
password: string;
14-
};<% } %>
15-
<%_ if(filters.ts) { -%>
15+
};<% } %><%_ if(filters.ts) { -%>
1616
interface User {
1717
name: string;
1818
email: string;
@@ -21,7 +21,7 @@ interface User {
2121

2222
@Component({
2323
selector: 'signup',
24-
template: require('./signup.<%=templateExt%>')
24+
template,
2525
})
2626
export class SignupComponent {
2727
user: User = {
@@ -61,19 +61,27 @@ export class SignupComponent {
6161
<% if(filters.ngroute) { %>this.Router.navigateByUrl('/home');<% } -%>
6262
<% if(filters.uirouter) { %>this.StateService.go('main');<% } -%>
6363
})
64-
.catch(err => {
65-
err = err.data;
66-
this.errors = {};<% if(filters.mongooseModels) { %>
64+
.catch(err => {<% if(filters.mongooseModels) { %>
65+
this.errors = err.errors;
66+
6767
// Update validity of form fields that match the mongoose errors
68-
err.errors.forEach((error, field) => {
68+
Object.entries(err.errors).forEach(([field, error]) => {
6969
this.errors[field] = error.message;
70+
71+
if(field === 'email' && error.kind === 'user defined') {
72+
form.form.controls[field].setErrors({inUse: true});
73+
}
7074
});<% } %><% if(filters.sequelizeModels) { %>
75+
this.errors = {};
76+
7177
// Update validity of form fields that match the sequelize errors
7278
if(err.name) {
7379
err.fields.forEach(field => {
7480
this.errors[field] = err.message;
7581
});
7682
}<% } %>
83+
84+
this.submitted = false;
7785
});
7886
}
7987
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<h1>Sign up</h1>
55
</div>
66
<div class="col-sm-12">
7-
<form class="form" name="form" (ngSubmit)="register(form)" novalidate #signupForm="ngForm">
7+
<form class="form" name="form" (ngSubmit)="register(signupForm)" novalidate #signupForm="ngForm">
88

99
<div class="form-group"
1010
[class.has-success]="name.valid && submitted"
@@ -26,11 +26,11 @@ <h1>Sign up</h1>
2626
required
2727
mongoose-error
2828
#email="ngModel">
29-
<p class="help-block" [hidden]="email.valid || (email.pristine && !signupForm.submitted)">
29+
<p class="help-block" [hidden]="email.valid || (email.pristine && !signupForm.submitted) || (email.errors ? email.errors.inUse : true)">
3030
Please enter a valid email address.
3131
</p>
32-
<p class="help-block" [hidden]="!errors.email">
33-
{{ errors.email }}
32+
<p class="help-block" [hidden]="email.errors ? !email.errors.inUse : true">
33+
This email address is already in use.
3434
</p>
3535
</div>
3636

Diff for: templates/app/client/app/admin(auth)/admin.module.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BrowserModule } from '@angular/platform-browser';<% if(filters.uirouter
33
import { UIRouterModule } from 'ui-router-ng2';<% } %><% if(filters.ngroute) { %>
44
import { RouterModule, Routes } from '@angular/router';<% } %>
55
import { AuthGuard } from '../../components/auth/auth-guard.service';
6+
import { AuthModule } from '../../components/auth/auth.module';
67
import { AdminComponent } from './admin.component';
78

89
<%_ if(filters.uirouter) { -%>
@@ -16,6 +17,7 @@ const adminRoutes: Routes = [{
1617

1718
@NgModule({
1819
imports: [
20+
AuthModule,
1921
BrowserModule,
2022
<%_ if(filters.ngroute) { _%>
2123
RouterModule.forChild(adminRoutes),<% } %>

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import { NgModule } from '@angular/core';
44
import { AuthService } from './auth.service';
55
import { UserService } from './user.service';
6+
import { AuthGuard } from '../../components/auth/auth-guard.service';
67

78
@NgModule({
89
providers: [
910
AuthService,
10-
UserService
11+
UserService,
12+
AuthGuard,
1113
]
1214
})
1315
export class AuthModule {}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ export class AuthService {
122122
})
123123
.catch(err => {
124124
this.logout();
125-
return safeCb(callback)(err);
125+
safeCb(callback)(err);
126+
return Promise.reject(err);
126127
});
127128
}
128129

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';
1+
// @flow
22
import { Injectable } from '@angular/core';
33
import { Response } from '@angular/http';
44
import { AuthHttp } from 'angular2-jwt';
@@ -7,7 +7,6 @@ import 'rxjs/add/operator/map';
77
import 'rxjs/add/operator/catch';
88
import 'rxjs/add/operator/toPromise';
99

10-
// @flow
1110
type UserType = {
1211
// TODO: use Mongoose model
1312
id?: string;
@@ -17,7 +16,7 @@ type UserType = {
1716
}
1817

1918
function handleError(err) {
20-
return Observable.throw(err.json().error || 'Server error');
19+
return Observable.throw(err.json() || 'Server error');
2120
}
2221

2322
@Injectable()

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { StateService } from 'ui-router-ng2';<% } %>
55
<%_ if (filters.ngroute) { -%>
66
import { Router } from '@angular/router';<% } %>
77
import { AuthService } from '../auth/auth.service';<% } %>
8+
import template from './navbar.html';
89

910
@Component({
1011
selector: 'navbar',
11-
template: require('./navbar.<%=templateExt%>')
12+
template,
1213
})
1314
export class NavbarComponent {
1415
isCollapsed = true;
@@ -53,9 +54,10 @@ export class NavbarComponent {
5354
}
5455

5556
logout() {
56-
let promise = this.AuthService.logout();<% if(filters.uirouter) { %>
57-
this.StateService.go('login');<% } %><% if(filters.ngroute) { %>
58-
this.Router.navigateByUrl('/home');<% } %>
59-
return promise;
57+
return this.AuthService.logout().then(() => {<% if(filters.uirouter) { %>
58+
this.StateService.go('login');<% } %><% if(filters.ngroute) { %>
59+
this.Router.navigateByUrl('/home');<% } %>
60+
this.reset();
61+
});
6062
}<% } -%>
6163
}

Diff for: templates/app/client/components/navbar/navbar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<li [hidden]="isLoggedIn" <% if(filters.uirouter) { %>uiSrefActive="active"<% } else { %>routerLinkActive="active"<% } %>><a <% if(filters.uirouter) { %>uiSref="login"<% } else { %>routerLink="/login"<% } %>>Login</a></li>
2727
<li [hidden]="!isLoggedIn"><p class="navbar-text">Hello {{ currentUser.name }}</p> </li>
2828
<li [hidden]="!isLoggedIn" <% if(filters.uirouter) { %>uiSrefActive="active"<% } else { %>routerLinkActive="active"<% } %>><a <% if(filters.uirouter) { %>uiSref="settings"<% } else { %>routerLink="/settings"<% } %>><span class="glyphicon glyphicon-cog"></span></a></li>
29-
<li [hidden]="!isLoggedIn"><a (click)="logout()">Logout</a></li>
29+
<li [hidden]="!isLoggedIn"><a (click)="logout()" style="cursor: pointer;">Log out</a></li>
3030
</ul><% } %>
3131
</div>
3232
</div>

0 commit comments

Comments
 (0)