Skip to content

Commit

Permalink
feat: fake logout support
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit committed Oct 18, 2024
1 parent 7c2a379 commit 3456ce6
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 21 deletions.
2 changes: 1 addition & 1 deletion authority-portal-frontend/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*ngIf="appConfig.useFakeBackend"
class="absolute t-[5px] w-full flex flex-row justify-end"
style="z-index: 9999">
<app-fake-backend-user-switcher></app-fake-backend-user-switcher>
<!-- <app-fake-backend-user-switcher></app-fake-backend-user-switcher> -->
</div>
<app-e2e-dev-user-switcher
*ngIf="appConfig.useLocalBackend"></app-e2e-dev-user-switcher>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,18 @@ export const updateLoggedInUser = (patcher: Patcher<UserInfo>) => {
currentlyLoggedInUser = patchObj<UserInfo>(currentlyLoggedInUser, patcher);
};

export const fakeLogin = () => {
currentlyLoggedInUser = buildUserInfo(
ALL_USERS['00000000-0000-0000-0000-000000000001'],
);
export const fakeLogin = (userId?: string) => {
if (userId && Object.keys(ALL_USERS).includes(userId)) {
currentlyLoggedInUser = buildUserInfo(ALL_USERS[userId]);
} else {
currentlyLoggedInUser = buildUserInfo(
ALL_USERS['00000000-0000-0000-0000-000000000001'],
);
}
};

export const fakeLogout = () => {
currentlyLoggedInUser = buildUnauthenticatedUserInfo();
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,36 @@
</p>
<div class="flex items-center flex-col gap-2">
<a
*ngIf="!this.appConfig.useFakeBackend"
id="btn-login"
class="w-[300px] bg-black hover:bg-black text-white font-bold py-2 px-4 rounded active:scale-[0.99]"
(click)="login()">
(click)="login('')">
Log In
</a>
<a
id="btn-register-organization"
class="w-[300px] bg-white text-black border border-gray-700 font-bold py-2 px-4 rounded active:scale-[0.99]"
routerLink="/create-organization">
Register Organization
</a>
<div *ngIf="this.appConfig.useFakeBackend">
Login as
<br />
<br />
<select
class="w-[300px] bg-white text-black border border-gray-700 font-bold py-2 px-4 rounded active:scale-[0.99]"
(change)="login($event)">
<option
*ngFor="let user of fakeBackendUserIds"
[value]="fakeBackendUsers[user]['userId']">
{{ fakeBackendUsers[user]['firstName'] }}
{{ fakeBackendUsers[user]['lastName'] }}
</option>
</select>
<a
id="btn-register-organization"
class="w-[300px] bg-white text-black border border-gray-700 font-bold py-2 px-4 rounded active:scale-[0.99]"
routerLink="/create-organization">
Register Organization
</a>
</div>
</div>
</div>

<!-- footer -->
<app-footer-for-full-page></app-footer-for-full-page>
<!-- footer -->
<app-footer-for-full-page></app-footer-for-full-page>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,25 @@
*/
import {Component, Inject} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {fakeLogin} from 'src/app/core/api/fake-backend/impl/fake-users';
import {Store} from '@ngxs/store';
import {
ALL_USERS,
fakeLogin,
} from 'src/app/core/api/fake-backend/impl/fake-users';
import {RefreshUserInfo} from 'src/app/core/global-state/global-state-actions';
import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';

@Component({
selector: 'app-unauthenticated-page',
templateUrl: './unauthenticated-page.component.html',
})
export class UnauthenticatedPageComponent {
fakeBackendUserIds = Object.keys(ALL_USERS);
fakeBackendUsers = ALL_USERS;

constructor(
@Inject(APP_CONFIG) public appConfig: AppConfig,
public store: Store,
private titleService: Title,
) {
this.titleService.setTitle('Unauthenticated');
Expand All @@ -33,9 +42,9 @@ export class UnauthenticatedPageComponent {
return url.toString();
}

login() {
login(event: any): void {
if (this.appConfig.useFakeBackend) {
fakeLogin();
fakeLogin(event.target.value);
} else {
location.href = this.loginUrl;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<a
*ngIf="!this.appConfig.useFakeBackend"
class="py-2 px-4 rounded-md bg-white text-black border-gray-700 border font-bold flex items-center gap-1 text-sm active:scale-[0.99]"
[href]="appConfig.logoutUrl">
(click)="logout()">
<mat-icon class="!text-[18px] !w-[18px] !h-[18px]">logout</mat-icon>Log Out
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* sovity GmbH - initial implementation
*/
import {Component, Inject} from '@angular/core';
import {fakeLogout} from 'src/app/core/api/fake-backend/impl/fake-users';
import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';

@Component({
Expand All @@ -19,4 +20,12 @@ import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';
})
export class LogoutButtonComponent {
constructor(@Inject(APP_CONFIG) public appConfig: AppConfig) {}

logout() {
if (this.appConfig.useFakeBackend) {
fakeLogout();
} else {
location.href = this.appConfig.logoutUrl;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<div>
<a
class="flex gap-2 justify-start items-center p-2 hover:text-brand-highlight"
[href]="logoutUrl">
(click)="logout()">
<mat-icon svgIcon="arrow-left-on-rectangle"></mat-icon>
<span>Logout</span>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
* Contributors:
* sovity GmbH - initial implementation
*/
import {Component, Input, OnChanges} from '@angular/core';
import {Component, Inject, Input, OnChanges} from '@angular/core';
import {fakeLogout} from 'src/app/core/api/fake-backend/impl/fake-users';
import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';
import {AvatarConfig} from '../avatar/avatar.component';
import {ControlCenterModel} from './control-center.model';

Expand All @@ -25,10 +27,20 @@ export class ControlCenterComponent implements OnChanges {
userAvatar!: AvatarConfig;
userMenuOpen = false;

constructor(@Inject(APP_CONFIG) public appConfig: AppConfig) {}

ngOnChanges(): void {
this.userAvatar = {
firstName: this.userData.firstName,
lastName: this.userData.lastName,
};
}

logout(): void {
if (this.appConfig.useFakeBackend) {
fakeLogout();
} else {
location.href = this.logoutUrl;
}
}
}

0 comments on commit 3456ce6

Please sign in to comment.