Skip to content

Commit

Permalink
Merge branch 'add-eslint' of https://github.com/ORCID/orcid-member-se…
Browse files Browse the repository at this point in the history
…rvices into add-eslint
  • Loading branch information
auumgn committed Oct 26, 2023
2 parents b61b178 + f141b56 commit 4c6ad62
Show file tree
Hide file tree
Showing 18 changed files with 290 additions and 267 deletions.
135 changes: 70 additions & 65 deletions ui/src/app/account/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import { AfterViewInit, Component, OnDestroy, Renderer2 } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { Router } from '@angular/router';
import { AccountService } from '../service/account.service';
import { LoginService } from '../service/login.service';
import { StateStorageService } from '../service/state-storage.service';
import { Subscription, filter, take } from 'rxjs';
import { EventService } from 'src/app/shared/service/event.service';
import { EventType } from 'src/app/app.constants';
import { Event } from 'src/app/shared/model/event.model';

import { AfterViewInit, Component, OnDestroy, Renderer2 } from '@angular/core'
import { FormBuilder } from '@angular/forms'
import { Router } from '@angular/router'
import { AccountService } from '../service/account.service'
import { LoginService } from '../service/login.service'
import { StateStorageService } from '../service/state-storage.service'
import { Subscription, filter, take } from 'rxjs'
import { EventService } from 'src/app/shared/service/event.service'
import { EventType } from 'src/app/app.constants'
import { Event } from 'src/app/shared/model/event.model'

@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
styleUrls: ['./login.component.scss'],
})
export class LoginComponent implements AfterViewInit, OnDestroy {
authenticationError = false;
showMfa = false;
mfaSent = false;
mfaError = false;
sub: Subscription | undefined;
authenticationError = false
showMfa = false
mfaSent = false
mfaError = false
sub: Subscription | undefined

loginForm = this.fb.group({
username: [''],
password: [''],
mfaCode: ['']
});
mfaCode: [''],
})

constructor(
private loginService: LoginService,
Expand All @@ -37,76 +36,84 @@ export class LoginComponent implements AfterViewInit, OnDestroy {
private fb: FormBuilder,
private eventService: EventService
) {
this.sub = this.eventService.on(EventType.LOG_IN_SUCCESS).subscribe(e => {
console.log(e.payload);
this.sub = this.eventService.on(EventType.LOG_IN_SUCCESS).subscribe((e) => {
console.log(e.payload)
})
}
}

ngOnDestroy(): void {
this.sub?.unsubscribe();
console.log('test')
}
ngOnDestroy(): void {
this.sub?.unsubscribe()
console.log('test')
}

ngAfterViewInit() {
setTimeout(() => this.renderer.selectRootElement('#username').scrollIntoView());
setTimeout(() =>
this.renderer.selectRootElement('#username').scrollIntoView()
)
}

cancel() {
this.authenticationError = false;
this.authenticationError = false
this.loginForm.patchValue({
username: '',
password: '',
mfaCode: ''
});
mfaCode: '',
})
}

login() {
this.mfaError = false;
const mfaCode = this.loginForm.get('mfaCode')?.value;
this.mfaError = false
const mfaCode = this.loginForm.get('mfaCode')?.value

if (this.showMfa && !mfaCode) {
this.mfaError = true;
this.mfaError = true
} else {
if (mfaCode) {
this.mfaSent = true;
this.mfaSent = true
}

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

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

View workflow job for this annotation

GitHub Actions / format

Forbidden non-null assertion

Check failure on line 77 in ui/src/app/account/login/login.component.ts

View workflow job for this annotation

GitHub Actions / format

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong
password: this.loginForm.get('password')?.value!,

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

View workflow job for this annotation

GitHub Actions / format

Forbidden non-null assertion

Check failure on line 78 in ui/src/app/account/login/login.component.ts

View workflow job for this annotation

GitHub Actions / format

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong
mfaCode: this.loginForm.get('mfaCode')?.value
mfaCode: this.loginForm.get('mfaCode')?.value,
})
.subscribe(
{
next: (data) => {
if (!data.mfaRequired) {
this.showMfa = false;
this.accountService.getAccountData().pipe(filter((account) => !!account), take(1)).subscribe((account) => {
.subscribe({
next: (data) => {
if (!data.mfaRequired) {
this.showMfa = false
this.accountService
.getAccountData()
.pipe(
filter((account) => !!account),
take(1)
)
.subscribe((account) => {
// TODO: remove after sprint review
console.log("Login successful, account data:", account);
this.loginSuccess();
});
} else {
this.showMfa = true;
this.mfaError = this.mfaSent;
}
this.mfaSent = false;
},
// TODO: review any type
error: err => {
this.loginService.logout();
this.authenticationError = true;
console.log('Login successful, account data:', account)
this.loginSuccess()
})
} else {
this.showMfa = true
this.mfaError = this.mfaSent
}
}
);
this.mfaSent = false
},
// TODO: review any type
error: (err) => {

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

View workflow job for this annotation

GitHub Actions / format

'err' is defined but never used
this.loginService.logout()
this.authenticationError = true
},
})
}
}

