Skip to content

Commit 99dfc5d

Browse files
signup ui connected with backend
1 parent 3ae72cd commit 99dfc5d

File tree

9 files changed

+110
-23
lines changed

9 files changed

+110
-23
lines changed

src/app/app-routing.module.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { RegisterComponent } from './register/register.component';
88

99

1010
const routes: Routes = [
11-
{ path: "login", component: LoginComponent },
12-
{ path: "register", component: RegisterComponent },
13-
{ path: "dashboard", component: DashboardComponent },
14-
{ path: "", component: HomeComponent },
15-
{ path: "app", component: AppComponent }
11+
{ path: "login", component: LoginComponent, pathMatch: "full" },
12+
{ path: "register", component: RegisterComponent, pathMatch: "full" },
13+
{ path: "dashboard", component: DashboardComponent, pathMatch: "full" },
14+
{ path: "", component: HomeComponent, pathMatch: "full" },
15+
{ path: "app", component: AppComponent, pathMatch: "full" }
1616
];
1717

1818
@NgModule({

src/app/app.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<li class="nav-item active">
1212
<a class="nav-link text-white" routerLink="login">Login / Signup <span class="sr-only">(current)</span></a>
1313
</li>
14+
<li class="nav-item">
15+
<a class="nav-link text-white" routerLink="register">Signup <span class="sr-only">(current)</span></a>
16+
</li>
1417
<!-- <li class="nav-item">
1518
<a class="nav-link" routerLink="course">Course</a>
1619
</li>

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { DashboardComponent } from './dashboard/dashboard.component';
2929
import { FooterComponent } from './footer/footer.component';
3030
import { HomeComponent } from './home/home.component';
3131
import { CardComponent } from './card/card.component';
32+
import { HttpClientModule } from '@angular/common/http';
3233

3334

3435
@NgModule({
@@ -57,6 +58,7 @@ import { CardComponent } from './card/card.component';
5758
FormsModule,
5859
MatExpansionModule,
5960
CdkAccordionModule,
61+
HttpClientModule
6062
// FlexLayoutModule
6163

6264
],

src/app/login/login.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<mat-tab-group mat-stretch-tabs class="example-stretched-tabs">
55
<mat-tab label="Login">
66
<mat-card-content>
7-
<form action="">
7+
<form>
88
<mat-form-field>
99
<input
1010
matInput
@@ -51,7 +51,7 @@
5151
class="login-button">
5252
Login with Google
5353
</button>
54-
<p class="login-button">Do not have account ! please <a routerLink="/register" >Register</a></p>
54+
<p class="login-button">Do not have account ! please <a routerLink="register" >Register</a></p>
5555
</form>
5656
</mat-card-content>
5757
</mat-tab>

src/app/register/register.component.html

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1-
<div class="login-page">
1+
<div class="container-fluid login-page">
22
<mat-card class="mat-elevation-z12">
33
<mat-card-title style="text-align:center;">Sign Up</mat-card-title>
44
<mat-tab-group mat-stretch-tabs class="example-stretched-tabs">
55
<mat-tab label="Sign Up">
66
<mat-card-content>
7-
<form action="">
7+
<form (ngSubmit)="registerNow()">
8+
<mat-form-field>
9+
<input
10+
matInput
11+
placeholder="Email"
12+
required
13+
name="email"
14+
[(ngModel)]="user.email"
15+
ngModel
16+
#email="ngModel">
17+
<mat-error *ngIf="email.invalid">Email is required</mat-error>
18+
<!-- <mat-icon matSuffix>email</mat-icon> -->
19+
</mat-form-field>
820
<mat-form-field>
921
<input
1022
matInput
1123
placeholder="User Name"
1224
required
13-
name="username"
25+
name="name"
26+
[(ngModel)]="user.name"
1427
ngModel
1528
#username="ngModel">
1629
<!-- <mat-icon matSuffix>perm_identity</mat-icon> -->
@@ -20,17 +33,7 @@
2033
</mat-error>
2134

2235
</mat-form-field>
23-
<mat-form-field>
24-
<input
25-
matInput
26-
placeholder="Email"
27-
required
28-
name="email"
29-
ngModel
30-
#email="ngModel">
31-
<mat-error *ngIf="email.invalid">Email is required</mat-error>
32-
<!-- <mat-icon matSuffix>email</mat-icon> -->
33-
</mat-form-field>
36+
3437
<mat-form-field>
3538
<input
3639
matInput
@@ -39,6 +42,7 @@
3942
required
4043
minlength="6"
4144
name="password"
45+
[(ngModel)]="user.password"
4246
ngModel
4347
#password="ngModel">
4448
<mat-error
@@ -71,9 +75,13 @@
7175
<button
7276
mat-raised-button
7377
color="primary"
74-
class="login-button">
78+
class="login-button"
79+
type="submit"
80+
>
81+
7582
Sign Up
7683
</button>
84+
<!-- <p>{{user | json }}</p> -->
7785
</form>
7886
</mat-card-content>
7987
</mat-tab>
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { UserServiceService } from '../user-service.service';
3+
import { User } from '../user';
24
@Component({
35
selector: 'app-register',
46
templateUrl: './register.component.html',
57
styleUrls: ['./register.component.css']
68
})
79
export class RegisterComponent implements OnInit {
810

9-
constructor() { }
11+
// u = {
12+
// email: "",
13+
// name: "",
14+
// password: ""
15+
// }
16+
user = new User("", "", "");
17+
18+
// m: any
19+
20+
21+
constructor(private service: UserServiceService) {
22+
23+
}
1024
ngOnInit(): void {
1125
}
1226

27+
public registerNow() {
28+
console.log(this.user);
29+
30+
this.service.doRegistration(this.user).subscribe(
31+
data => console.log("Response Received", data),
32+
error => console.log("Exception Occured")
33+
)
34+
35+
36+
37+
}
38+
1339
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { UserServiceService } from './user-service.service';
4+
5+
describe('UserServiceService', () => {
6+
let service: UserServiceService;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
service = TestBed.inject(UserServiceService);
11+
});
12+
13+
it('should be created', () => {
14+
expect(service).toBeTruthy();
15+
});
16+
});

src/app/user-service.service.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Injectable } from '@angular/core';
2+
import { HttpClient } from '@angular/common/http';
3+
import { User } from './user';
4+
import { Observable } from 'rxjs';
5+
6+
@Injectable({
7+
providedIn: 'root'
8+
})
9+
export class UserServiceService {
10+
11+
constructor(private http: HttpClient) { }
12+
public doRegistration(user: User): Observable<any> {
13+
return this.http.post<any>("https://global-rest-api.herokuapp.com/userAuth/register", user);
14+
}
15+
16+
}

src/app/user.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export class User {
2+
email: string;
3+
name: string;
4+
password: string;
5+
constructor(
6+
email: string,
7+
name: string,
8+
password: string
9+
) {
10+
this.email = email,
11+
this.name = name,
12+
this.password = password
13+
14+
15+
}
16+
}

0 commit comments

Comments
 (0)