Skip to content

Commit

Permalink
Merge pull request #1194 from ORCID/app-clean-up
Browse files Browse the repository at this point in the history
tidy up app
  • Loading branch information
bobcaprice authored May 22, 2024
2 parents 2d46404 + 145f206 commit 08cc64d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 60 deletions.
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 @@ -95,8 +95,7 @@ export class LoginComponent implements AfterViewInit, OnDestroy {
}
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

0 comments on commit 08cc64d

Please sign in to comment.