loginSuccess(): void {
this.router.navigate(['']);
this.router.navigate([''])

this.eventService.broadcast(new Event(EventType.LOG_IN_SUCCESS, "logged in"))
this.eventService.broadcast(
new Event(EventType.LOG_IN_SUCCESS, 'logged in')
)
// TODO: Event manager
/* this.eventManager.broadcast({
name: 'authenticationSuccess',
Expand All @@ -115,20 +122,18 @@ export class LoginComponent implements AfterViewInit, OnDestroy {

// previousState was set in the authExpiredInterceptor before being redirected to login modal.
// since login is successful, go to stored previousState and clear previousState
const redirect = this.stateStorageService.getUrl();
const redirect = this.stateStorageService.getUrl()
if (redirect) {
this.stateStorageService.storeUrl(null);
this.router.navigateByUrl(redirect);
this.stateStorageService.storeUrl(null)
this.router.navigateByUrl(redirect)
}
}

register() {
this.router.navigate(['/register']);
this.router.navigate(['/register'])
}

requestResetPassword() {
this.router.navigate(['/reset', 'request']);
this.router.navigate(['/reset', 'request'])
}

}

26 changes: 13 additions & 13 deletions ui/src/app/home/home.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing'

import { HomeComponent } from './home.component';
import { HomeComponent } from './home.component'

describe('HomeComponent', () => {
let component: HomeComponent;
let fixture: ComponentFixture<HomeComponent>;
let component: HomeComponent
let fixture: ComponentFixture<HomeComponent>

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [HomeComponent]
});
fixture = TestBed.createComponent(HomeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
declarations: [HomeComponent],
})
fixture = TestBed.createComponent(HomeComponent)
component = fixture.componentInstance
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})
8 changes: 3 additions & 5 deletions ui/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Component } from '@angular/core';
import { Component } from '@angular/core'

@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
styleUrls: ['./home.component.scss'],
})
export class HomeComponent {

}
export class HomeComponent {}
17 changes: 7 additions & 10 deletions ui/src/app/home/home.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { routes } from './home.route';
import { HomeComponent } from './home.component';
import { NgModule } from '@angular/core'
import { CommonModule } from '@angular/common'
import { RouterModule } from '@angular/router'
import { routes } from './home.route'
import { HomeComponent } from './home.component'

@NgModule({
declarations: [HomeComponent],
imports: [
CommonModule,
RouterModule.forChild(routes)
]
imports: [CommonModule, RouterModule.forChild(routes)],
})
export class HomeModule { }
export class HomeModule {}
29 changes: 13 additions & 16 deletions ui/src/app/home/home.route.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { Routes } from "@angular/router";
import { HomeComponent } from "../home/home.component";
import { AuthGuard } from "../account/auth.guard";
import { Routes } from '@angular/router'
import { HomeComponent } from '../home/home.component'
import { AuthGuard } from '../account/auth.guard'

export const routes: Routes = [
{

path: '',
component: HomeComponent,
data: {
authorities: ['ROLE_USER'],
pageTitle: 'home.title.string'
},
canActivate: [AuthGuard]

}
];

{
path: '',
component: HomeComponent,
data: {
authorities: ['ROLE_USER'],
pageTitle: 'home.title.string',
},
canActivate: [AuthGuard],
},
]
40 changes: 20 additions & 20 deletions ui/src/app/member/model/member.model.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Moment } from 'moment';
import { Moment } from 'moment'

export interface IMember {
id?: string;
clientId?: string;
clientName?: string;
clientSecret?: string;
salesforceId?: string;
parentSalesforceId?: string;
isConsortiumLead?: boolean;
superadminEnabled?: boolean;
assertionServiceEnabled?: boolean;
createdBy?: string;
createdDate?: Moment;
lastModifiedBy?: string;
lastModifiedDate?: Moment;
type?: string;
status?: string;
defaultLanguage?: string;
id?: string
clientId?: string
clientName?: string
clientSecret?: string
salesforceId?: string
parentSalesforceId?: string
isConsortiumLead?: boolean
superadminEnabled?: boolean
assertionServiceEnabled?: boolean
createdBy?: string
createdDate?: Moment
lastModifiedBy?: string
lastModifiedDate?: Moment
type?: string
status?: string
defaultLanguage?: string
}

export class Member implements IMember {
Expand All @@ -38,8 +38,8 @@ export class Member implements IMember {
public status?: string,
public defaultLaungage?: string
) {
this.isConsortiumLead = this.isConsortiumLead || false;
this.superadminEnabled = this.superadminEnabled || false;
this.assertionServiceEnabled = this.assertionServiceEnabled || false;
this.isConsortiumLead = this.isConsortiumLead || false
this.superadminEnabled = this.superadminEnabled || false
this.assertionServiceEnabled = this.assertionServiceEnabled || false
}
}
14 changes: 7 additions & 7 deletions ui/src/app/member/model/salesforce-address.model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export interface ISFAddress {
city?: string;
country?: string;
countryCode?: string;
postalCode?: string;
state?: string;
stateCode?: string;
street?: string;
city?: string
country?: string
countryCode?: string
postalCode?: string
state?: string
stateCode?: string
street?: string
}

export class SFAddress implements ISFAddress {
Expand Down
9 changes: 6 additions & 3 deletions ui/src/app/member/model/salesforce-country.model copy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
export interface ISFState {
code: string;
name: string;
code: string
name: string
}

export class SFState implements ISFState {
constructor(public code: string, public name: string) {}
constructor(
public code: string,
public name: string
) {}
}
Loading

0 comments on commit 4c6ad62

Please sign in to comment.