Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidy up app #1194

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ui/src/app/account/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
private eventService: EventService,
private ngZone: NgZone
) {
this.sub = this.eventService.on(EventType.LOG_IN_SUCCESS).subscribe((e) => {

Check warning on line 40 in ui/src/app/account/login/login.component.ts

View workflow job for this annotation

GitHub Actions / format

'e' is defined but never used
console.log('login success')
})
}
Expand Down Expand Up @@ -72,8 +72,8 @@

this.loginService
.login({
username: this.loginForm.get('username')!.value!,

Check warning on line 75 in ui/src/app/account/login/login.component.ts

View workflow job for this annotation

GitHub Actions / format

Forbidden non-null assertion

Check warning on line 75 in ui/src/app/account/login/login.component.ts

View workflow job for this annotation

GitHub Actions / format

Forbidden non-null assertion
password: this.loginForm.get('password')!.value!,

Check warning on line 76 in ui/src/app/account/login/login.component.ts

View workflow job for this annotation

GitHub Actions / format

Forbidden non-null assertion

Check warning on line 76 in ui/src/app/account/login/login.component.ts

View workflow job for this annotation

GitHub Actions / format

Forbidden non-null assertion
mfaCode: this.loginForm.get('mfaCode')?.value,
})
.subscribe({
Expand All @@ -95,8 +95,7 @@
}
this.mfaSent = false
},
// TODO: review any type
error: (err) => {
error: () => {
this.loginService.logout()
this.authenticationError = true
},
Expand Down
35 changes: 15 additions & 20 deletions ui/src/app/account/service/account.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { Injectable } from '@angular/core'
import { SessionStorageService } from 'ngx-webstorage'
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http'
import { BehaviorSubject, EMPTY, Observable, Subject, catchError, map, of, takeUntil, tap } from 'rxjs'
import { HttpClient, HttpResponse } from '@angular/common/http'
import { BehaviorSubject, EMPTY, Observable, Subject, catchError, map, of, takeUntil } from 'rxjs'

import { IAccount } from '../model/account.model'
import { LanguageService } from 'src/app/shared/service/language.service'
import { Router } from '@angular/router'
// TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service
//import { MSMemberService } from 'app/entities/member/member.service';
import { MemberService } from 'src/app/member/service/member.service'

@Injectable({ providedIn: 'root' })
export class AccountService {
// TODO: have unknown and offline instead of undefined and null
// TODO: have custom 'unknown' and 'offline' statuses instead of 'undefined' and 'null'
private accountData = new BehaviorSubject<IAccount | null | undefined>(undefined)
private isFetchingAccountData = false
private stopFetchingAccountData = new Subject()
Expand All @@ -21,9 +20,9 @@ export class AccountService {
private languageService: LanguageService,
private sessionStorage: SessionStorageService,
private router: Router,
private http: HttpClient // TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service
) //private memberService: MSMemberService
{}
private http: HttpClient,
private memberService: MemberService
) {}

private fetchAccountData() {
this.isFetchingAccountData = true
Expand All @@ -33,11 +32,10 @@ export class AccountService {
})
.pipe(
takeUntil(this.stopFetchingAccountData),
catchError((err) => {
catchError(() => {
this.authenticated = false
this.accountData.next(null)
// TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service
//this.memberService.memberData.next(undefined);
this.memberService.setMemberData(undefined)
this.isFetchingAccountData = false
return EMPTY
}),
Expand All @@ -51,8 +49,7 @@ export class AccountService {
}
this.accountData.next(account)
} else {
// TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service
//this.memberService.memberData.next(undefined);
this.memberService.setMemberData(undefined)
this.accountData.next(null)
this.authenticated = false
console.error('Invalid response:', response)
Expand All @@ -69,7 +66,7 @@ export class AccountService {
const headers = { 'Accept-Language': account.langKey }
return this.http.post('/services/userservice/api/account', account, { observe: 'response', headers }).pipe(
map((res: HttpResponse<any>) => this.isSuccess(res)),
catchError((err) => {
catchError(() => {
return of(false)
})
)
Expand All @@ -85,7 +82,7 @@ export class AccountService {
enableMfa(mfaSetup: any): Observable<string[] | null> {
return this.http.post('/services/userservice/api/account/mfa/on', mfaSetup, { observe: 'response' }).pipe(
map((res: HttpResponse<any>) => res.body),
catchError((err) => {
catchError(() => {
console.error('error enabling mfa')
return of(null)
})
Expand All @@ -95,12 +92,11 @@ export class AccountService {
disableMfa(): Observable<boolean> {
return this.http.post('/services/userservice/api/account/mfa/off', null, { observe: 'response' }).pipe(
map((res: HttpResponse<any>) => this.isSuccess(res)),
catchError((err) => {
catchError(() => {
return of(false)
})
)
}
// TODO: any - this seems to only be used for logging out (only ever receives null as arg)
clearAccountData() {
this.accountData.next(null)
this.authenticated = false
Expand Down Expand Up @@ -131,9 +127,8 @@ export class AccountService {

getAccountData(force?: boolean): Observable<IAccount | undefined | null> {
if (force) {
// TODO: uncomment when memberservice is added or change the account service so that this logic is absent from the account service
//this.memberService.stopFetchingMemberData.next();
//this.memberService.memberData.next(undefined);
this.memberService.stopFetchingMemberData.next(true)
this.memberService.setMemberData(undefined)
this.stopFetchingAccountData.next(true)
}
if ((this.accountData.value === undefined && !this.isFetchingAccountData) || force) {
Expand Down
13 changes: 0 additions & 13 deletions ui/src/app/account/service/auth-jwt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ export class AuthServerProvider {
return this.http.post<ILoginResult>('/auth/login', credentials)
}

// TODO: not being used?
/* loginWithToken(jwt, rememberMe) {
if (jwt) {
this.storeAuthenticationToken(jwt, rememberMe);
return Promise.resolve(jwt);
} else {
return Promise.reject('auth-jwt-service Promise reject'); // Put appropriate error message here
}
}
storeAuthenticationToken(jwt, rememberMe) {}
*/

logout(): Observable<any> {
return this.http.post('/auth/logout', null)
}
Expand Down
21 changes: 0 additions & 21 deletions ui/src/app/account/service/state-storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ export class StateStorageService {
this.$sessionStorage.clear('previousState')
}

// TODO: not being used?
/* storePreviousState(previousStateName, previousStateParams) {
const previousState = { name: previousStateName, params: previousStateParams };
this.$sessionStorage.store('previousState', previousState);
} */

getDestinationState() {
return this.$sessionStorage.retrieve('destinationState')
}
Expand All @@ -30,19 +24,4 @@ export class StateStorageService {
getUrl() {
return this.$sessionStorage.retrieve('previousUrl')
}

// TODO: not being used?
/* storeDestinationState(destinationState, destinationStateParams, fromState) {
const destinationInfo = {
destination: {
name: destinationState.name,
data: destinationState.data
},
params: destinationStateParams,
from: {
name: fromState.name
}
};
this.$sessionStorage.store('destinationState', destinationInfo);
} */
}
4 changes: 0 additions & 4 deletions ui/src/app/home/member-info/member-info-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ export class MemberInfoEditComponent implements OnInit, OnDestroy {
.pipe(take(1))
.subscribe((countries) => {
this.countries = countries
// TODO: redundant? remove
if (this.memberData) {
this.updateForm(this.memberData)
}
})

this.editForm.valueChanges.subscribe(() => {
Expand Down
Loading