Skip to content

Commit ee41cef

Browse files
Code after end of Part 6
1 parent 9b2b23b commit ee41cef

12 files changed

+103
-20
lines changed

src/app/app.component.html

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
<main class="container">
33
<router-outlet></router-outlet>
44
</main>
5-

src/app/app.module.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { BrowserModule } from '@angular/platform-browser';
2+
import { FormsModule } from '@angular/forms';
23
import { NgModule } from '@angular/core';
34
import { RouterModule, Routes } from '@angular/router';
45

@@ -10,6 +11,8 @@ import { NavbarComponent } from './components/navbar/navbar.component';
1011
import { ProfileComponent } from './components/profile/profile.component';
1112
import { RegisterComponent } from './components/register/register.component';
1213

14+
import { ValidateService } from './services/validate.service';
15+
1316
const appRoutes: Routes = [
1417
{ path: '', component: HomeComponent },
1518
{ path: 'register', component: RegisterComponent },
@@ -30,9 +33,10 @@ const appRoutes: Routes = [
3033
],
3134
imports: [
3235
BrowserModule.withServerTransition({ appId: 'serverApp' }),
33-
RouterModule.forRoot(appRoutes)
36+
FormsModule,
37+
RouterModule.forRoot(appRoutes),
3438
],
35-
providers: [],
39+
providers: [ValidateService],
3640
bootstrap: [AppComponent]
3741
})
3842
export class AppModule { }
+24-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1-
<p>
2-
home works!
3-
</p>
1+
<div class="jumbotron text-center">
2+
<h1 class="display-3">MEAN Authentication App</h1>
3+
<p class="lead">Welcome to our custom MEAN authentication application built from scratch</p>
4+
<hr class="my-4">
5+
<div>
6+
<a href="" class="btn btn-primary" routerLink="/register">Register</a>
7+
<a href="" class="btn btn-primary" routerLink="/login">Login</a>
8+
</div>
9+
</div>
10+
11+
<div class="row">
12+
<div class="col-md-4">
13+
<h3>Express Backend</h3>
14+
<p>A rock solid Node.js/Express server using Mongoose to organize models and query the database.</p>
15+
</div>
16+
<div class="col-md-4">
17+
<h3>Angular CLI</h3>
18+
<p>Angular CLI to generate components, services, and more. Local dev server and easy and easy compilation</p>
19+
</div>
20+
<div class="col-md-4">
21+
<h3>JWT Tokens</h3>
22+
<p>Full featured authentication using JSON web tokens. Login and store user data.</p>
23+
</div>
24+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.active {
2+
background:#272825;
3+
}

src/app/components/navbar/navbar.component.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<a class="navbar-brand" routerLink="/">MEAN Auth App</a>
44
<div class="navbar-collapse">
55
<ul class="navbar-nav mr-auto">
6-
<li class="nav-item"><a class="btn" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }"routerLink="/">Home</a></li>
6+
<li><a class="btn" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }"routerLink="/">Home</a></li>
77
</ul>
88
<div class="form-inline">
9-
<li class="nav-item"><a class="btn" routerLinkActive="active" routerLink="/login">Login</a></li>
10-
<li class="nav-item"><a class="btn" routerLinkActive="active" routerLink="/register">Register</a></li>
9+
<li><a class="btn" routerLinkActive="active" routerLink="/login">Login</a></li>
10+
<li><a class="btn" routerLinkActive="active" routerLink="/register">Register</a></li>
1111
</div>
1212
</div>
1313
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.red {
2+
color: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
<p>
2-
register works!
3-
</p>
1+
<h2 class="page-header">Register</h2>
2+
<div class="alert alert-danger" *ngIf="noEmail" role="alert">{{ errMsg }}</div>
3+
<form #regForm="ngForm" (ngSubmit)="onRegisterSubmit(regForm)">
4+
<div class="form-group">
5+
<label for="name">Name <sup class="red">*</sup></label>
6+
<input required name="name" id="name" #name="ngModel" ngModel type="text" class="form-control" ></div>
7+
<div class="form-group">
8+
<label for="username">Username <sup class="red">*</sup></label>
9+
<input required name="username" id="username" #username="ngModel" ngModel type="text" class="form-control"></div>
10+
<div class="form-group">
11+
<label for="email">Email <sup class="red">*</sup></label>
12+
<input required name="email" id="email" #email="ngModel" ngModel type="email" class="form-control"></div>
13+
<div class="form-group">
14+
<label for="password">Password <sup class="red">*</sup></label>
15+
<input required name="password" id="password" #password="ngModel" ngModel type="password" class="form-control"></div>
16+
<input type="submit" class="btn btn-primary" value="Submit" [disabled]="!regForm.valid">
17+
</form>

src/app/components/register/register.component.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ValidateService } from '../../services/validate.service';
12
import { Component, OnInit } from '@angular/core';
23

34
@Component({
@@ -7,9 +8,23 @@ import { Component, OnInit } from '@angular/core';
78
})
89
export class RegisterComponent implements OnInit {
910

10-
constructor() { }
11+
noEmail = false;
12+
errMsg: string;
13+
14+
constructor(private validateService: ValidateService) { }
1115

1216
ngOnInit() {
1317
}
1418

19+
onRegisterSubmit(form) {
20+
21+
// Validate Email
22+
if (!this.validateService.validateEmail(form.value.email)) {
23+
this.noEmail = true;
24+
this.errMsg = 'Please use a valid email';
25+
return false;
26+
}
27+
28+
}
29+
1530
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { TestBed, inject } from '@angular/core/testing';
2+
3+
import { ValidateService } from './validate.service';
4+
5+
describe('ValidateService', () => {
6+
beforeEach(() => {
7+
TestBed.configureTestingModule({
8+
providers: [ValidateService]
9+
});
10+
});
11+
12+
it('should be created', inject([ValidateService], (service: ValidateService) => {
13+
expect(service).toBeTruthy();
14+
}));
15+
});

src/app/services/validate.service.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Injectable } from '@angular/core';
2+
3+
@Injectable()
4+
export class ValidateService {
5+
6+
constructor() { }
7+
8+
validateEmail(email) {
9+
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
10+
return re.test(email.toLowerCase());
11+
}
12+
13+
}

src/styles.css

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
/* You can add global styles to this file, and also import other style files */
2-
@import "assets/css/bootstrap.min.css";
3-
4-
.active {
5-
background:#272825;
6-
}
2+
@import "assets/css/bootstrap.min.css";

tslint.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
true,
1111
"check-space"
1212
],
13-
"curly": true,
13+
"curly": false,
1414
"deprecation": {
1515
"severity": "warn"
1616
},
@@ -30,7 +30,7 @@
3030
"label-position": true,
3131
"max-line-length": [
3232
true,
33-
140
33+
500
3434
],
3535
"member-access": false,
3636
"member-ordering": [

0 commit comments

Comments
 (0)