diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index ae1c30bea2..7e257b1671 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -91,7 +91,7 @@ const routes: Routes = [ path: ApplicationRoutes.register, canActivateChild: [LanguageGuard, RegisterGuard], loadChildren: () => - import('./register2/register.module').then((m) => m.RegisterModule), + import('./register/register.module').then((m) => m.RegisterModule), }, { path: ApplicationRoutes.search, @@ -151,7 +151,7 @@ const routes: Routes = [ matcher: routerReactivation, canActivateChild: [LanguageGuard, RegisterGuard], loadChildren: () => - import('./register2/register.module').then((m) => m.RegisterModule), + import('./register/register.module').then((m) => m.RegisterModule), }, { path: ApplicationRoutes.selfService, diff --git a/src/app/core/register/register.backend-validators.ts b/src/app/core/register/register.backend-validators.ts index f3597f7535..d43340e885 100644 --- a/src/app/core/register/register.backend-validators.ts +++ b/src/app/core/register/register.backend-validators.ts @@ -1,15 +1,15 @@ +import { HttpClient } from '@angular/common/http' import { - UntypedFormGroup, - AsyncValidatorFn, AbstractControl, + AsyncValidatorFn, + UntypedFormGroup, ValidationErrors, } from '@angular/forms' -import { RegisterForm } from 'src/app/types/register.endpoint' -import { Constructor } from 'src/app/types' import { Observable, of } from 'rxjs' +import { catchError, map, retry } from 'rxjs/operators' +import { Constructor } from 'src/app/types' +import { RegisterForm } from 'src/app/types/register.endpoint' import { environment } from 'src/environments/environment' -import { retry, catchError, map } from 'rxjs/operators' -import { HttpClient } from '@angular/common/http' import { ErrorHandlerService } from '../error-handler/error-handler.service' interface HasHttpClientAndErrorHandler { @@ -23,7 +23,9 @@ interface HasFormAdapters { formGroupToFullRegistrationForm( StepA: UntypedFormGroup, StepB: UntypedFormGroup, - StepC: UntypedFormGroup + StepC: UntypedFormGroup, + StepC2: UntypedFormGroup, + StepD: UntypedFormGroup ): RegisterForm } @@ -160,12 +162,17 @@ export function RegisterBackendValidatorMixin< StepA: UntypedFormGroup, StepB: UntypedFormGroup, StepC: UntypedFormGroup, + StepC2: UntypedFormGroup, + StepD: UntypedFormGroup, + type?: 'shibboleth' ): Observable { const registerForm = this.formGroupToFullRegistrationForm( StepA, StepB, - StepC + StepC, + StepC2, + StepD ) return this._http .post(`${environment.API_WEB}register.json`, registerForm) diff --git a/src/app/core/register/register.form-adapter.ts b/src/app/core/register/register.form-adapter.ts index 8657261895..aa069cc955 100644 --- a/src/app/core/register/register.form-adapter.ts +++ b/src/app/core/register/register.form-adapter.ts @@ -1,7 +1,7 @@ import { UntypedFormGroup } from '@angular/forms' -import { RegisterForm } from 'src/app/types/register.endpoint' -import { Value, Visibility } from 'src/app/types/common.endpoint' import { Constructor } from 'src/app/types' +import { Value, Visibility } from 'src/app/types/common.endpoint' +import { RegisterForm } from 'src/app/types/register.endpoint' export function RegisterFormAdapterMixin>(base: T) { return class RegisterFormAdapter extends base { @@ -116,18 +116,61 @@ export function RegisterFormAdapterMixin>(base: T) { return value } + formGroupToAffiliationRegisterForm(formGroup: UntypedFormGroup) { + const value = formGroup.controls['organization'].value + const departmentName = formGroup.controls['departmentName'].value + const roleTitle = formGroup.controls['roleTitle'].value + const startDateGroup = formGroup.controls['startDateGroup'].value + + if (typeof value === 'string') { + return { affiliationName: { value } } + } else { + return { + affiliationName: { value: value.value }, + disambiguatedAffiliationSourceId: { + value: value.disambiguatedAffiliationIdentifier, + }, + orgDisambiguatedId: { + value: value.disambiguatedAffiliationIdentifier, + }, + departmentName: { value: departmentName }, + roleTitle: { value: roleTitle }, + affiliationType: { value: 'employment' }, + startDate: { + month: startDateGroup.startDateMonth, + year: startDateGroup.startDateYear, + }, + sourceId: { value: value.sourceId }, + city: { value: value.city }, + region: { value: value.region }, + country: { value: value.country }, + } + } + } + formGroupToFullRegistrationForm( StepA: UntypedFormGroup, StepB: UntypedFormGroup, - StepC: UntypedFormGroup + StepC: UntypedFormGroup, + StepC2: UntypedFormGroup, + StepD: UntypedFormGroup ): RegisterForm { - return { + const value = { ...StepA.value.personal, ...StepB.value.password, - ...StepB.value.sendOrcidNews, ...StepC.value.activitiesVisibilityDefault, - ...StepC.value.termsOfUse, - ...StepC.value.captcha, + ...StepD.value.sendOrcidNews, + ...StepD.value.termsOfUse, + ...StepD.value.captcha, + } + + if (StepC2.valid) { + return { + ...value, + ...StepC2.value.affiliations, + } + } else { + return value } } } diff --git a/src/app/core/register/register.service.spec.ts b/src/app/core/register/register.service.spec.ts deleted file mode 100644 index 06ed3590bd..0000000000 --- a/src/app/core/register/register.service.spec.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { TestBed } from '@angular/core/testing' - -import { RegisterService } from './register.service' -import { HttpClientTestingModule } from '@angular/common/http/testing' -import { RouterTestingModule } from '@angular/router/testing' -import { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog' -import { WINDOW_PROVIDERS } from '../../cdk/window' -import { PlatformInfoService } from '../../cdk/platform-info' -import { ErrorHandlerService } from '../error-handler/error-handler.service' -import { SnackbarService } from '../../cdk/snackbar/snackbar.service' -import { MatLegacySnackBar as MatSnackBar } from '@angular/material/legacy-snack-bar' -import { Overlay } from '@angular/cdk/overlay' - -import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' - -describe('RegisterService', () => { - beforeEach(() => - TestBed.configureTestingModule({ - imports: [HttpClientTestingModule, RouterTestingModule], - providers: [ - WINDOW_PROVIDERS, - PlatformInfoService, - ErrorHandlerService, - SnackbarService, - MatSnackBar, - MatDialog, - Overlay, - ], - }) - ) - - it('should be created', () => { - const service: RegisterService = TestBed.inject(RegisterService) - expect(service).toBeTruthy() - }) -}) diff --git a/src/app/core/register/register.service.ts b/src/app/core/register/register.service.ts index 98e7fa6758..26791a9293 100644 --- a/src/app/core/register/register.service.ts +++ b/src/app/core/register/register.service.ts @@ -1,8 +1,8 @@ import { HttpClient } from '@angular/common/http' import { Injectable } from '@angular/core' import { UntypedFormGroup } from '@angular/forms' -import { Observable } from 'rxjs' -import { catchError, first, map, retry, switchMap } from 'rxjs/operators' +import { Observable, throwError } from 'rxjs' +import { catchError, first, map, retry, switchMap, tap } from 'rxjs/operators' import { PlatformInfo, PlatformInfoService } from 'src/app/cdk/platform-info' import { RequestInfoForm } from 'src/app/types' import { @@ -12,13 +12,14 @@ import { } from 'src/app/types/register.endpoint' import { environment } from 'src/environments/environment' +import { ERROR_REPORT } from 'src/app/errors' +import { objectToUrlParameters } from '../../constants' +import { ReactivationLocal } from '../../types/reactivation.local' import { ErrorHandlerService } from '../error-handler/error-handler.service' import { UserService } from '../user/user.service' import { RegisterBackendValidatorMixin } from './register.backend-validators' import { RegisterFormAdapterMixin } from './register.form-adapter' -import { ERROR_REPORT } from 'src/app/errors' -import { objectToUrlParameters } from '../../constants' -import { ReactivationLocal } from '../../types/reactivation.local' +import { EmailCategoryEndpoint } from 'src/app/types/register.email-category' // Mixing boiler plate @@ -74,10 +75,18 @@ export class RegisterService extends _RegisterServiceMixingBase { .pipe(map((form) => (this.backendRegistrationForm = form))) } + getEmailCategory(email: string): Observable { + return this._http.get( + `${environment.API_WEB}email-domain/find-category?domain=${email}` + ) + } + register( StepA: UntypedFormGroup, StepB: UntypedFormGroup, StepC: UntypedFormGroup, + StepC2: UntypedFormGroup, + StepD: UntypedFormGroup, reactivation: ReactivationLocal, requestInfoForm?: RequestInfoForm, updateUserService = true @@ -87,7 +96,9 @@ export class RegisterService extends _RegisterServiceMixingBase { const registerForm = this.formGroupToFullRegistrationForm( StepA, StepB, - StepC + StepC, + StepC2, + StepD ) this.addOauthContext(registerForm, requestInfoForm) return this._platform.get().pipe( diff --git a/src/app/core/register2/register2.backend-validators.ts b/src/app/core/register2/register2.backend-validators.ts deleted file mode 100644 index 5d730df0ad..0000000000 --- a/src/app/core/register2/register2.backend-validators.ts +++ /dev/null @@ -1,256 +0,0 @@ -import { HttpClient } from '@angular/common/http' -import { - AbstractControl, - AsyncValidatorFn, - UntypedFormGroup, - ValidationErrors, -} from '@angular/forms' -import { Observable, of } from 'rxjs' -import { catchError, map, retry } from 'rxjs/operators' -import { Constructor } from 'src/app/types' -import { RegisterForm } from 'src/app/types/register.endpoint' -import { environment } from 'src/environments/environment' -import { ErrorHandlerService } from '../error-handler/error-handler.service' - -interface HasHttpClientAndErrorHandler { - _http: HttpClient - _errorHandler: ErrorHandlerService -} - -interface HasFormAdapters { - formGroupToEmailRegisterForm(formGroup: UntypedFormGroup): RegisterForm - formGroupToPasswordRegisterForm(formGroup: UntypedFormGroup): RegisterForm - formGroupToFullRegistrationForm( - StepA: UntypedFormGroup, - StepB: UntypedFormGroup, - StepC: UntypedFormGroup, - StepC2: UntypedFormGroup, - StepD: UntypedFormGroup - ): RegisterForm -} - -export function Register2BackendValidatorMixin< - T extends Constructor ->(base: T) { - return class RegisterBackendValidator extends base { - constructor(...args: any[]) { - super(...args) - } - formInputs = { - givenNames: { - validationEndpoint: 'validateGivenNames', - }, - familyNames: { - validationEndpoint: 'validateFamilyNames', - }, - email: { - validationEndpoint: 'validateEmail', - }, - emailsAdditional: { - validationEndpoint: 'validateEmailsAdditional', - }, - passwordConfirm: { - validationEndpoint: 'validatePasswordConfirm', - }, - password: { - validationEndpoint: 'validatePassword', - }, - } - - validateRegisterValue( - controlName: string, - value: RegisterForm - ): Observable { - return this._http - .post( - environment.API_WEB + - `oauth/custom/register/${this.formInputs[controlName].validationEndpoint}.json`, - value - ) - .pipe( - retry(3), - catchError((error) => this._errorHandler.handleError(error)) - ) - } - - validateAdditionalEmailsReactivation( - value: RegisterForm - ): Observable { - return this._http - .post( - `${environment.API_WEB}reactivateAdditionalEmailsValidate.json`, - value - ) - .pipe( - retry(3), - catchError((error) => this._errorHandler.handleError(error)) - ) - } - - backendValueValidate( - controlName: 'givenNames' | 'familyNames' | 'email' | 'password' - ): AsyncValidatorFn { - return ( - control: AbstractControl - ): Observable => { - if (control.value === '') { - return of(null) - } - const value = {} - value[controlName] = { value: control.value } - - return this.validateRegisterValue(controlName, value).pipe( - map((res) => { - if (res[controlName].errors && res[controlName].errors.length > 0) { - const error = { - backendError: res[controlName].errors, - } - return error - } - return null - }) - ) - } - } - - backendAdditionalEmailsValidate(reactivate: boolean): AsyncValidatorFn { - return ( - formGroup: UntypedFormGroup - ): Observable => { - const value: RegisterForm = this.formGroupToEmailRegisterForm(formGroup) - if (!value.emailsAdditional || value.emailsAdditional.length === 0) { - return of(null) - } - - if (reactivate) { - return this.validateAdditionalEmailsReactivation(value).pipe( - map((response) => { - // Add errors to additional emails controls - return this.setFormGroupEmailErrors(response, 'backendErrors') - }) - ) - } - - return this.validateRegisterValue('emailsAdditional', value).pipe( - map((response) => { - // Add errors to additional emails controls - return this.setFormGroupEmailErrors(response, 'backendErrors') - }) - ) - } - } - - backendPasswordValidate(): AsyncValidatorFn { - return ( - formGroup: UntypedFormGroup - ): Observable => { - const value: RegisterForm = - this.formGroupToPasswordRegisterForm(formGroup) - if (value.password.value === '' || value.passwordConfirm.value === '') { - return of(null) - } - return this.validateRegisterValue('password', value).pipe( - map((response) => { - // Add errors to additional emails controls - return this.setFormGroupPasswordErrors(response, 'backendErrors') - }) - ) - } - } - - backendRegisterFormValidate( - StepA: UntypedFormGroup, - StepB: UntypedFormGroup, - StepC: UntypedFormGroup, - StepC2: UntypedFormGroup, - StepD: UntypedFormGroup, - - type?: 'shibboleth' - ): Observable { - const registerForm = this.formGroupToFullRegistrationForm( - StepA, - StepB, - StepC, - StepC2, - StepD - ) - return this._http - .post(`${environment.API_WEB}register.json`, registerForm) - .pipe( - retry(3), - catchError((error) => this._errorHandler.handleError(error)) - ) - } - - public setFormGroupEmailErrors( - registerForm: RegisterForm, - errorGroup: string - ) { - let hasErrors = false - const error = {} - error[errorGroup] = { - additionalEmails: {}, - email: [], - } - - registerForm.emailsAdditional.forEach((responseControl) => { - if (responseControl.errors && responseControl.errors.length > 0) { - hasErrors = true - error[errorGroup]['additionalEmails'][responseControl.value] = - responseControl.errors - } - }) - - if ( - registerForm.email && - registerForm.email.errors && - registerForm.email.errors.length > 0 - ) { - hasErrors = true - error[errorGroup]['email'].push({ - value: registerForm.email.value, - errors: registerForm.email.errors, - }) - } - - return hasErrors ? error : null - } - - public setFormGroupPasswordErrors( - registerForm: RegisterForm, - errorGroup: string - ) { - let hasErrors = false - const error = {} - error[errorGroup] = { - password: [], - passwordConfirm: [], - } - - if ( - registerForm.password && - registerForm.password.errors && - registerForm.password.errors.length > 0 - ) { - hasErrors = true - error[errorGroup]['password'].push({ - value: registerForm.email.value, - errors: registerForm.email.errors, - }) - } - if ( - registerForm.passwordConfirm && - registerForm.passwordConfirm.errors && - registerForm.passwordConfirm.errors.length > 0 - ) { - hasErrors = true - error[errorGroup]['passwordConfirm'].push({ - value: registerForm.passwordConfirm.value, - errors: registerForm.passwordConfirm.errors, - }) - } - - return hasErrors ? error : null - } - } -} diff --git a/src/app/core/register2/register2.form-adapter.ts b/src/app/core/register2/register2.form-adapter.ts deleted file mode 100644 index 1e0b4c7990..0000000000 --- a/src/app/core/register2/register2.form-adapter.ts +++ /dev/null @@ -1,177 +0,0 @@ -import { UntypedFormGroup } from '@angular/forms' -import { Constructor } from 'src/app/types' -import { Value, Visibility } from 'src/app/types/common.endpoint' -import { RegisterForm } from 'src/app/types/register.endpoint' - -export function Register2FormAdapterMixin>(base: T) { - return class RegisterFormAdapter extends base { - formGroupToEmailRegisterForm(formGroup: UntypedFormGroup): RegisterForm { - let additionalEmailsValue: Value[] - if (formGroup.controls['additionalEmails']) { - const additionalEmailsControls = ( - formGroup.controls['additionalEmails'] as UntypedFormGroup - ).controls - additionalEmailsValue = Object.keys(additionalEmailsControls) - .filter((name) => additionalEmailsControls[name].value !== '') - .map((name) => { - if (additionalEmailsControls[name].value) { - return { value: additionalEmailsControls[name].value } - } - }) - } - let emailValue - if (formGroup.controls['email']) { - emailValue = formGroup.controls['email'].value - } - - const value: RegisterForm = {} - - if (emailValue) { - value['email'] = { value: emailValue } - } - if (additionalEmailsValue) { - value['emailsAdditional'] = additionalEmailsValue - } - return value - } - - formGroupToNamesRegisterForm(formGroup: UntypedFormGroup): RegisterForm { - return { - givenNames: { value: formGroup.controls['givenNames'].value }, - familyNames: { value: formGroup.controls['familyNames'].value }, - } - } - - formGroupToActivitiesVisibilityForm( - formGroup: UntypedFormGroup - ): RegisterForm { - let activitiesVisibilityDefault: Visibility - if ( - formGroup && - formGroup.controls && - formGroup.controls['activitiesVisibilityDefault'] - ) { - activitiesVisibilityDefault = { - visibility: formGroup.controls['activitiesVisibilityDefault'].value, - } - } - return { activitiesVisibilityDefault } - } - - formGroupToPasswordRegisterForm(formGroup: UntypedFormGroup): RegisterForm { - let password: Value - if (formGroup && formGroup.controls && formGroup.controls['password']) { - password = { value: formGroup.controls['password'].value } - } - let passwordConfirm: Value - if ( - formGroup && - formGroup.controls && - formGroup.controls['passwordConfirm'] - ) { - passwordConfirm = { value: formGroup.controls['passwordConfirm'].value } - } - return { password, passwordConfirm } - } - - formGroupTermsOfUseAndDataProcessedRegisterForm( - formGroup: UntypedFormGroup - ): RegisterForm { - let termsOfUse: Value - let dataProcessed: Value - if (formGroup && formGroup.controls) { - if (formGroup.controls['termsOfUse']) { - termsOfUse = { value: formGroup.controls['termsOfUse'].value } - } - if (formGroup.controls['dataProcessed']) { - dataProcessed = { value: formGroup.controls['dataProcessed'].value } - } - } - return { termsOfUse, dataProcessed } - } - - formGroupToSendOrcidNewsForm(formGroup: UntypedFormGroup) { - let sendOrcidNews: Value - if ( - formGroup && - formGroup.controls && - formGroup.controls['sendOrcidNews'] - ) { - sendOrcidNews = { value: formGroup.controls['sendOrcidNews'].value } - } - return { sendOrcidNews } - } - - formGroupToRecaptchaForm( - formGroup: UntypedFormGroup, - widgetId: number - ): RegisterForm { - const value: RegisterForm = {} - value.grecaptchaWidgetId = { - value: widgetId != null ? widgetId.toString() : null, - } - if (formGroup && formGroup.controls && formGroup.controls['captcha']) { - value.grecaptcha = { value: formGroup.controls['captcha'].value } - } - return value - } - - formGroupToAffiliationRegisterForm(formGroup: UntypedFormGroup) { - const value = formGroup.controls['organization'].value - const departmentName = formGroup.controls['departmentName'].value - const roleTitle = formGroup.controls['roleTitle'].value - const startDateGroup = formGroup.controls['startDateGroup'].value - - if (typeof value === 'string') { - return { affiliationName: { value } } - } else { - return { - affiliationName: { value: value.value }, - disambiguatedAffiliationSourceId: { - value: value.disambiguatedAffiliationIdentifier, - }, - orgDisambiguatedId: { - value: value.disambiguatedAffiliationIdentifier, - }, - departmentName: { value: departmentName }, - roleTitle: { value: roleTitle }, - affiliationType: { value: 'employment' }, - startDate: { - month: startDateGroup.startDateMonth, - year: startDateGroup.startDateYear, - }, - sourceId: { value: value.sourceId }, - city: { value: value.city }, - region: { value: value.region }, - country: { value: value.country }, - } - } - } - - formGroupToFullRegistrationForm( - StepA: UntypedFormGroup, - StepB: UntypedFormGroup, - StepC: UntypedFormGroup, - StepC2: UntypedFormGroup, - StepD: UntypedFormGroup - ): RegisterForm { - const value = { - ...StepA.value.personal, - ...StepB.value.password, - ...StepC.value.activitiesVisibilityDefault, - ...StepD.value.sendOrcidNews, - ...StepD.value.termsOfUse, - ...StepD.value.captcha, - } - - if (StepC2.valid) { - return { - ...value, - ...StepC2.value.affiliations, - } - } else { - return value - } - } - } -} diff --git a/src/app/core/register2/register2.service.ts b/src/app/core/register2/register2.service.ts deleted file mode 100644 index 627e8ed9bb..0000000000 --- a/src/app/core/register2/register2.service.ts +++ /dev/null @@ -1,192 +0,0 @@ -import { HttpClient } from '@angular/common/http' -import { Injectable } from '@angular/core' -import { UntypedFormGroup } from '@angular/forms' -import { Observable, throwError } from 'rxjs' -import { catchError, first, map, retry, switchMap, tap } from 'rxjs/operators' -import { PlatformInfo, PlatformInfoService } from 'src/app/cdk/platform-info' -import { RequestInfoForm } from 'src/app/types' -import { - DuplicatedName, - RegisterConfirmResponse, - RegisterForm, -} from 'src/app/types/register.endpoint' -import { environment } from 'src/environments/environment' - -import { ERROR_REPORT } from 'src/app/errors' -import { objectToUrlParameters } from '../../constants' -import { ReactivationLocal } from '../../types/reactivation.local' -import { ErrorHandlerService } from '../error-handler/error-handler.service' -import { UserService } from '../user/user.service' -import { Register2BackendValidatorMixin } from './register2.backend-validators' -import { Register2FormAdapterMixin } from './register2.form-adapter' -import { EmailCategoryEndpoint } from 'src/app/types/register.email-category' - -// Mixing boiler plate - -class Register2ServiceBase { - constructor( - public _http: HttpClient, - public _errorHandler: ErrorHandlerService - ) {} -} -const _RegisterServiceMixingBase = Register2BackendValidatorMixin( - Register2FormAdapterMixin(Register2ServiceBase) -) - -@Injectable({ - providedIn: 'root', -}) -export class Register2Service extends _RegisterServiceMixingBase { - backendRegistrationForm: RegisterForm - - constructor( - _http: HttpClient, - _errorHandler: ErrorHandlerService, - private _userService: UserService, - private _platform: PlatformInfoService - ) { - super(_http, _errorHandler) - } - - public checkDuplicatedResearcher(names: { - familyNames: string - givenNames: string - }) { - return this._http - .get(environment.API_WEB + `dupicateResearcher.json`, { - params: names, - withCredentials: true, - }) - .pipe( - retry(3), - catchError((error) => this._errorHandler.handleError(error)) - ) - } - - getRegisterForm(): Observable { - return this._http - .get(`${environment.API_WEB}register.json`, { - withCredentials: true, - }) - .pipe( - retry(3), - catchError((error) => this._errorHandler.handleError(error)) - ) - .pipe(map((form) => (this.backendRegistrationForm = form))) - } - - getEmailCategory(email: string): Observable { - return this._http.get( - `${environment.API_WEB}email-domain/find-category?domain=${email}` - ) - } - - register( - StepA: UntypedFormGroup, - StepB: UntypedFormGroup, - StepC: UntypedFormGroup, - StepC2: UntypedFormGroup, - StepD: UntypedFormGroup, - reactivation: ReactivationLocal, - requestInfoForm?: RequestInfoForm, - updateUserService = true - ): Observable { - this.backendRegistrationForm.valNumClient = - this.backendRegistrationForm.valNumServer / 2 - const registerForm = this.formGroupToFullRegistrationForm( - StepA, - StepB, - StepC, - StepC2, - StepD - ) - this.addOauthContext(registerForm, requestInfoForm) - return this._platform.get().pipe( - first(), - switchMap((platform) => { - let url = `${environment.API_WEB}` - if ( - platform.institutional || - platform.queryParameters.linkType === 'shibboleth' - ) { - url += `shibboleth/` - } - if (reactivation.isReactivation) { - url += `reactivationConfirm.json?${objectToUrlParameters( - platform.queryParameters - )}` - registerForm.resetParams = reactivation.reactivationCode - } else { - url += `registerConfirm.json?${objectToUrlParameters( - platform.queryParameters - )}` - } - - const registerFormWithTypeContext = this.addCreationTypeContext( - platform, - registerForm - ) - - return this._http - .post( - url, - Object.assign( - this.backendRegistrationForm, - registerFormWithTypeContext - ) - ) - .pipe( - retry(3), - catchError((error) => - this._errorHandler.handleError(error, ERROR_REPORT.REGISTER) - ), - switchMap((value) => { - return this._userService.refreshUserSession(true, true).pipe( - first(), - map((userStatus) => { - if (!userStatus.loggedIn && !value.errors) { - // sanity check the user should be logged - // sanity check the user should be logged - this._errorHandler.handleError( - new Error('registerSanityIssue'), - ERROR_REPORT.REGISTER - ) - } - return value - }) - ) - }) - ) - }) - ) - } - - addOauthContext( - registerForm: RegisterForm, - requestInfoForm?: RequestInfoForm - ): void { - if (requestInfoForm) { - registerForm.referredBy = { value: requestInfoForm.clientId } - } - } - addCreationTypeContext( - platform: PlatformInfo, - registerForm: RegisterForm - ): RegisterForm { - /// TODO @leomendoza123 depend only on the user session thirty party login data - /// avoid taking data from the the parameters. - if ( - platform.social || - platform.queryParameters.providerId === 'facebook' || - platform.queryParameters.providerId === 'google' - ) { - registerForm.linkType = 'social' - return registerForm - } else if (platform.institutional || platform.queryParameters.providerId) { - registerForm.linkType = 'shibboleth' - return registerForm - } else { - return registerForm - } - } -} diff --git a/src/app/register/components/form-anti-robots/form-anti-robots.component.spec.ts b/src/app/register/components/form-anti-robots/form-anti-robots.component.spec.ts index 5b64b57dbc..16717e0a8f 100644 --- a/src/app/register/components/form-anti-robots/form-anti-robots.component.spec.ts +++ b/src/app/register/components/form-anti-robots/form-anti-robots.component.spec.ts @@ -10,7 +10,7 @@ import { PlatformInfoService } from '../../../cdk/platform-info' import { SnackbarService } from '../../../cdk/snackbar/snackbar.service' import { WINDOW_PROVIDERS } from '../../../cdk/window' import { ErrorHandlerService } from '../../../core/error-handler/error-handler.service' -import { Register2Service } from '../../../core/register2/register2.service' +import { RegisterService } from '../../../core/register/register.service' import { FormAntiRobotsComponent } from './form-anti-robots.component' import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' @@ -25,7 +25,7 @@ describe('FormAntiRobotsComponent', () => { declarations: [FormAntiRobotsComponent], providers: [ WINDOW_PROVIDERS, - Register2Service, + RegisterService, ErrorStateMatcher, PlatformInfoService, ErrorHandlerService, diff --git a/src/app/register/components/form-anti-robots/form-anti-robots.component.ts b/src/app/register/components/form-anti-robots/form-anti-robots.component.ts index 7c9a67ad70..7ddd4163df 100644 --- a/src/app/register/components/form-anti-robots/form-anti-robots.component.ts +++ b/src/app/register/components/form-anti-robots/form-anti-robots.component.ts @@ -9,7 +9,7 @@ import { } from '@angular/forms' import { ErrorStateMatcher } from '@angular/material/core' import { merge, Subject } from 'rxjs' -import { Register2Service } from 'src/app/core/register2/register2.service' +import { RegisterService } from 'src/app/core/register/register.service' import { BaseForm } from '../BaseForm' import { RegisterStateService } from '../../register-state.service' @@ -50,7 +50,7 @@ export class FormAntiRobotsComponent extends BaseForm implements OnInit { } constructor( - private _register: Register2Service, + private _register: RegisterService, private _registerStateService: RegisterStateService ) { super() diff --git a/src/app/register/components/form-current-employment/form-current-employment.component.spec.ts b/src/app/register/components/form-current-employment/form-current-employment.component.spec.ts index c3ded611a2..1a81cdd8d3 100644 --- a/src/app/register/components/form-current-employment/form-current-employment.component.spec.ts +++ b/src/app/register/components/form-current-employment/form-current-employment.component.spec.ts @@ -11,7 +11,7 @@ import { SnackbarService } from '../../../cdk/snackbar/snackbar.service' import { WINDOW_PROVIDERS } from '../../../cdk/window' import { ErrorHandlerService } from '../../../core/error-handler/error-handler.service' import { ReactivationService } from '../../../core/reactivation/reactivation.service' -import { Register2Service } from '../../../core/register2/register2.service' +import { RegisterService } from '../../../core/register/register.service' import { FormCurrentEmploymentComponent } from './form-current-employment.component' import { MatLegacyAutocomplete, @@ -38,7 +38,7 @@ describe('FormPersonalComponent', () => { providers: [ WINDOW_PROVIDERS, ReactivationService, - Register2Service, + RegisterService, PlatformInfoService, ErrorHandlerService, SnackbarService, diff --git a/src/app/register/components/form-current-employment/form-current-employment.component.ts b/src/app/register/components/form-current-employment/form-current-employment.component.ts index 67576ba86b..1074342eb0 100644 --- a/src/app/register/components/form-current-employment/form-current-employment.component.ts +++ b/src/app/register/components/form-current-employment/form-current-employment.component.ts @@ -18,7 +18,7 @@ import { ValidatorFn, Validators, } from '@angular/forms' -import { Register2Service } from 'src/app/core/register2/register2.service' +import { RegisterService } from 'src/app/core/register/register.service' import { OrcidValidators } from 'src/app/validators' import { first, switchMap, takeUntil, tap } from 'rxjs/operators' @@ -60,8 +60,8 @@ export class MyErrorStateMatcher implements ErrorStateMatcher { styleUrls: [ './form-current-employment.component.scss', './form-current-employment.component.scss-theme.scss', - '../register2.style.scss', - '../register2.scss-theme.scss', + '../register.style.scss', + '../register.scss-theme.scss', ], preserveWhitespaces: true, providers: [ @@ -126,7 +126,7 @@ export class FormCurrentEmploymentComponent isMobile: boolean rorId: string = 'https://ror.org/036mest28' constructor( - private _register: Register2Service, + private _register: RegisterService, private _platform: PlatformInfoService, private _liveAnnouncer: LiveAnnouncer, private _recordAffiliationService: RecordAffiliationService, diff --git a/src/app/register/components/form-notifications/form-notifications.component.spec.ts b/src/app/register/components/form-notifications/form-notifications.component.spec.ts index 8734d9d3b7..9bfc7fd4fb 100644 --- a/src/app/register/components/form-notifications/form-notifications.component.spec.ts +++ b/src/app/register/components/form-notifications/form-notifications.component.spec.ts @@ -9,7 +9,7 @@ import { PlatformInfoService } from '../../../cdk/platform-info' import { SnackbarService } from '../../../cdk/snackbar/snackbar.service' import { WINDOW_PROVIDERS } from '../../../cdk/window' import { ErrorHandlerService } from '../../../core/error-handler/error-handler.service' -import { Register2Service } from '../../../core/register2/register2.service' +import { RegisterService } from '../../../core/register/register.service' import { FormNotificationsComponent } from './form-notifications.component' import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' @@ -31,7 +31,7 @@ describe('FormNotificationsComponent', () => { declarations: [FormNotificationsComponent], providers: [ WINDOW_PROVIDERS, - Register2Service, + RegisterService, PlatformInfoService, ErrorHandlerService, SnackbarService, diff --git a/src/app/register/components/form-notifications/form-notifications.component.ts b/src/app/register/components/form-notifications/form-notifications.component.ts index edbfad6e43..e14290ea65 100644 --- a/src/app/register/components/form-notifications/form-notifications.component.ts +++ b/src/app/register/components/form-notifications/form-notifications.component.ts @@ -7,7 +7,7 @@ import { Validators, } from '@angular/forms' -import { Register2Service } from 'src/app/core/register2/register2.service' +import { RegisterService } from 'src/app/core/register/register.service' import { BaseForm } from '../BaseForm' @Component({ @@ -15,8 +15,8 @@ import { BaseForm } from '../BaseForm' templateUrl: './form-notifications.component.html', styleUrls: [ './form-notifications.component.scss', - '../register2.style.scss', - '../register2.scss-theme.scss', + '../register.style.scss', + '../register.scss-theme.scss', ], providers: [ { @@ -32,7 +32,7 @@ import { BaseForm } from '../BaseForm' ], }) export class FormNotificationsComponent extends BaseForm implements OnInit { - constructor(private _register: Register2Service) { + constructor(private _register: RegisterService) { super() } ngOnInit() { diff --git a/src/app/register/components/form-password/form-password.component.spec.ts b/src/app/register/components/form-password/form-password.component.spec.ts index b4c5282752..ac6452f154 100644 --- a/src/app/register/components/form-password/form-password.component.spec.ts +++ b/src/app/register/components/form-password/form-password.component.spec.ts @@ -14,7 +14,7 @@ import { MdePopoverModule } from '../../../cdk/popover' import { SnackbarService } from '../../../cdk/snackbar/snackbar.service' import { WINDOW_PROVIDERS } from '../../../cdk/window' import { ErrorHandlerService } from '../../../core/error-handler/error-handler.service' -import { Register2Service } from '../../../core/register2/register2.service' +import { RegisterService } from '../../../core/register/register.service' import { FormPasswordComponent } from './form-password.component' import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' @@ -37,7 +37,7 @@ describe('FormPasswordComponent', () => { { provide: MatDialogRef, useValue: {} }, { provide: MAT_DIALOG_DATA, useValue: {} }, WINDOW_PROVIDERS, - Register2Service, + RegisterService, PlatformInfoService, ErrorHandlerService, SnackbarService, diff --git a/src/app/register/components/form-password/form-password.component.ts b/src/app/register/components/form-password/form-password.component.ts index 2485228992..7bfe8c105c 100644 --- a/src/app/register/components/form-password/form-password.component.ts +++ b/src/app/register/components/form-password/form-password.component.ts @@ -16,7 +16,7 @@ import { Validators, } from '@angular/forms' import { HAS_LETTER_OR_SYMBOL, HAS_NUMBER } from 'src/app/constants' -import { Register2Service } from 'src/app/core/register2/register2.service' +import { RegisterService } from 'src/app/core/register/register.service' import { RegisterForm } from 'src/app/types/register.endpoint' import { OrcidValidators } from 'src/app/validators' @@ -34,8 +34,8 @@ import { takeUntil } from 'rxjs/operators' styleUrls: [ './form-password.component.scss-theme.scss', './form-password.component.scss', - '../register2.scss-theme.scss', - '../register2.style.scss', + '../register.scss-theme.scss', + '../register.style.scss', ], providers: [ { @@ -80,7 +80,7 @@ export class FormPasswordComponent _currentAccesibilityError: string destroy = new Subject() constructor( - private _register: Register2Service, + private _register: RegisterService, private _liveAnnouncer: LiveAnnouncer, private _changeDetectorRef: ChangeDetectorRef, private _registerObservability: RegisterObservabilityService, diff --git a/src/app/register/components/form-personal-additional-emails/form-personal-additional-emails.component.ts b/src/app/register/components/form-personal-additional-emails/form-personal-additional-emails.component.ts index eefa8cb846..43d1a66e9f 100644 --- a/src/app/register/components/form-personal-additional-emails/form-personal-additional-emails.component.ts +++ b/src/app/register/components/form-personal-additional-emails/form-personal-additional-emails.component.ts @@ -21,8 +21,8 @@ import { ErrorStateMatcherForFormLevelErrors } from '../../ErrorStateMatcherForF templateUrl: './form-personal-additional-emails.component.html', styleUrls: [ './form-personal-additional-emails.component.scss', - '../register2.style.scss', - '../register2.scss-theme.scss', + '../register.style.scss', + '../register.scss-theme.scss', ], }) export class FormPersonalAdditionalEmailsComponent implements AfterViewInit { diff --git a/src/app/register/components/form-personal/form-personal.component.spec.ts b/src/app/register/components/form-personal/form-personal.component.spec.ts index 8cfe5e01e3..08f601792a 100644 --- a/src/app/register/components/form-personal/form-personal.component.spec.ts +++ b/src/app/register/components/form-personal/form-personal.component.spec.ts @@ -11,7 +11,7 @@ import { SnackbarService } from '../../../cdk/snackbar/snackbar.service' import { WINDOW_PROVIDERS } from '../../../cdk/window' import { ErrorHandlerService } from '../../../core/error-handler/error-handler.service' import { ReactivationService } from '../../../core/reactivation/reactivation.service' -import { Register2Service } from '../../../core/register2/register2.service' +import { RegisterService } from '../../../core/register/register.service' import { FormPersonalComponent } from './form-personal.component' import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' @@ -27,7 +27,7 @@ describe('FormPersonalComponent', () => { providers: [ WINDOW_PROVIDERS, ReactivationService, - Register2Service, + RegisterService, PlatformInfoService, ErrorHandlerService, SnackbarService, diff --git a/src/app/register/components/form-personal/form-personal.component.ts b/src/app/register/components/form-personal/form-personal.component.ts index c9a7b3e3fc..c77da05083 100644 --- a/src/app/register/components/form-personal/form-personal.component.ts +++ b/src/app/register/components/form-personal/form-personal.component.ts @@ -20,7 +20,7 @@ import { ValidatorFn, Validators, } from '@angular/forms' -import { Register2Service } from 'src/app/core/register2/register2.service' +import { RegisterService } from 'src/app/core/register/register.service' import { OrcidValidators } from 'src/app/validators' import { @@ -73,8 +73,8 @@ export class MyErrorStateMatcher implements ErrorStateMatcher { templateUrl: './form-personal.component.html', styleUrls: [ './form-personal.component.scss', - '../register2.style.scss', - '../register2.scss-theme.scss', + '../register.style.scss', + '../register.scss-theme.scss', ], preserveWhitespaces: true, providers: [ @@ -114,7 +114,7 @@ export class FormPersonalComponent destroy = new Subject() constructor( - private _register: Register2Service, + private _register: RegisterService, private _reactivationService: ReactivationService, private _platform: PlatformInfoService, private _router: Router, diff --git a/src/app/register/components/form-terms/form-terms.component.spec.ts b/src/app/register/components/form-terms/form-terms.component.spec.ts index eebdb88b4d..de1d40d1eb 100644 --- a/src/app/register/components/form-terms/form-terms.component.spec.ts +++ b/src/app/register/components/form-terms/form-terms.component.spec.ts @@ -9,7 +9,7 @@ import { PlatformInfoService } from '../../../cdk/platform-info' import { SnackbarService } from '../../../cdk/snackbar/snackbar.service' import { WINDOW_PROVIDERS } from '../../../cdk/window' import { ErrorHandlerService } from '../../../core/error-handler/error-handler.service' -import { Register2Service } from '../../../core/register2/register2.service' +import { RegisterService } from '../../../core/register/register.service' import { FormTermsComponent } from './form-terms.component' import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' @@ -24,7 +24,7 @@ describe('FormTermsComponent', () => { declarations: [FormTermsComponent], providers: [ WINDOW_PROVIDERS, - Register2Service, + RegisterService, PlatformInfoService, ErrorHandlerService, SnackbarService, diff --git a/src/app/register/components/form-terms/form-terms.component.ts b/src/app/register/components/form-terms/form-terms.component.ts index 4dd9ed5132..c739726712 100644 --- a/src/app/register/components/form-terms/form-terms.component.ts +++ b/src/app/register/components/form-terms/form-terms.component.ts @@ -7,7 +7,7 @@ import { Validators, } from '@angular/forms' import { ErrorStateMatcher } from '@angular/material/core' -import { Register2Service } from 'src/app/core/register2/register2.service' +import { RegisterService } from 'src/app/core/register/register.service' import { environment } from 'src/environments/environment' import { BaseForm } from '../BaseForm' @@ -18,8 +18,8 @@ import { RegisterStateService } from '../../register-state.service' templateUrl: './form-terms.component.html', styleUrls: [ './form-terms.component.scss', - '../register2.style.scss', - '../register2.scss-theme.scss', + '../register.style.scss', + '../register.scss-theme.scss', ], providers: [ { @@ -40,7 +40,7 @@ export class FormTermsComponent extends BaseForm implements OnInit, DoCheck { nextButtonWasClicked: boolean environment = environment constructor( - private _register: Register2Service, + private _register: RegisterService, private _errorStateMatcher: ErrorStateMatcher, private _registerStateService: RegisterStateService ) { diff --git a/src/app/register/components/form-visibility/form-visibility.component.spec.ts b/src/app/register/components/form-visibility/form-visibility.component.spec.ts index 22745949f6..898eea1391 100644 --- a/src/app/register/components/form-visibility/form-visibility.component.spec.ts +++ b/src/app/register/components/form-visibility/form-visibility.component.spec.ts @@ -9,7 +9,7 @@ import { PlatformInfoService } from '../../../cdk/platform-info' import { SnackbarService } from '../../../cdk/snackbar/snackbar.service' import { WINDOW_PROVIDERS } from '../../../cdk/window' import { ErrorHandlerService } from '../../../core/error-handler/error-handler.service' -import { Register2Service } from '../../../core/register2/register2.service' +import { RegisterService } from '../../../core/register/register.service' import { FormVisibilityComponent } from './form-visibility.component' import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' @@ -24,7 +24,7 @@ describe('FormVisibilityComponent', () => { declarations: [FormVisibilityComponent], providers: [ WINDOW_PROVIDERS, - Register2Service, + RegisterService, PlatformInfoService, ErrorHandlerService, SnackbarService, diff --git a/src/app/register/components/form-visibility/form-visibility.component.ts b/src/app/register/components/form-visibility/form-visibility.component.ts index c1cb29ed26..3af68bf88b 100644 --- a/src/app/register/components/form-visibility/form-visibility.component.ts +++ b/src/app/register/components/form-visibility/form-visibility.component.ts @@ -14,7 +14,7 @@ import { } from '@angular/forms' import { ErrorStateMatcher } from '@angular/material/core' import { VISIBILITY_OPTIONS } from 'src/app/constants' -import { Register2Service } from 'src/app/core/register2/register2.service' +import { RegisterService } from 'src/app/core/register/register.service' import { BaseForm } from '../BaseForm' import { RegisterStateService } from '../../register-state.service' @@ -27,8 +27,8 @@ import { takeUntil } from 'rxjs/operators' templateUrl: './form-visibility.component.html', styleUrls: [ './form-visibility.component.scss', - '../register2.style.scss', - '../register2.scss-theme.scss', + '../register.style.scss', + '../register.scss-theme.scss', ], preserveWhitespaces: true, providers: [ @@ -54,7 +54,7 @@ export class FormVisibilityComponent activitiesVisibilityDefault = new UntypedFormControl('', Validators.required) destroy = new Subject() constructor( - private _register: Register2Service, + private _register: RegisterService, private _errorStateMatcher: ErrorStateMatcher, private _registerStateService: RegisterStateService, private _registerObservability: RegisterObservabilityService diff --git a/src/app/register/components/step-a/step-a.component.ts b/src/app/register/components/step-a/step-a.component.ts index b6a4dc9f40..67863306a4 100644 --- a/src/app/register/components/step-a/step-a.component.ts +++ b/src/app/register/components/step-a/step-a.component.ts @@ -22,8 +22,8 @@ import { RegisterObservabilityService } from '../../register-observability.servi templateUrl: './step-a.component.html', styleUrls: [ './step-a.component.scss', - '../register2.style.scss', - '../register2.scss-theme.scss', + '../register.style.scss', + '../register.scss-theme.scss', ], preserveWhitespaces: true, }) diff --git a/src/app/register/components/step-b/step-b.component.ts b/src/app/register/components/step-b/step-b.component.ts index 03cc0971a1..94a6c894e3 100644 --- a/src/app/register/components/step-b/step-b.component.ts +++ b/src/app/register/components/step-b/step-b.component.ts @@ -10,8 +10,8 @@ import { RegisterObservabilityService } from '../../register-observability.servi templateUrl: './step-b.component.html', styleUrls: [ './step-b.component.scss', - '../register2.style.scss', - '../register2.scss-theme.scss', + '../register.style.scss', + '../register.scss-theme.scss', ], }) export class StepBComponent extends BaseStepDirective implements OnInit { diff --git a/src/app/register/components/step-c/step-c.component.ts b/src/app/register/components/step-c/step-c.component.ts index 66abd4b3fc..0905f31c1b 100644 --- a/src/app/register/components/step-c/step-c.component.ts +++ b/src/app/register/components/step-c/step-c.component.ts @@ -10,8 +10,8 @@ import { RegisterObservabilityService } from '../../register-observability.servi templateUrl: './step-c.component.html', styleUrls: [ './step-c.component.scss', - '../register2.style.scss', - '../register2.scss-theme.scss', + '../register.style.scss', + '../register.scss-theme.scss', ], }) export class StepCComponent extends BaseStepDirective implements OnInit { diff --git a/src/app/register/components/step-c2/step-c2.component.ts b/src/app/register/components/step-c2/step-c2.component.ts index 1e679c8310..45e37cc0a4 100644 --- a/src/app/register/components/step-c2/step-c2.component.ts +++ b/src/app/register/components/step-c2/step-c2.component.ts @@ -11,8 +11,8 @@ import { RegisterObservabilityService } from '../../register-observability.servi templateUrl: './step-c2.component.html', styleUrls: [ './step-c2.component.scss', - '../register2.style.scss', - '../register2.scss-theme.scss', + '../register.style.scss', + '../register.scss-theme.scss', ], }) export class StepC2Component extends BaseStepDirective implements OnInit { diff --git a/src/app/register/components/step-d/step-d.component.ts b/src/app/register/components/step-d/step-d.component.ts index 5263881dda..3540cb5bf2 100644 --- a/src/app/register/components/step-d/step-d.component.ts +++ b/src/app/register/components/step-d/step-d.component.ts @@ -10,8 +10,8 @@ import { RegisterObservabilityService } from '../../register-observability.servi templateUrl: './step-d.component.html', styleUrls: [ './step-d.component.scss', - '../register2.style.scss', - '../register2.scss-theme.scss', + '../register.style.scss', + '../register.scss-theme.scss', ], }) export class StepDComponent extends BaseStepDirective { diff --git a/src/app/register/pages/register/register.component.ts b/src/app/register/pages/register/register.component.ts index b0569f80b7..3158896bba 100644 --- a/src/app/register/pages/register/register.component.ts +++ b/src/app/register/pages/register/register.component.ts @@ -18,7 +18,7 @@ import { WINDOW } from 'src/app/cdk/window' import { isRedirectToTheAuthorizationPage } from 'src/app/constants' import { UserService } from 'src/app/core' import { ErrorHandlerService } from 'src/app/core/error-handler/error-handler.service' -import { Register2Service } from 'src/app/core/register2/register2.service' +import { RegisterService } from 'src/app/core/register/register.service' import { ERROR_REPORT } from 'src/app/errors' import { RequestInfoForm } from 'src/app/types' import { @@ -76,7 +76,7 @@ export class RegisterComponent implements OnInit, AfterViewInit { private _cdref: ChangeDetectorRef, private _platformInfo: PlatformInfoService, private _formBuilder: UntypedFormBuilder, - private _register: Register2Service, + private _register: RegisterService, @Inject(WINDOW) private window: Window, private _googleTagManagerService: GoogleTagManagerService, private _router: Router,