mirror of
https://github.com/ceph/ceph
synced 2024-12-27 14:03:25 +00:00
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:
commit
c7d602929a
@ -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>
|
||||
|
||||
|
@ -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: [
|
||||
'',
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user