From af3613d5cd57728368a9944080c85445267c1170 Mon Sep 17 00:00:00 2001
From: Lukas Kimpel <lukas.kimpel@mni.thm.de>
Date: Tue, 6 Mar 2018 15:58:01 +0100
Subject: [PATCH] Add error handling

---
 src/app/login/login.component.html |  2 ++
 src/app/login/login.component.ts   | 13 ++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html
index 39d0d9934..800da983d 100644
--- a/src/app/login/login.component.html
+++ b/src/app/login/login.component.html
@@ -1,9 +1,11 @@
 <mat-form-field class="input-block">
   <input matInput #userName placeholder="Username"/>
+  <mat-error *ngIf="usernameErrorMessage !== ''">{{ usernameErrorMessage }}</mat-error>
 </mat-form-field>
 
 <mat-form-field class="input-block">
   <input matInput #userPassword type="password" placeholder="Password"/>
+  <mat-error *ngIf="passwordErrorMessage !== ''">{{ passwordErrorMessage }}</mat-error>
 </mat-form-field>
 
 <button mat-raised-button color="primary" (click)="login(userName.value, userPassword.value)">Login</button>
diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts
index 89883adf2..3310c0e4b 100644
--- a/src/app/login/login.component.ts
+++ b/src/app/login/login.component.ts
@@ -10,7 +10,12 @@ import { NotificationService } from '../notification.service';
 })
 export class LoginComponent implements OnInit {
 
-  constructor(public authenticationService: AuthenticationService, public router: Router, public notificationService: NotificationService) {
+  protected usernameErrorMessage = '';
+  protected passwordErrorMessage = '';
+
+  constructor(public authenticationService: AuthenticationService,
+              public router: Router,
+              public notificationService: NotificationService) {
   }
 
   ngOnInit() {
@@ -20,9 +25,11 @@ export class LoginComponent implements OnInit {
     username = username.trim();
     password = password.trim();
 
-    if (username === '' || password === '') {
+    if (username === '') {
       // ToDo: Handle username and password not correct event
-      console.log(`Username or password empty`);
+      this.usernameErrorMessage = 'Username is required';
+    } else if (password === '') {
+      this.passwordErrorMessage = 'Password is required';
     } else {
       this.authenticationService.login(username, password).subscribe(loginSuccessful => {
         console.log(loginSuccessful);
-- 
GitLab