mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
69432: Fix being able to send invalid password form + 6 character password validator
This commit is contained in:
@@ -1449,6 +1449,8 @@
|
|||||||
|
|
||||||
"profile.security.form.error.matching-passwords": "The passwords do not match.",
|
"profile.security.form.error.matching-passwords": "The passwords do not match.",
|
||||||
|
|
||||||
|
"profile.security.form.error.password-length": "The password should be at least 6 characters long.",
|
||||||
|
|
||||||
"profile.security.form.info": "Optionally, you can enter a new password in the box below, and confirm it by typing it again into the second box. It should be at least six characters long.",
|
"profile.security.form.info": "Optionally, you can enter a new password in the box below, and confirm it by typing it again into the second box. It should be at least six characters long.",
|
||||||
|
|
||||||
"profile.security.form.label.password": "Password",
|
"profile.security.form.label.password": "Password",
|
||||||
@@ -1461,6 +1463,8 @@
|
|||||||
|
|
||||||
"profile.security.form.notifications.error.title": "Error changing passwords",
|
"profile.security.form.notifications.error.title": "Error changing passwords",
|
||||||
|
|
||||||
|
"profile.security.form.notifications.error.not-long-enough": "The password has to be at least 6 characters long.",
|
||||||
|
|
||||||
"profile.security.form.notifications.error.not-same": "The provided passwords are not the same.",
|
"profile.security.form.notifications.error.not-same": "The provided passwords are not the same.",
|
||||||
|
|
||||||
"profile.title": "Update Profile",
|
"profile.title": "Update Profile",
|
||||||
|
@@ -5,4 +5,5 @@
|
|||||||
[formGroup]="formGroup"
|
[formGroup]="formGroup"
|
||||||
[displaySubmit]="false">
|
[displaySubmit]="false">
|
||||||
</ds-form>
|
</ds-form>
|
||||||
|
<div class="container-fluid text-danger" *ngIf="formGroup.hasError('notLongEnough')">{{'profile.security.form.error.password-length' | translate}}</div>
|
||||||
<div class="container-fluid text-danger" *ngIf="formGroup.hasError('notSame')">{{'profile.security.form.error.matching-passwords' | translate}}</div>
|
<div class="container-fluid text-danger" *ngIf="formGroup.hasError('notSame')">{{'profile.security.form.error.matching-passwords' | translate}}</div>
|
||||||
|
@@ -80,14 +80,14 @@ describe('ProfilePageSecurityFormComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when both password fields are filled in and equal', () => {
|
describe('when both password fields are filled in, long enough and equal', () => {
|
||||||
let result;
|
let result;
|
||||||
let operations;
|
let operations;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
setModelValue('password', 'test');
|
setModelValue('password', 'testest');
|
||||||
setModelValue('passwordrepeat', 'test');
|
setModelValue('passwordrepeat', 'testest');
|
||||||
operations = [{ op: 'replace', path: '/password', value: 'test' }];
|
operations = [{ op: 'replace', path: '/password', value: 'testest' }];
|
||||||
result = component.updateSecurity();
|
result = component.updateSecurity();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -64,7 +64,7 @@ export class ProfilePageSecurityFormComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.formGroup = this.formService.createFormGroup(this.formModel, { validators: this.checkPasswords });
|
this.formGroup = this.formService.createFormGroup(this.formModel, { validators: [this.checkPasswordsEqual, this.checkPasswordLength] });
|
||||||
this.updateFieldTranslations();
|
this.updateFieldTranslations();
|
||||||
this.translate.onLangChange
|
this.translate.onLangChange
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
@@ -87,11 +87,21 @@ export class ProfilePageSecurityFormComponent implements OnInit {
|
|||||||
* Check if both password fields are filled in and equal
|
* Check if both password fields are filled in and equal
|
||||||
* @param group The FormGroup to validate
|
* @param group The FormGroup to validate
|
||||||
*/
|
*/
|
||||||
checkPasswords(group: FormGroup) {
|
checkPasswordsEqual(group: FormGroup) {
|
||||||
const pass = group.get('password').value;
|
const pass = group.get('password').value;
|
||||||
const repeatPass = group.get('passwordrepeat').value;
|
const repeatPass = group.get('passwordrepeat').value;
|
||||||
|
|
||||||
return isEmpty(repeatPass) || pass === repeatPass ? null : { notSame: true };
|
return pass === repeatPass ? null : { notSame: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the password is at least 6 characters long
|
||||||
|
* @param group The FormGroup to validate
|
||||||
|
*/
|
||||||
|
checkPasswordLength(group: FormGroup) {
|
||||||
|
const pass = group.get('password').value;
|
||||||
|
|
||||||
|
return isEmpty(pass) || pass.length >= 6 ? null : { notLongEnough: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,7 +119,12 @@ export class ProfilePageSecurityFormComponent implements OnInit {
|
|||||||
const passEntered = isNotEmpty(pass);
|
const passEntered = isNotEmpty(pass);
|
||||||
if (!this.formGroup.valid) {
|
if (!this.formGroup.valid) {
|
||||||
if (passEntered) {
|
if (passEntered) {
|
||||||
this.notificationsService.error(this.translate.instant(this.NOTIFICATIONS_PREFIX + 'error.not-same'));
|
if (this.checkPasswordsEqual(this.formGroup) != null) {
|
||||||
|
this.notificationsService.error(this.translate.instant(this.NOTIFICATIONS_PREFIX + 'error.not-same'));
|
||||||
|
}
|
||||||
|
if (this.checkPasswordLength(this.formGroup) != null) {
|
||||||
|
this.notificationsService.error(this.translate.instant(this.NOTIFICATIONS_PREFIX + 'error.not-long-enough'));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user