From 959453c6d5f78d9e17480a876e03003d29600c16 Mon Sep 17 00:00:00 2001
From: Lukas Kimpel <lukas.kimpel@mni.thm.de>
Date: Wed, 21 Mar 2018 00:00:20 +0100
Subject: [PATCH] Implement flag whether a user is logged in as guest or not

---
 src/app/models/user.ts                          |  4 +++-
 src/app/services/http/authentication.service.ts | 10 ++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/app/models/user.ts b/src/app/models/user.ts
index e37a93bde..369934fdf 100644
--- a/src/app/models/user.ts
+++ b/src/app/models/user.ts
@@ -7,12 +7,14 @@ export class User {
   authProvider: AuthProvider;
   token: string;
   role: UserRole;
+  isGuest: boolean;
 
-  constructor(id: string, loginId: string, authProvider: AuthProvider, token: string, role: UserRole) {
+  constructor(id: string, loginId: string, authProvider: AuthProvider, token: string, role: UserRole, isGuest: boolean) {
     this.id = id;
     this.loginId = loginId;
     this.authProvider = authProvider;
     this.token = token;
     this.role = role;
+    this.isGuest = isGuest;
   }
 }
diff --git a/src/app/services/http/authentication.service.ts b/src/app/services/http/authentication.service.ts
index 3fce9041e..d3dbdd74e 100644
--- a/src/app/services/http/authentication.service.ts
+++ b/src/app/services/http/authentication.service.ts
@@ -40,13 +40,13 @@ export class AuthenticationService {
     return this.checkLogin(this.http.post<ClientAuthentication>(connectionUrl, {
       loginId: email,
       password: password
-    }, this.httpOptions), userRole);
+    }, this.httpOptions), userRole, false);
   }
 
   guestLogin(): Observable<boolean> {
     const connectionUrl: string = this.apiUrl.base + this.apiUrl.auth + this.apiUrl.login + this.apiUrl.guest;
 
-    return this.checkLogin(this.http.post<ClientAuthentication>(connectionUrl, null, this.httpOptions), UserRole.PARTICIPANT);
+    return this.checkLogin(this.http.post<ClientAuthentication>(connectionUrl, null, this.httpOptions), UserRole.PARTICIPANT, true);
   }
 
   register(email: string, password: string): Observable<boolean> {
@@ -98,14 +98,16 @@ export class AuthenticationService {
     return this.user.token;
   }
 
-  private checkLogin(clientAuthentication: Observable<ClientAuthentication>, userRole: UserRole): Observable<boolean> {
+  private checkLogin(clientAuthentication: Observable<ClientAuthentication>, userRole: UserRole, isGuest: boolean): Observable<boolean> {
     return clientAuthentication.map(result => {
       if (result) {
         this.setUser(new User(
           result.userId,
           result.loginId,
           result.authProvider,
-          result.token, userRole));
+          result.token,
+          userRole,
+          isGuest));
         return true;
       } else {
         return false;
-- 
GitLab