[frontend] Finish login design

This commit is contained in:
Cathy Hu 2020-08-27 11:52:43 +02:00
parent f497b52d83
commit 99a74ba927
5 changed files with 108 additions and 52 deletions

View file

@ -1,47 +1,49 @@
<div *ngIf="error" class="error">{{ error }}</div> <div class="container">
<div *ngIf="info" class="success">{{ info }}</div> <mat-card class="login-form">
<h2>Login</h2> <mat-card-header>
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()"> <h2>Log in as hood admin!</h2>
<div class="form-group"> </mat-card-header>
<label for="email">E-Mail</label> <mat-card-content>
<input <form [formGroup]="loginForm" (ngSubmit)="onSubmit()">
type="text" <div class="input-container">
formControlName="email" <mat-form-field appearance="fill">
class="form-control" <mat-label>E-Mail</mat-label>
[ngClass]="{ 'is-invalid': submitted && loginForm.controls.email.errors }" <input type="text" formControlName="email" matInput />
/> <mat-error
<div *ngIf="
*ngIf="submitted && loginForm.controls.email.errors" loginForm.controls.email.errors &&
class="invalid-feedback" loginForm.controls.email.errors.required
> "
<div *ngIf="loginForm.controls.email.errors.required"> >
Email is required Email is required
</div> </mat-error>
</div> </mat-form-field>
</div> <mat-form-field appearance="fill">
<div class="form-group"> <mat-label>Password</mat-label>
<label for="password">Password</label> <input
<input type="password"
type="password" formControlName="password"
formControlName="password" matInput
class="form-control" [type]="'password'"
[ngClass]="{ />
'is-invalid': submitted && loginForm.controls.password.errors <mat-error
}" *ngIf="
/> loginForm.controls.password.errors &&
<div loginForm.controls.password.errors.required
*ngIf="submitted && loginForm.controls.password.errors" "
class="invalid-feedback" >
> Password is required
<div *ngIf="loginForm.controls.password.errors.required"> </mat-error>
Password is required </mat-form-field>
</div> </div>
</div> <div class="buttons">
</div> <button mat-raised-button color="primary" [disabled]="loading">
<div class="form-group"> Log In
<button [disabled]="loading" class="btn btn-primary"> </button>
Login <a mat-button routerLink="/register">Register</a>
</button> </div>
<a routerLink="/register">Register</a> </form>
</div> </mat-card-content>
</form> </mat-card>
<div class="banner"></div>
</div>

View file

@ -0,0 +1,43 @@
.input-container {
display: grid;
grid-template-rows: 1fr 1fr;
margin-left: 5%;
margin-right: 5%;
margin-bottom: 5%;
margin-top: 3%;
}
.mat-card:not([class*="mat-elevation-z"]) {
box-shadow: none;
}
.container {
display: grid;
grid-template-columns: 1fr 1fr;
margin-left: 10%;
margin-right: 10%;
margin-top: 5%;
@media (max-width: 600px) {
grid-template-columns: 1fr;
margin-top: 10%;
margin-left: 5%;
margin-right: 5%;
}
}
.banner {
background: url("../../../assets/hoods1.jpg");
background-size: 100%;
display: block;
width: 100%;
height: 100%;
}
.buttons {
margin-left: 20px;
}
.login-form {
margin-top: 10%;
margin-bottom: 10%;
}

View file

@ -3,6 +3,7 @@ import { LoginService } from '../../core/auth/login.service';
import { Router, ActivatedRoute } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { Validators, FormGroup, FormBuilder } from '@angular/forms'; import { Validators, FormGroup, FormBuilder } from '@angular/forms';
import { first } from 'rxjs/operators'; import { first } from 'rxjs/operators';
import { MatSnackBar } from '@angular/material/snack-bar';
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
@ -12,16 +13,16 @@ import { first } from 'rxjs/operators';
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
loginForm: FormGroup; loginForm: FormGroup;
returnUrl: string; returnUrl: string;
error: string;
loading = false; loading = false;
submitted = false; submitted = false;
info: string; hide = true;
constructor( constructor(
private loginService: LoginService, private loginService: LoginService,
private router: Router, private router: Router,
private route: ActivatedRoute, private route: ActivatedRoute,
private formBuilder: FormBuilder private formBuilder: FormBuilder,
private snackBar: MatSnackBar
) { ) {
if (this.loginService.currentHoodAdminValue) { if (this.loginService.currentHoodAdminValue) {
this.router.navigate(['/dashboard']); this.router.navigate(['/dashboard']);
@ -37,7 +38,9 @@ export class LoginComponent implements OnInit {
this.route.snapshot.queryParams['returnUrl'] || '/dashboard'; this.route.snapshot.queryParams['returnUrl'] || '/dashboard';
if (this.route.snapshot.queryParams['registered'] === true) { if (this.route.snapshot.queryParams['registered'] === true) {
this.info = 'Registration successful'; this.snackBar.open('Registration successful', 'Close', {
duration: 2000,
});
} }
} }
@ -59,7 +62,9 @@ export class LoginComponent implements OnInit {
this.router.navigate([this.returnUrl]); this.router.navigate([this.returnUrl]);
}, },
(error) => { (error) => {
this.error = 'Wrong credentials! Try again.'; this.snackBar.open('Wrong credentials! Try again.', 'Close', {
duration: 2000,
});
this.loading = false; this.loading = false;
} }
); );

View file

@ -8,6 +8,8 @@ import { MatCardModule } from '@angular/material/card';
import { MatExpansionModule } from '@angular/material/expansion'; import { MatExpansionModule } from '@angular/material/expansion';
import { MatListModule } from '@angular/material/list'; import { MatListModule } from '@angular/material/list';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { MatDialogModule } from '@angular/material/dialog';
import { MatSnackBarModule } from '@angular/material/snack-bar';
@NgModule({ @NgModule({
declarations: [], declarations: [],
@ -21,6 +23,8 @@ import { MatInputModule } from '@angular/material/input';
MatExpansionModule, MatExpansionModule,
MatListModule, MatListModule,
MatInputModule, MatInputModule,
MatDialogModule,
MatSnackBarModule,
], ],
exports: [ exports: [
MatButtonModule, MatButtonModule,
@ -32,6 +36,8 @@ import { MatInputModule } from '@angular/material/input';
MatExpansionModule, MatExpansionModule,
MatListModule, MatListModule,
MatInputModule, MatInputModule,
MatDialogModule,
MatSnackBarModule,
], ],
}) })
export class MaterialModule {} export class MaterialModule {}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 MiB