mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 22:13:02 +00:00
CST-6153 changes for current password field introduce
This commit is contained in:
@@ -74,6 +74,19 @@ describe('ProfilePageSecurityFormComponent', () => {
|
||||
|
||||
expect(component.passwordValue.emit).toHaveBeenCalledWith('new-password');
|
||||
}));
|
||||
|
||||
it('should emit the value on password change with current password for profile-page', fakeAsync(() => {
|
||||
spyOn(component.passwordValue, 'emit');
|
||||
spyOn(component.currentPasswordValue, 'emit');
|
||||
component.FORM_PREFIX = 'profile.security.form.';
|
||||
component.ngOnInit();
|
||||
component.formGroup.patchValue({password: 'new-password'});
|
||||
component.formGroup.patchValue({'current-password': 'current-password'});
|
||||
tick(300);
|
||||
|
||||
expect(component.passwordValue.emit).toHaveBeenCalledWith('new-password');
|
||||
expect(component.currentPasswordValue.emit).toHaveBeenCalledWith('current-password');
|
||||
}))
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -27,6 +27,10 @@ export class ProfilePageSecurityFormComponent implements OnInit {
|
||||
* Emits the value of the password
|
||||
*/
|
||||
@Output() passwordValue = new EventEmitter<string>();
|
||||
/**
|
||||
* Emits the value of the current-password
|
||||
*/
|
||||
@Output() currentPasswordValue = new EventEmitter<string>();
|
||||
|
||||
/**
|
||||
* The form's input models
|
||||
@@ -69,6 +73,14 @@ export class ProfilePageSecurityFormComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.FORM_PREFIX === 'profile.security.form.') {
|
||||
this.formModel.unshift(new DynamicInputModel({
|
||||
id: 'current-password',
|
||||
name: 'current-password',
|
||||
inputType: 'password',
|
||||
required: true
|
||||
}));
|
||||
}
|
||||
if (this.passwordCanBeEmpty) {
|
||||
this.formGroup = this.formService.createFormGroup(this.formModel,
|
||||
{validators: [this.checkPasswordsEqual, this.checkPasswordLength]});
|
||||
@@ -85,11 +97,7 @@ export class ProfilePageSecurityFormComponent implements OnInit {
|
||||
this.subs.push(this.formGroup.statusChanges.pipe(
|
||||
debounceTime(300),
|
||||
map((status: string) => {
|
||||
if (status !== 'VALID') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return status !== 'VALID';
|
||||
})).subscribe((status) => this.isInvalid.emit(status))
|
||||
);
|
||||
|
||||
@@ -97,6 +105,9 @@ export class ProfilePageSecurityFormComponent implements OnInit {
|
||||
debounceTime(300),
|
||||
).subscribe((valueChange) => {
|
||||
this.passwordValue.emit(valueChange.password);
|
||||
if (this.FORM_PREFIX === 'profile.security.form.') {
|
||||
this.currentPasswordValue.emit(valueChange['current-password']);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
@@ -24,6 +24,7 @@
|
||||
[FORM_PREFIX]="'profile.security.form.'"
|
||||
(isInvalid)="setInvalid($event)"
|
||||
(passwordValue)="setPasswordValue($event)"
|
||||
(currentPasswordValue)="setCurrentPasswordValue($event)"
|
||||
></ds-profile-page-security-form>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -180,7 +180,7 @@ describe('ProfilePageComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.setPasswordValue('');
|
||||
|
||||
component.setCurrentPasswordValue('current-password');
|
||||
result = component.updateSecurity();
|
||||
});
|
||||
|
||||
@@ -199,6 +199,7 @@ describe('ProfilePageComponent', () => {
|
||||
beforeEach(() => {
|
||||
component.setPasswordValue('test');
|
||||
component.setInvalid(true);
|
||||
component.setCurrentPasswordValue('current-password');
|
||||
result = component.updateSecurity();
|
||||
});
|
||||
|
||||
@@ -215,8 +216,12 @@ describe('ProfilePageComponent', () => {
|
||||
beforeEach(() => {
|
||||
component.setPasswordValue('testest');
|
||||
component.setInvalid(false);
|
||||
component.setCurrentPasswordValue('current-password');
|
||||
|
||||
operations = [{ op: 'add', path: '/password', value: 'testest' }];
|
||||
operations = [
|
||||
{ op: 'add', path: '/password', value: 'testest' },
|
||||
{ op: 'add', path: '/challenge', value: 'current-password' }
|
||||
];
|
||||
result = component.updateSecurity();
|
||||
});
|
||||
|
||||
|
@@ -67,6 +67,10 @@ export class ProfilePageComponent implements OnInit {
|
||||
* The password filled in, in the security form
|
||||
*/
|
||||
private password: string;
|
||||
/**
|
||||
* The current-password filled in, in the security form
|
||||
*/
|
||||
private currentPassword: string;
|
||||
|
||||
/**
|
||||
* The authenticated user
|
||||
@@ -138,15 +142,15 @@ export class ProfilePageComponent implements OnInit {
|
||||
*/
|
||||
updateSecurity() {
|
||||
const passEntered = isNotEmpty(this.password);
|
||||
|
||||
if (this.invalidSecurity) {
|
||||
this.notificationsService.error(this.translate.instant(this.PASSWORD_NOTIFICATIONS_PREFIX + 'error.general'));
|
||||
}
|
||||
if (!this.invalidSecurity && passEntered) {
|
||||
const operation = {op: 'add', path: '/password', value: this.password} as Operation;
|
||||
this.epersonService.patch(this.currentUser, [operation]).pipe(
|
||||
getFirstCompletedRemoteData()
|
||||
).subscribe((response: RemoteData<EPerson>) => {
|
||||
const operations = [
|
||||
{ op: 'add', path: '/password', value: this.password },
|
||||
{ op: 'add', path: '/challenge', value: this.currentPassword }
|
||||
] as Operation[];
|
||||
this.epersonService.patch(this.currentUser, operations).pipe(getFirstCompletedRemoteData()).subscribe((response: RemoteData<EPerson>) => {
|
||||
if (response.hasSucceeded) {
|
||||
this.notificationsService.success(
|
||||
this.translate.instant(this.PASSWORD_NOTIFICATIONS_PREFIX + 'success.title'),
|
||||
@@ -170,6 +174,14 @@ export class ProfilePageComponent implements OnInit {
|
||||
this.password = $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current-password value based on the value emitted from the security form
|
||||
* @param $event
|
||||
*/
|
||||
setCurrentPasswordValue($event: string) {
|
||||
this.currentPassword = $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit of the security form that triggers the updateProfile method
|
||||
*/
|
||||
|
@@ -3046,6 +3046,8 @@
|
||||
|
||||
"profile.security.form.label.passwordrepeat": "Retype to confirm",
|
||||
|
||||
"profile.security.form.label.current-password": "Current password",
|
||||
|
||||
"profile.security.form.notifications.success.content": "Your changes to the password were saved.",
|
||||
|
||||
"profile.security.form.notifications.success.title": "Password saved",
|
||||
|
Reference in New Issue
Block a user