Skip to content
Snippets Groups Projects
Verified Commit 959453c6 authored by Lukas Maximilian Kimpel's avatar Lukas Maximilian Kimpel
Browse files

Implement flag whether a user is logged in as guest or not

parent 7914d1d4
1 merge request!99Resolve "Differentiate between guests and registered users"
Pipeline #13771 passed with stage
in 33 seconds
...@@ -7,12 +7,14 @@ export class User { ...@@ -7,12 +7,14 @@ export class User {
authProvider: AuthProvider; authProvider: AuthProvider;
token: string; token: string;
role: UserRole; 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.id = id;
this.loginId = loginId; this.loginId = loginId;
this.authProvider = authProvider; this.authProvider = authProvider;
this.token = token; this.token = token;
this.role = role; this.role = role;
this.isGuest = isGuest;
} }
} }
...@@ -40,13 +40,13 @@ export class AuthenticationService { ...@@ -40,13 +40,13 @@ export class AuthenticationService {
return this.checkLogin(this.http.post<ClientAuthentication>(connectionUrl, { return this.checkLogin(this.http.post<ClientAuthentication>(connectionUrl, {
loginId: email, loginId: email,
password: password password: password
}, this.httpOptions), userRole); }, this.httpOptions), userRole, false);
} }
guestLogin(): Observable<boolean> { guestLogin(): Observable<boolean> {
const connectionUrl: string = this.apiUrl.base + this.apiUrl.auth + this.apiUrl.login + this.apiUrl.guest; 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> { register(email: string, password: string): Observable<boolean> {
...@@ -98,14 +98,16 @@ export class AuthenticationService { ...@@ -98,14 +98,16 @@ export class AuthenticationService {
return this.user.token; 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 => { return clientAuthentication.map(result => {
if (result) { if (result) {
this.setUser(new User( this.setUser(new User(
result.userId, result.userId,
result.loginId, result.loginId,
result.authProvider, result.authProvider,
result.token, userRole)); result.token,
userRole,
isGuest));
return true; return true;
} else { } else {
return false; return false;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment