validation
This commit is contained in:
@@ -2717,7 +2717,7 @@ class PHP_CRUD_API {
|
||||
'dbengine'=>'MySQL',
|
||||
'hostname'=>'localhost',
|
||||
'username'=>'lazyp_workadmin',
|
||||
'password'=>'ZGmH0HQPo5ocbOuN',
|
||||
'password'=>'GH5fZF0iCtLnHLrz',
|
||||
'database'=>'LudosData',
|
||||
'charset'=>'utf8mb4'
|
||||
));
|
||||
|
||||
@@ -26,8 +26,6 @@ import { LoginComponent } from './login/login.component';
|
||||
import { RegisterComponent } from './register/register.component';
|
||||
|
||||
import { RegistrationService } from './registration.service';
|
||||
|
||||
//import { CreditCardValidator } from './creditcardvalidator.directive'
|
||||
import { UsernameValidator } from './validators/username.validator'
|
||||
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
import { Directive, forwardRef } from '@angular/core';
|
||||
import { NG_VALIDATORS, AbstractControl, ValidationErrors, Validator, FormControl } from '@angular/forms';
|
||||
|
||||
@Directive({
|
||||
selector: '[validCreditCard]',
|
||||
providers: [
|
||||
{ provide: NG_VALIDATORS, useExisting: CreditCardValidator, multi: true }
|
||||
]
|
||||
})
|
||||
export class CreditCardValidator implements Validator {
|
||||
|
||||
validate(c: FormControl): ValidationErrors | null {
|
||||
return CreditCardValidator.validateCcNumber(c);
|
||||
}
|
||||
|
||||
static validateCcNumber(control: FormControl): ValidationErrors | null {
|
||||
if (!(control.value.startsWith('37')
|
||||
|| control.value.startsWith('4')
|
||||
|| control.value.startsWith('5'))
|
||||
) {
|
||||
// Return error if card is not Amex, Visa or Mastercard
|
||||
return { creditCard: 'Your credit card number is not from a supported credit card provider' };
|
||||
} else if (control.value.length !== 16) {
|
||||
console.log(control.value)
|
||||
// Return error if length is not 16 digits
|
||||
return { creditCard: 'A credit card number must be 16-digit long' };
|
||||
}
|
||||
// If no error, return null
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
import { Directive, forwardRef } from '@angular/core';
|
||||
import { NG_VALIDATORS, AbstractControl, ValidationErrors, Validator, FormControl } from '@angular/forms';
|
||||
import { RegistrationService } from './registration.service';
|
||||
|
||||
@Directive({
|
||||
selector: '[validCreditCard]',
|
||||
providers: [
|
||||
{ provide: NG_VALIDATORS, useExisting: CreditCardValidatorX, multi: true }
|
||||
]
|
||||
})
|
||||
export class CreditCardValidatorX implements Validator {
|
||||
|
||||
constructor(
|
||||
private registrationService2: RegistrationService
|
||||
){ }
|
||||
|
||||
validate(c: FormControl): ValidationErrors | null {
|
||||
return CreditCardValidatorX.validateCcNumber(c);
|
||||
}
|
||||
|
||||
|
||||
validateUserName( control: FormControl ){
|
||||
|
||||
this.registrationService2.validateUserName( control.value ).subscribe( data => {
|
||||
console.log( data );
|
||||
if( control.value != data.username ){
|
||||
return{
|
||||
validUserName: true
|
||||
};
|
||||
}
|
||||
return null;
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
static validateCcNumber(control: FormControl): ValidationErrors | null {
|
||||
if (!(control.value.startsWith('37')
|
||||
|| control.value.startsWith('4')
|
||||
|| control.value.startsWith('5'))
|
||||
) {
|
||||
// Return error if card is not Amex, Visa or Mastercard
|
||||
return { creditCard: 'Your credit card number is not from a supported credit card provider' };
|
||||
} else if (control.value.length !== 16) {
|
||||
console.log(control.value)
|
||||
// Return error if length is not 16 digits
|
||||
return { creditCard: 'A credit card number must be 16-digit long' };
|
||||
}
|
||||
// If no error, return null
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ const httpOptionsPut = {
|
||||
@Injectable()
|
||||
export class GamesService {
|
||||
|
||||
APIURL = "http://192.241.155.78/ludosdata/api.php";
|
||||
APIURL = "http://192.241.155.78/api.php";
|
||||
|
||||
constructor(
|
||||
private http: HttpClient
|
||||
|
||||
@@ -6,8 +6,6 @@ import { RegistrationService } from '../registration.service';
|
||||
import { UsernameValidator } from '../validators/username.validator'
|
||||
|
||||
|
||||
//import { ValidateUserName } from '../validators/username.validator';
|
||||
|
||||
@Component({
|
||||
selector: 'app-register',
|
||||
templateUrl: './register.component.html',
|
||||
@@ -17,7 +15,6 @@ export class RegisterComponent implements OnInit {
|
||||
|
||||
form: any;
|
||||
loading = false;
|
||||
//userNameValidator = new UserNameValidator(null);
|
||||
|
||||
constructor(
|
||||
private registrationService: RegistrationService,
|
||||
@@ -79,8 +76,6 @@ export class RegisterComponent implements OnInit {
|
||||
}else if( key == "max" ) {
|
||||
formValidators.push(Validators.max(validators[key]));
|
||||
}else if( key == "ValidateUserName" ){
|
||||
//formValidators.push( this.validateUserName );
|
||||
//formValidators.push( CreditCardValidator.validateCcNumber );
|
||||
formValidators.push( this.usernameValidator.checkUsername.bind( this.usernameValidator ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'rxjs/add/operator/map';
|
||||
@Injectable()
|
||||
export class RegistrationService {
|
||||
|
||||
APIURL = "http://192.241.155.78/ludosdata/api.php";
|
||||
APIURL = "http://192.241.155.78/api.php";
|
||||
|
||||
constructor(
|
||||
private http: HttpClient
|
||||
@@ -25,8 +25,9 @@ export class RegistrationService {
|
||||
*/
|
||||
|
||||
validateUserName( userName ): Observable<any> {
|
||||
return this.http.get( this.APIURL + "/users?filter=email,cs," + userName + "&transform=1" )
|
||||
return this.http.get( this.APIURL + "/users?filter=userName,cs," + userName + "&transform=1" )
|
||||
.map(res => {
|
||||
console.log(res)
|
||||
return(
|
||||
res
|
||||
);
|
||||
|
||||
@@ -7,18 +7,15 @@ export class UsernameValidator {
|
||||
|
||||
debouncer: any;
|
||||
|
||||
constructor(private registrationService: RegistrationService){
|
||||
|
||||
}
|
||||
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);
|
||||
@@ -26,10 +23,7 @@ export class UsernameValidator {
|
||||
}, (err) => {
|
||||
resolve({'usernameInUse': true});
|
||||
});
|
||||
|
||||
}, 1000);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user