Skip to content

Commit

Permalink
user: password validator
Browse files Browse the repository at this point in the history
The password is mandatory if the user is not loaded,
otherwise it is optional

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Dec 5, 2022
1 parent 222fb40 commit 9b41e1e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
54 changes: 54 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
},
"dependencies": {
"@angular/animations": "^14.2.6",
"@angular/cdk": "^14.2.7",
"@angular/common": "^14.2.6",
"@angular/compiler": "^14.2.6",
"@angular/core": "^14.2.6",
Expand All @@ -90,6 +91,7 @@
"easymde": "^2.18.0",
"font-awesome": "^4.7.0",
"issn": "^1.0.6",
"js-generate-password": "^0.1.7",
"lodash-es": "^4.17.21",
"marked": "^4.1.1",
"moment": "^2.29.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { Component, OnInit } from '@angular/core';
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { FormlyJsonschema } from '@ngx-formly/core/json-schema';
import { TranslateService } from '@ngx-translate/core';
Expand Down Expand Up @@ -54,6 +54,9 @@ export class UserIdEditorComponent implements OnInit {
/** Formly fields configuration populate by the JSONSchema */
fields: FormlyFieldConfig[];

/** Password field */
passwordField: FormlyFieldConfig;

/**
* Constructor
*
Expand Down Expand Up @@ -106,6 +109,12 @@ export class UserIdEditorComponent implements OnInit {
}
field.asyncValidators.uniqueUsername = this.getUniqueValidator('username');
}
if (field.key === 'password') {
if (!this.userID) {
field.templateOptions.required = true;
}
this.passwordField = field;
}
// remove Message suffix to the message validation key
// (required for backend translations)
if (field.validation) {
Expand Down Expand Up @@ -142,6 +151,7 @@ export class UserIdEditorComponent implements OnInit {
searchValueUpdated(query: (string | null)): void {
if (!query) {
this.loadedUserID = null;
this.passwordField.templateOptions.required = true;
this.form.reset();
this.model = {};
return;
Expand Down Expand Up @@ -179,6 +189,7 @@ export class UserIdEditorComponent implements OnInit {
this._translateService.instant('The personal data has been successfully linked to this patron.')
);
this.loadedUserID = model.id;
this.passwordField.templateOptions.required = false;
this.form.reset();
return this.model = model.metadata ? model.metadata : null;
}),
Expand Down

0 comments on commit 9b41e1e

Please sign in to comment.