-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b39084a
commit 03d0e90
Showing
8 changed files
with
132 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
<div class="main"> | ||
<nav class="navbar navbar-expand-md navbar-dark bg-dark"> | ||
<a class="navbar-brand" href="#">U Business</a> | ||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample04" | ||
aria-controls="navbarsExample04" aria-expanded="false" aria-label="Toggle navigation"> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
<nav class="navbar navbar-expand-md navbar-dark bg-dark"> | ||
<a class="navbar-brand" href="#">U Business</a> | ||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample04" | ||
aria-controls="navbarsExample04" aria-expanded="false" aria-label="Toggle navigation"> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
|
||
<div class="collapse navbar-collapse" id="navbarsExample04"> | ||
<ul class="navbar-nav mr-auto"> | ||
<li class="nav-item active"> | ||
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="#">Sign In </a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="#">Create Account</a> | ||
</li> | ||
<div class="collapse navbar-collapse" id="navbarsExample04"> | ||
<ul class="navbar-nav mr-auto"> | ||
<li class="nav-item active"> | ||
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" [routerLink]="['/sign-in']">Log in</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" [routerLink]="['/user/sign-up']">Sign up</a> | ||
</li> | ||
|
||
</ul> | ||
<form class="form-inline my-2 my-md-0"> | ||
<input class="form-control" type="text" placeholder="Search"> | ||
</form> | ||
</div> | ||
</nav> | ||
|
||
<div class="jumbotron img-fluid"> | ||
<div class="header"> | ||
U Business | ||
<span>Connecting Businesses to Opportunity</span> | ||
</div> | ||
</ul> | ||
<form class="form-inline my-2 my-md-0"> | ||
<input class="form-control" type="text" placeholder="Search"> | ||
</form> | ||
</div> | ||
</nav> | ||
|
||
<div class="jumbotron img-fluid"> | ||
<div class="header"> | ||
U Business | ||
<span>Connecting Businesses to Opportunity</span> | ||
</div> | ||
|
||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { AuthGuardService } from './auth-guard.service'; | ||
|
||
describe('AuthGuardService', () => { | ||
let service: AuthGuardService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(AuthGuardService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Router, CanActivate } from '@angular/router'; | ||
import { AuthService } from './auth.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class AuthGuardService implements CanActivate{ | ||
|
||
constructor( | ||
public auth: AuthService, | ||
public router: Router | ||
) { } | ||
|
||
canActivate(): boolean { | ||
if (!this.auth.getToken()) { | ||
this.router.navigateByUrl('/sign-in'); | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { catchError } from 'rxjs/operators'; | ||
import { Injectable, Injector } from '@angular/core'; | ||
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpErrorResponse } from '@angular/common/http'; | ||
import { Router } from '@angular/router'; | ||
import { Observable, throwError } from 'rxjs'; | ||
import { AuthService } from './auth.service'; | ||
|
||
@Injectable() | ||
export class TokenInterceptor implements HttpInterceptor { | ||
private authService: AuthService; | ||
|
||
constructor(private injector: Injector) { } | ||
|
||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { | ||
this.authService = this.injector.get(AuthService); | ||
const token = this.authService.getToken(); | ||
request = request.clone({ | ||
setHeaders: { | ||
Authorization: `Bearer ${token}`, | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
return next.handle(request); | ||
} | ||
} | ||
|
||
@Injectable() | ||
export class ErrorInterceptor implements HttpInterceptor { | ||
constructor(private router: Router) {} | ||
|
||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { | ||
return next.handle(request).pipe( | ||
catchError(response => { | ||
if (response instanceof HttpErrorResponse && response.status === 401) {} | ||
return throwError(response); | ||
}) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters