mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
CST-6110 changes for robust password error
This commit is contained in:
@@ -9,3 +9,4 @@
|
||||
<div id="notLongEnough" class="container-fluid text-danger" *ngIf="formGroup.hasError('notLongEnough')">{{FORM_PREFIX + 'error.password-length' | translate}}</div>
|
||||
<div id="notSame" class="container-fluid text-danger" *ngIf="formGroup.hasError('notSame')">{{FORM_PREFIX + 'error.matching-passwords' | translate}}</div>
|
||||
<div id="emptyPassword" class="container-fluid text-danger" *ngIf="(formGroup.dirty || formGroup.touched) && formGroup.hasError('emptyPassword')">{{FORM_PREFIX + 'error.empty-password' | translate}}</div>
|
||||
<div data-test="robust-password-error" class="container-fluid text-danger" *ngIf="isRobustPasswordError">{{FORM_PREFIX + 'error.robust-password' | translate}}</div>
|
||||
|
@@ -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();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
@@ -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,
|
||||
|
@@ -24,6 +24,7 @@
|
||||
[FORM_PREFIX]="'profile.security.form.'"
|
||||
(isInvalid)="setInvalid($event)"
|
||||
(passwordValue)="setPasswordValue($event)"
|
||||
[isRobustPasswordError]="isRobustPasswordError | async"
|
||||
></ds-profile-page-security-form>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -73,6 +73,7 @@ export class ProfilePageComponent implements OnInit {
|
||||
*/
|
||||
private currentUser: EPerson;
|
||||
canChangePassword$: Observable<boolean>;
|
||||
isRobustPasswordError: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
|
||||
isResearcherProfileEnabled$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
|
||||
@@ -147,7 +148,9 @@ export class ProfilePageComponent implements OnInit {
|
||||
this.epersonService.patch(this.currentUser, [operation]).pipe(
|
||||
getFirstCompletedRemoteData()
|
||||
).subscribe((response: RemoteData<EPerson>) => {
|
||||
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')
|
||||
|
@@ -73,6 +73,7 @@
|
||||
[FORM_PREFIX]="'register-page.create-profile.security.'"
|
||||
(isInvalid)="setInValid($event)"
|
||||
(passwordValue)="setPasswordValue($event)"
|
||||
[isRobustPasswordError]="isRobustPasswordError | async"
|
||||
></ds-profile-page-security-form>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -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));
|
||||
|
@@ -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<boolean> = new BehaviorSubject<boolean>(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<EPerson>) => {
|
||||
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));
|
||||
|
@@ -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.",
|
||||
|
Reference in New Issue
Block a user