2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 import {Component, OnInit} from '@angular/core';
21 import {AbstractControl, FormBuilder, FormControl, FormGroup, ValidationErrors, ValidatorFn} from '@angular/forms';
22 import {UserService} from "../../../../services/user.service";
23 import {ErrorResult} from "../../../../model/error-result";
24 import {catchError} from "rxjs/operators";
25 import {UserInfo} from "../../../../model/user-info";
26 import {ManageUsersBaseComponent} from "../manage-users-base.component";
29 selector: 'app-manage-users-add',
30 templateUrl: './manage-users-add.component.html',
31 styleUrls: ['./manage-users-add.component.scss']
33 export class ManageUsersAddComponent extends ManageUsersBaseComponent implements OnInit {
35 constructor(userService: UserService, fb: FormBuilder) {
36 super(userService, fb);
44 // Process checkout data here
46 if (this.userForm.valid) {
47 let user = this.copyFromForm(this.editProperties);
48 console.info('Adding user ' + user);
49 this.userService.addUser(user).pipe(catchError((error: ErrorResult) => {
50 // console.log("Error " + error + " - " + typeof (error) + " - " + JSON.stringify(error));
51 if (error.status == 422) {
52 // console.warn("Validation error");
54 for (let message of error.error_messages) {
55 if (message.error_key.startsWith('user.password.violation')) {
56 pwdErrors[message.error_key] = message.message;
59 this.userForm.get('password').setErrors(pwdErrors);
62 this.errorResult = error;
66 // return throwError(error);
67 })).subscribe((user: UserInfo) => {
71 this.userForm.reset(this.formInitialValues);