Start adding Login and Register Components
This commit is contained in:
parent
762066f13d
commit
d58070c5ba
20
client/src/app/account/account-routing.module.ts
Normal file
20
client/src/app/account/account-routing.module.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { LoginComponent } from './login/login.component';
|
||||||
|
import { RegisterComponent } from './register/register.component';
|
||||||
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
|
|
||||||
|
const routes: Routes = [
|
||||||
|
{path: 'login', component: LoginComponent},
|
||||||
|
{path: 'register', component: RegisterComponent}
|
||||||
|
];
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [],
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
RouterModule.forChild(routes)
|
||||||
|
],
|
||||||
|
exports: [RouterModule]
|
||||||
|
})
|
||||||
|
export class AccountRoutingModule { }
|
19
client/src/app/account/account.module.ts
Normal file
19
client/src/app/account/account.module.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { LoginComponent } from './login/login.component';
|
||||||
|
import { RegisterComponent } from './register/register.component';
|
||||||
|
import { AccountRoutingModule } from './account-routing.module';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [
|
||||||
|
LoginComponent,
|
||||||
|
RegisterComponent
|
||||||
|
],
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
AccountRoutingModule
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class AccountModule { }
|
48
client/src/app/account/account.service.ts
Normal file
48
client/src/app/account/account.service.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { BehaviorSubject, map } from 'rxjs';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
import { IUser } from '../shared/models/user';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class AccoutService {
|
||||||
|
baseUrl = environment.apiUrl;
|
||||||
|
private currentUserSource = new BehaviorSubject<IUser>(null);
|
||||||
|
currentUser$ = this.currentUserSource.asObservable();
|
||||||
|
|
||||||
|
constructor(private http: HttpClient, private router: Router) { }
|
||||||
|
|
||||||
|
login(values: any){
|
||||||
|
return this.http.post(this.baseUrl + 'account/login', values).pipe(
|
||||||
|
map((user: IUser) =>{
|
||||||
|
if(user) {
|
||||||
|
localStorage.setItem('token', user.token);
|
||||||
|
this.currentUserSource.next(user);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
register(values: any){
|
||||||
|
return this.http.post(this.baseUrl + 'account/register', values).pipe(
|
||||||
|
map((user:IUser) => {
|
||||||
|
if(user){
|
||||||
|
localStorage.setItem('token', user.token);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
logout(){
|
||||||
|
localStorage.removeItem('token');
|
||||||
|
this.currentUserSource.next(null);
|
||||||
|
this.router.navigateByUrl('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
checkEmailExists(email: string){
|
||||||
|
return this.http.get(this.baseUrl + '/account/emailexists?email=' + email);
|
||||||
|
}
|
||||||
|
}
|
17
client/src/app/account/login/login.component.html
Normal file
17
client/src/app/account/login/login.component.html
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<div class="d-flex justify-content-center mt-5">
|
||||||
|
<div class="col-3">
|
||||||
|
<form>
|
||||||
|
<h1 class="h3 mb-3 fw-normal text-center">Login</h1>
|
||||||
|
|
||||||
|
<div class="form-floating mb-2">
|
||||||
|
<input type="email" class="form-control" id="floatingInput" placeholder="name@example.com">
|
||||||
|
<label for="floatingInput">Email address</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating mb-2">
|
||||||
|
<input type="password" class="form-control" id="floatingPassword" placeholder="Password">
|
||||||
|
<label for="floatingPassword">Password</label>
|
||||||
|
</div>
|
||||||
|
<button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
0
client/src/app/account/login/login.component.scss
Normal file
0
client/src/app/account/login/login.component.scss
Normal file
15
client/src/app/account/login/login.component.ts
Normal file
15
client/src/app/account/login/login.component.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-login',
|
||||||
|
templateUrl: './login.component.html',
|
||||||
|
styleUrls: ['./login.component.scss']
|
||||||
|
})
|
||||||
|
export class LoginComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1
client/src/app/account/register/register.component.html
Normal file
1
client/src/app/account/register/register.component.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<p>register works!</p>
|
15
client/src/app/account/register/register.component.ts
Normal file
15
client/src/app/account/register/register.component.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-register',
|
||||||
|
templateUrl: './register.component.html',
|
||||||
|
styleUrls: ['./register.component.scss']
|
||||||
|
})
|
||||||
|
export class RegisterComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,6 +13,7 @@ const routes: Routes = [
|
|||||||
{path: 'shop', loadChildren: ()=> import('./shop/shop.module').then(mod => mod.ShopModule), data: {breadcrumb: 'Shop'}},
|
{path: 'shop', loadChildren: ()=> import('./shop/shop.module').then(mod => mod.ShopModule), data: {breadcrumb: 'Shop'}},
|
||||||
{path: 'basket', loadChildren: ()=> import('./basket/basket.module').then(mod => mod.BasketModule), data: {breadcrumb: 'Shopping Cart'}},
|
{path: 'basket', loadChildren: ()=> import('./basket/basket.module').then(mod => mod.BasketModule), data: {breadcrumb: 'Shopping Cart'}},
|
||||||
{path: 'checkout', loadChildren: ()=> import('./checkout/checkout.module').then(mod => mod.CheckoutModule), data: {breadcrumb: 'Checkout'}},
|
{path: 'checkout', loadChildren: ()=> import('./checkout/checkout.module').then(mod => mod.CheckoutModule), data: {breadcrumb: 'Checkout'}},
|
||||||
|
{path: 'account', loadChildren: ()=> import('./account/account.module').then(mod => mod.AccountModule), data: {breadcrumb: {skip: true}}},
|
||||||
{path: '**', redirectTo: 'not-found', pathMatch: 'full'}
|
{path: '**', redirectTo: 'not-found', pathMatch: 'full'}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
<i class="fa fa-shopping-cart fa-2x me-3 text-dark"></i>
|
<i class="fa fa-shopping-cart fa-2x me-3 text-dark"></i>
|
||||||
<div *ngIf="(basket$ | async) as basket" class="cart-no">{{basket.items.length}}</div>
|
<div *ngIf="(basket$ | async) as basket" class="cart-no">{{basket.items.length}}</div>
|
||||||
</a>
|
</a>
|
||||||
<a class="btn btn-outline-secondary me-3" href="#">Login</a>
|
<a routerLink="/account/login" class="btn btn-outline-secondary me-3" href="#">Login</a>
|
||||||
<a class="btn btn-outline-secondary me-3" href="#">Sign up</a>
|
<a routerLink="/account/register" class="btn btn-outline-secondary me-3" href="#">Sign up</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
8
client/src/app/shared/models/address.ts
Normal file
8
client/src/app/shared/models/address.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export interface IAddress {
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
street: string;
|
||||||
|
city: string;
|
||||||
|
state: string;
|
||||||
|
zipCode: string;
|
||||||
|
}
|
5
client/src/app/shared/models/user.ts
Normal file
5
client/src/app/shared/models/user.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export interface IUser {
|
||||||
|
email: string;
|
||||||
|
displayName: string;
|
||||||
|
token: string;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user