Login and register

Logout is broken with merge
This commit is contained in:
Walter Jay 2019-06-04 16:37:09 +09:00
parent 7e7bc572d8
commit 10e37d437d
3 changed files with 40 additions and 34 deletions

View File

@ -19,17 +19,16 @@
</mat-menu>
<mat-menu #profileMenu="matMenu">
<button mat-menu-item>Login</button>
<button mat-menu-item>Create Account</button>
<button mat-menu-item>Logout</button>
<a routerLink="/register"><button mat-menu-item>Login</button></a>
<a routerLink="/register"><button mat-menu-item>Create Account</button></a>
<button mat-menu-item (click)="authService.logout()">Logout</button>
</mat-menu>
<mat-sidenav-content>
<header>
<div fxHide.lt-md="true" fxLayout="row" fxLayoutAlign="space-between" fxShow
id="header-container-desktop">
<div fxHide.lt-md="true" fxLayout="row" fxLayoutAlign="space-between" fxShow id="header-container-desktop">
<div class="title" fxFlex="200px">
<a routerLink="/">DiscoTrip</a>
@ -66,11 +65,9 @@
</div>
<div fxHide.gt-sm="true" fxLayout="row" fxLayoutAlign="space-between" fxShow
id="header-container-mobile">
<div fxHide.gt-sm="true" fxLayout="row" fxLayoutAlign="space-between" fxShow id="header-container-mobile">
<button (click)="drawer.toggle()" mat-flat-button
style="position: absolute;top: 0;left: 0;height: 60px;">
<button (click)="drawer.toggle()" mat-flat-button style="position: absolute;top: 0;left: 0;height: 60px;">
<mat-icon style="transform: scale(1.3)">menu</mat-icon>
</button>

View File

@ -25,11 +25,21 @@ export class AuthService {
})
}
async login(email: string, password: string) {
async register(email: string, password: string) {
try {
await this.afAuth.auth.createUserWithEmailAndPassword(email, password)
alert("Thank you: " + email + " for registering on DiscoTrip")
this.router.navigate(['/']);
} catch (e) {
alert("Error!" + e.message);
}
}
async login(email: string, password: string) {
try {
await this.afAuth.auth.signInWithEmailAndPassword(email, password)
this.router.navigate(['register/list']);
alert("User: " + email + " is connected")
this.router.navigate(['/']);
} catch (e) {
alert("Error!" + e.message);
}
@ -38,7 +48,7 @@ export class AuthService {
async logout(){
await this.afAuth.auth.signOut();
localStorage.removeItem('user');
this.router.navigate(['/register']);
alert("Thank you for using DiscoTrip, see you soon")
}
get isLoggedIn(): boolean {

View File

@ -1,23 +1,22 @@
<div class="container pt-3">
<div class="row justify-content-sm-center">
<div class="col-sm-10 col-md-6">
<div class="card border-info">
<div class="card-header">Login</div>
<div class="card-body">
<div class="row">
<div class="col-md-4 text-center">
<img src="https://placeimg.com/128/128/nature">
</div>
<div class="col-md-8">
<input type="text" class="form-control mb-2" placeholder="Email" #userEmail required autofocus>
<input type="password" class="form-control mb-2" placeholder="Password" #userPassword required>
<button class="btn btn-lg btn-primary btn-block mb-1" (click)="authService.login(userEmail.value, userPassword.value)">Login</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row justify-content-sm-center">
<div class="col-sm-10 col-md-6">
<div class="card border-info">
<div class="card-header">Login</div>
<div class="card-body">
<div class="row">
<div class="col-md-4 text-center">
<img src="https://placeimg.com/128/128/nature">
</div>
<div class="col-md-8">
<input type="text" class="form-control mb-2" placeholder="Email" #userEmail required autofocus>
<input type="password" class="form-control mb-2" placeholder="Password" #userPassword required>
<button class="btn btn-lg btn-primary btn-block mb-1" (click)="authService.login(userEmail.value, userPassword.value)">Login</button>
<button class="btn btn-lg btn-primary btn-block mb-1" (click)="authService.register(userEmail.value, userPassword.value)">Register</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>