username works!
This commit is contained in:
@@ -1,31 +1,35 @@
|
||||
|
||||
import { AbstractControl } from '@angular/forms';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { FormControl } from '@angular/forms';
|
||||
import { RegistrationService } from '../registration.service';
|
||||
|
||||
|
||||
export class ValidateUserName{
|
||||
|
||||
constructor(
|
||||
private RS: RegistrationService
|
||||
){ }
|
||||
|
||||
validateUserName( control: AbstractControl ){
|
||||
//var RS = new RegistrationService(null);
|
||||
/*
|
||||
this.registrationService2.validateUserName( control.value ).subscribe( data => {
|
||||
console.log( data );
|
||||
if( control.value != data.username ){
|
||||
return{
|
||||
validUserName: true
|
||||
};
|
||||
}
|
||||
return null;
|
||||
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class UsernameValidator {
|
||||
|
||||
debouncer: any;
|
||||
|
||||
constructor(private registrationService: RegistrationService){
|
||||
|
||||
}
|
||||
|
||||
checkUsername(control: FormControl): any {
|
||||
|
||||
clearTimeout(this.debouncer);
|
||||
|
||||
return new Promise(resolve => {
|
||||
|
||||
this.debouncer = setTimeout(() => {
|
||||
|
||||
this.registrationService.validateUserName(control.value).subscribe((res) => {
|
||||
if(res.ok){
|
||||
resolve(null);
|
||||
}
|
||||
}, (err) => {
|
||||
resolve({'usernameInUse': true});
|
||||
});
|
||||
|
||||
}, 1000);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user