diff --git a/src/app/profile-page/profile-page-security-form/profile-page-security-form.component.html b/src/app/profile-page/profile-page-security-form/profile-page-security-form.component.html index 7c1dff5bdf..66c9d73be2 100644 --- a/src/app/profile-page/profile-page-security-form/profile-page-security-form.component.html +++ b/src/app/profile-page/profile-page-security-form/profile-page-security-form.component.html @@ -9,3 +9,4 @@
{{FORM_PREFIX + 'error.password-length' | translate}}
{{FORM_PREFIX + 'error.matching-passwords' | translate}}
{{FORM_PREFIX + 'error.empty-password' | translate}}
+
{{FORM_PREFIX + 'error.robust-password' | translate}}
diff --git a/src/app/profile-page/profile-page-security-form/profile-page-security-form.component.spec.ts b/src/app/profile-page/profile-page-security-form/profile-page-security-form.component.spec.ts index 213a83b86e..e8fd4740eb 100644 --- a/src/app/profile-page/profile-page-security-form/profile-page-security-form.component.spec.ts +++ b/src/app/profile-page/profile-page-security-form/profile-page-security-form.component.spec.ts @@ -9,6 +9,7 @@ import { FormBuilderService } from '../../shared/form/builder/form-builder.servi import { ProfilePageSecurityFormComponent } from './profile-page-security-form.component'; import { of as observableOf } from 'rxjs'; import { RestResponse } from '../../core/cache/response.models'; +import { By } from '@angular/platform-browser'; describe('ProfilePageSecurityFormComponent', () => { let component: ProfilePageSecurityFormComponent; @@ -76,4 +77,16 @@ describe('ProfilePageSecurityFormComponent', () => { })); }); }); + + describe('On robust password Error', () => { + it('should show/hide robust password error', () => { + component.isRobustPasswordError = true; + fixture.detectChanges(); + expect(fixture.debugElement.query(By.css('[data-test="robust-password-error"]'))).toBeTruthy(); + + component.isRobustPasswordError = false; + fixture.detectChanges(); + expect(fixture.debugElement.query(By.css('[data-test="robust-password-error"]'))).toBeFalsy(); + }) + }); }); diff --git a/src/app/profile-page/profile-page-security-form/profile-page-security-form.component.ts b/src/app/profile-page/profile-page-security-form/profile-page-security-form.component.ts index 4f310204e3..1eacb9f1be 100644 --- a/src/app/profile-page/profile-page-security-form/profile-page-security-form.component.ts +++ b/src/app/profile-page/profile-page-security-form/profile-page-security-form.component.ts @@ -60,6 +60,12 @@ export class ProfilePageSecurityFormComponent implements OnInit { */ @Input() FORM_PREFIX: string; + + /** + * monitor to password is weak or not from server response + */ + @Input() + isRobustPasswordError: boolean; private subs: Subscription[] = []; constructor(protected formService: DynamicFormService, diff --git a/src/app/profile-page/profile-page.component.html b/src/app/profile-page/profile-page.component.html index 6e22f73a75..63c34d02b3 100644 --- a/src/app/profile-page/profile-page.component.html +++ b/src/app/profile-page/profile-page.component.html @@ -24,6 +24,7 @@ [FORM_PREFIX]="'profile.security.form.'" (isInvalid)="setInvalid($event)" (passwordValue)="setPasswordValue($event)" + [isRobustPasswordError]="isRobustPasswordError | async" > diff --git a/src/app/profile-page/profile-page.component.ts b/src/app/profile-page/profile-page.component.ts index 5629a1ae18..5762192e92 100644 --- a/src/app/profile-page/profile-page.component.ts +++ b/src/app/profile-page/profile-page.component.ts @@ -73,6 +73,7 @@ export class ProfilePageComponent implements OnInit { */ private currentUser: EPerson; canChangePassword$: Observable; + isRobustPasswordError: BehaviorSubject = new BehaviorSubject(false); isResearcherProfileEnabled$: BehaviorSubject = new BehaviorSubject(false); @@ -147,7 +148,9 @@ export class ProfilePageComponent implements OnInit { this.epersonService.patch(this.currentUser, [operation]).pipe( getFirstCompletedRemoteData() ).subscribe((response: RemoteData) => { - if (response.hasSucceeded) { + if (response.statusCode === 422) { + this.isRobustPasswordError.next(true); + } else if (response.hasSucceeded) { this.notificationsService.success( this.translate.instant(this.PASSWORD_NOTIFICATIONS_PREFIX + 'success.title'), this.translate.instant(this.PASSWORD_NOTIFICATIONS_PREFIX + 'success.content') diff --git a/src/app/register-page/create-profile/create-profile.component.html b/src/app/register-page/create-profile/create-profile.component.html index f56059ad69..5ef17c6b64 100644 --- a/src/app/register-page/create-profile/create-profile.component.html +++ b/src/app/register-page/create-profile/create-profile.component.html @@ -73,6 +73,7 @@ [FORM_PREFIX]="'register-page.create-profile.security.'" (isInvalid)="setInValid($event)" (passwordValue)="setPasswordValue($event)" + [isRobustPasswordError]="isRobustPasswordError | async" > diff --git a/src/app/register-page/create-profile/create-profile.component.spec.ts b/src/app/register-page/create-profile/create-profile.component.spec.ts index b95e380e08..d2d4c4c0ee 100644 --- a/src/app/register-page/create-profile/create-profile.component.spec.ts +++ b/src/app/register-page/create-profile/create-profile.component.spec.ts @@ -238,6 +238,24 @@ describe('CreateProfileComponent', () => { expect(router.navigate).not.toHaveBeenCalled(); expect(notificationsService.error).toHaveBeenCalled(); }); + + it('should submit an eperson for creation but password is weak', () => { + + (ePersonDataService.createEPersonForToken as jasmine.Spy).and.returnValue(createFailedRemoteDataObject$('Error', 422)); + + comp.firstName.patchValue('First'); + comp.lastName.patchValue('Last'); + comp.contactPhone.patchValue('Phone'); + comp.language.patchValue('en'); + comp.password = 'password'; + comp.isInValidPassword = false; + + comp.submitEperson(); + + expect(ePersonDataService.createEPersonForToken).toHaveBeenCalledWith(eperson, 'test-token'); + expect(comp.isRobustPasswordError.value).toBeTrue(); + }); + it('should submit not create an eperson when the user info form is invalid', () => { (ePersonDataService.createEPersonForToken as jasmine.Spy).and.returnValue(createFailedRemoteDataObject$('Error', 500)); diff --git a/src/app/register-page/create-profile/create-profile.component.ts b/src/app/register-page/create-profile/create-profile.component.ts index d042e63ece..ff71e1ee01 100644 --- a/src/app/register-page/create-profile/create-profile.component.ts +++ b/src/app/register-page/create-profile/create-profile.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { map } from 'rxjs/operators'; import { Registration } from '../../core/shared/registration.model'; -import { Observable } from 'rxjs'; +import { BehaviorSubject, Observable } from 'rxjs'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { TranslateService } from '@ngx-translate/core'; import { EPersonDataService } from '../../core/eperson/eperson-data.service'; @@ -40,7 +40,7 @@ export class CreateProfileComponent implements OnInit { userInfoForm: FormGroup; activeLangs: LangConfig[]; - + isRobustPasswordError: BehaviorSubject = new BehaviorSubject(false); constructor( private translateService: TranslateService, private ePersonDataService: EPersonDataService, @@ -160,7 +160,9 @@ export class CreateProfileComponent implements OnInit { this.ePersonDataService.createEPersonForToken(eperson, this.token).pipe( getFirstCompletedRemoteData(), ).subscribe((rd: RemoteData) => { - if (rd.hasSucceeded) { + if (rd.statusCode === 422) { + this.isRobustPasswordError.next(true); + } else if (rd.hasSucceeded) { this.notificationsService.success(this.translateService.get('register-page.create-profile.submit.success.head'), this.translateService.get('register-page.create-profile.submit.success.content')); this.store.dispatch(new AuthenticateAction(this.email, this.password)); diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index cb664e19f7..bf5ccb4f06 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -3056,6 +3056,8 @@ "profile.security.form.notifications.error.not-same": "The provided passwords are not the same.", + "profile.security.form.notifications.error.robust-password": "Please select a more robust password.", + "profile.title": "Update Profile", "profile.card.researcher": "Researcher Profile", @@ -3146,6 +3148,8 @@ "register-page.create-profile.security.error.empty-password": "Please enter a password in the box below.", + "register-page.create-profile.security.error.robust-password": "Please select a more robust password.", + "register-page.create-profile.security.error.matching-passwords": "The passwords do not match.", "register-page.create-profile.security.error.password-length": "The password should be at least 6 characters long.",