-
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.
Merge pull request #18 from BuildForSDG/feature-login
Feature login
- Loading branch information
Showing
26 changed files
with
531 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<div class="main"> | ||
<div id="left"> | ||
<div class="spacer"></div> | ||
<div class="signin"> | ||
<div class="user"> | ||
<h1>SME Connect</h1> | ||
<h2>Welcome User</h2> | ||
</div> | ||
<div *ngIf="errorMessage"> | ||
<div class="alert alert-danger" role="alert"> | ||
{{errorMessage}} | ||
</div> | ||
</div> | ||
<form [formGroup]="loginForm" (ngSubmit)="onLogin()" > | ||
<div class="form"> | ||
<label for="email">Email</label> | ||
<input type="text" id="email" name="email" class="control" formControlName="email"> | ||
<div *ngIf="login && f.email.errors" class="invalid-feedback"> | ||
<div *ngIf="f.email.errors.required">Email is required</div> | ||
<div *ngIf="f.email.errors.email">Email must be a valid email address</div> | ||
</div> | ||
</div> | ||
<div class="form"> | ||
<label for="Password">Password</label> | ||
<input type="password" id="Password" class="control" formControlName="password"> | ||
<div *ngIf="login && f.password.errors" class="invalid-feedback"> | ||
<div *ngIf="f.password.errors.required">Password is required</div> | ||
</div> | ||
</div> | ||
<button type="submit" id="login">Sign in</button> | ||
</form> | ||
<div> | ||
<a href="#">Forgot password?</a> | ||
</div> | ||
<div> | ||
<hr /> | ||
</div> | ||
<a href="#"> | ||
<span class="card card-small">Create an account</span> | ||
</a> | ||
</div> | ||
<footer id="footer"> | ||
Copyright © 2020 SME Connect LLC. All rights reserved. | ||
<div> | ||
<a href="#">Terms of Use</a> | | ||
<a href="#">Privacy Policy</a> | ||
</div> | ||
</footer> | ||
|
||
</div> | ||
<div id="right"> | ||
<div class="banner"><h1>Inspiring change for the <strong>better.</strong></h1> | ||
<h2>Your number one business partner. </h2></div> | ||
|
||
</div> | ||
</div> |
File renamed without changes.
File renamed without changes.
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,61 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | ||
import {Router} from '@angular/router'; | ||
import { Store } from '@ngrx/store'; | ||
import { UserState } from '../../store/state/user.state'; | ||
import { selectAuthState } from './../../store/state/user.state'; | ||
|
||
import { LogIn } from './../../store/actions/auth.actions'; | ||
import { User } from './../user/user.model'; | ||
import { Observable } from 'rxjs'; | ||
|
||
|
||
@Component({ | ||
selector: 'app-sign-in', | ||
templateUrl: './sign-in.component.html', | ||
styleUrls: ['./sign-in.component.scss'] | ||
}) | ||
export class SignInComponent implements OnInit { | ||
loginForm: FormGroup; | ||
login = false; | ||
getState: Observable<any>; | ||
errorMessage: string | null; | ||
|
||
|
||
|
||
constructor( | ||
private router: Router, | ||
private store: Store<UserState>, | ||
private formBuilder: FormBuilder | ||
) { | ||
this.getState = this.store.select(selectAuthState); | ||
} | ||
|
||
ngOnInit(): void { | ||
this.loginForm = this.formBuilder.group({ | ||
email: ['', [Validators.required, Validators.email]], | ||
password: ['', Validators.required] | ||
}); | ||
this.getState.subscribe(state => { | ||
this.errorMessage = state.errorMessage; | ||
}); | ||
} | ||
|
||
// convenient getter for easy access to form fields | ||
get f() { return this.loginForm.controls; } | ||
|
||
onLogin(): void { | ||
this.login = true; | ||
|
||
if (this.loginForm.invalid) { return; } | ||
const rawLogin = this.loginForm.getRawValue(); | ||
const payload = { | ||
email: rawLogin.email, | ||
password: rawLogin.password | ||
}; | ||
console.log('payload', payload); | ||
|
||
this.store.dispatch(new LogIn(payload)); | ||
} | ||
|
||
} |
6 changes: 5 additions & 1 deletion
6
src/app/components/smes-dashboard/smes-dashboard.component.html
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,4 +1,8 @@ | ||
<app-navbar></app-navbar> | ||
<div class="wrapper"> | ||
<app-side-nav></app-side-nav> | ||
<div *ngIf="isAuthenticated" > | ||
<app-side-nav></app-side-nav> | ||
</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
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; | ||
} | ||
} |
Oops, something went wrong.