diff --git a/src/app/authentication.guard.ts b/src/app/authentication.guard.ts index 9009340b11f5390f31ed08fdc09378b463a2fd54..4e4f004072101b72a224b54a4236be5b33d5202d 100644 --- a/src/app/authentication.guard.ts +++ b/src/app/authentication.guard.ts @@ -25,7 +25,7 @@ export class AuthenticationGuard implements CanActivate { // Allow access when user is logged in AND // the route doesn't require a specific role OR // the user's role is one of the required roles - if (user && (!requiredRoles || requiredRoles.includes(user.userRole))) { + if (user && (!requiredRoles || requiredRoles.includes(user.role))) { return true; } diff --git a/src/app/authentication.interceptor.ts b/src/app/authentication.interceptor.ts index 98b085c4e707d897c6b32d2cb3f06816f5406067..071cba6ae663016ab49bd4fcf16ead90792b2df7 100644 --- a/src/app/authentication.interceptor.ts +++ b/src/app/authentication.interceptor.ts @@ -8,8 +8,6 @@ import { Observable } from 'rxjs/Observable'; const AUTH_HEADER_KEY = 'Arsnova-Auth-Token'; -const AUTH_HEADER_KEY = 'Arsnova-Auth-Token'; - @Injectable() export class AuthenticationInterceptor implements HttpInterceptor { diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index f4156f3e1de6acb4b402619f60589361e1c308cc..cc6bcb187d7af8b45ff9b3eef16a616ba879422b 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -45,7 +45,7 @@ export class LoginComponent implements OnInit { if (!this.usernameFormControl.hasError('required') && !this.usernameFormControl.hasError('email') && !this.passwordFormControl.hasError('required')) { - this.authenticationService.login(username, password).subscribe(loginSuccessful => this.checkLogin(loginSuccessful)); + this.authenticationService.login(username, password, this.role).subscribe(loginSuccessful => this.checkLogin(loginSuccessful)); } else { this.notificationService.show('Please fit the requirements shown above.'); } @@ -55,15 +55,8 @@ export class LoginComponent implements OnInit { this.authenticationService.guestLogin().subscribe(loginSuccessful => this.checkLogin(loginSuccessful)); } - private checkLogin(loginSuccessful: ClientAuthentication) { + private checkLogin(loginSuccessful: boolean) { if (loginSuccessful) { - const user: User = new User( - loginSuccessful.userId, - loginSuccessful.loginId, - loginSuccessful.authProvider, - loginSuccessful.token, - this.role); - this.authenticationService.setUser(user); this.notificationService.show('Login successful!'); if (this.role === UserRole.CREATOR) { this.router.navigate(['creator']); diff --git a/src/app/room-list/room-list.component.html b/src/app/room-list/room-list.component.html index 869db2914fe77f900b27bbe3ab66a64009ec082d..2513764e9b0fdc1734b5ee7dd2161989ddaec001 100644 --- a/src/app/room-list/room-list.component.html +++ b/src/app/room-list/room-list.component.html @@ -4,7 +4,7 @@ </div> <mat-expansion-panel *ngFor="let room of rooms"> <mat-expansion-panel-header> - <button mat-button color="primary" routerLink="/{{ baseUrl }}/room/{{ room.id }}"> + <button mat-button color="primary" routerLink="/{{ baseUrl }}/room/{{ room.shortId }}"> <mat-icon>send</mat-icon> </button> <mat-panel-title> diff --git a/src/app/room-list/room-list.component.ts b/src/app/room-list/room-list.component.ts index 9e0dd6e4a902818b2804f661f87468b0f268cce7..0181fad400b18eca38bea1a3a4363591860a5a4f 100644 --- a/src/app/room-list/room-list.component.ts +++ b/src/app/room-list/room-list.component.ts @@ -34,10 +34,18 @@ export class RoomListComponent implements OnInit { } getRooms(): void { - this.roomService.getRooms().subscribe(rooms => { - this.rooms = rooms; - this.closedRooms = this.rooms.filter(room => room.closed); - this.isLoading = false; - }); + if (this.authenticationService.getRole() === UserRole.CREATOR) { + this.roomService.getCreatorRooms().subscribe(rooms => { + this.rooms = rooms; + this.closedRooms = this.rooms.filter(room => room.closed); + this.isLoading = false; + }); + } else if (this.authenticationService.getRole() === UserRole.PARTICIPANT) { + this.roomService.getParticipantRooms().subscribe(rooms => { + this.rooms = rooms; + this.closedRooms = this.rooms.filter(room => room.closed); + this.isLoading = false; + }); + } } } diff --git a/src/app/room.service.ts b/src/app/room.service.ts index 31582ab76352ba432742a4ca877c7d8424d9c4ae..45a09f718dd96590c3827c90b4bc75ae383a9a2e 100644 --- a/src/app/room.service.ts +++ b/src/app/room.service.ts @@ -26,7 +26,7 @@ export class RoomService extends ErrorHandlingService { getCreatorRooms(): Observable<Room[]> { const url = this.apiBaseUrl + this.roomsUrl + this.findRoomsUrl; return this.http.post<Room[]>(url, { - properties: { ownerId: this.authService.getUser().userId }, + properties: { ownerId: this.authService.getUser().id }, externalFilters: {} }).pipe( tap(_ => ''), @@ -38,9 +38,9 @@ export class RoomService extends ErrorHandlingService { const url = this.apiBaseUrl + this.roomsUrl + this.findRoomsUrl; return this.http.post<Room[]>(url, { properties: {}, - externalFilters: { inHistoryOfUserId: this.authService.getUser().userId } + externalFilters: { inHistoryOfUserId: this.authService.getUser().id } }).pipe( - tap(_ => ''), + tap(() => ''), catchError(this.handleError('getRooms', [])) ); } @@ -48,7 +48,7 @@ export class RoomService extends ErrorHandlingService { addRoom(room: Room): Observable<Room> { const connectionUrl = this.apiBaseUrl + this.roomsUrl + '/'; return this.http.post<Room>(connectionUrl, { - ownerId: this.authService.getUser().userId, + ownerId: this.authService.getUser().id, abbreviation: room.abbreviation, name: room.name, closed: room.closed, description: room.description }, httpOptions); } @@ -61,7 +61,7 @@ export class RoomService extends ErrorHandlingService { } addToHistory(roomId: string): void { - const connectionUrl = `${ this.apiBaseUrl }${ this.userUrl }/${this.authService.getUser().userId}/roomHistory`; + const connectionUrl = `${ this.apiBaseUrl }${ this.userUrl }/${this.authService.getUser().id}/roomHistory`; this.http.post(connectionUrl, { roomId: roomId, lastVisit: this.joinDate.getTime() }, httpOptions).subscribe(r => console.log(r)); } @@ -75,10 +75,10 @@ export class RoomService extends ErrorHandlingService { updateRoom(room: Room): Observable<Room> { const connectionUrl = `${this.apiBaseUrl}${this.roomsUrl}/~${room.shortId}`; return this.http.put(connectionUrl, { - ownerId: this.authService.getUser().userId, + ownerId: this.authService.getUser().id, abbreviation: room.abbreviation, name: room.name, description: room.description }, httpOptions).pipe( - tap(_ => ''), + tap(() => ''), catchError(this.handleError<any>('updateRoom')) ); } @@ -86,7 +86,7 @@ export class RoomService extends ErrorHandlingService { deleteRoom(room: Room): Observable<Room> { const connectionUrl = `${this.apiBaseUrl}${this.roomsUrl}/${room.id}`; return this.http.delete<Room>(connectionUrl, httpOptions).pipe( - tap(_ => ''), + tap(() => ''), catchError(this.handleError<Room>('deleteRoom')) ); }