Merge pull request #34587 from rhcs-dashboard/async_user_name

Reviewed-by: Ernesto Puerta <epuertat@redhat.com>
Reviewed-by: Tiago Melo <tmelo@suse.com>
Reviewed-by: Volker Theile <vtheile@suse.com>
This commit is contained in:
Lenz Grimmer 2020-04-29 14:00:11 +02:00 committed by GitHub
commit c7d602929a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -29,6 +29,9 @@
<span class="invalid-feedback"
*ngIf="userForm.showError('username', formDir, 'required')"
i18n>This field is required.</span>
<span class="invalid-feedback"
*ngIf="userForm.showError('username', formDir, 'notUnique')"
i18n>The username already exists.</span>
</div>
</div>

View File

@ -84,7 +84,11 @@ export class UserFormComponent implements OnInit {
});
this.userForm = this.formBuilder.group(
{
username: ['', [Validators.required]],
username: [
'',
[Validators.required],
[CdValidators.unique(this.userService.validateUserName, this.userService)]
],
name: [''],
password: [
'',

View File

@ -1,5 +1,7 @@
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, of as observableOf } from 'rxjs';
import { catchError, mapTo } from 'rxjs/operators';
import { UserFormModel } from '../../core/auth/user-form/user-form.model';
import { ApiModule } from './api.module';
@ -40,6 +42,16 @@ export class UserService {
});
}
validateUserName(user_name: string): Observable<boolean> {
return this.get(user_name).pipe(
mapTo(true),
catchError((error) => {
error.preventDefault();
return observableOf(false);
})
);
}
validatePassword(password: string, username: string = null, oldPassword: string = null) {
let params = new HttpParams();
params = params.append('password', password);