validation
This commit is contained in:
@@ -2717,7 +2717,7 @@ class PHP_CRUD_API {
|
|||||||
'dbengine'=>'MySQL',
|
'dbengine'=>'MySQL',
|
||||||
'hostname'=>'localhost',
|
'hostname'=>'localhost',
|
||||||
'username'=>'lazyp_workadmin',
|
'username'=>'lazyp_workadmin',
|
||||||
'password'=>'ZGmH0HQPo5ocbOuN',
|
'password'=>'GH5fZF0iCtLnHLrz',
|
||||||
'database'=>'LudosData',
|
'database'=>'LudosData',
|
||||||
'charset'=>'utf8mb4'
|
'charset'=>'utf8mb4'
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ import { LoginComponent } from './login/login.component';
|
|||||||
import { RegisterComponent } from './register/register.component';
|
import { RegisterComponent } from './register/register.component';
|
||||||
|
|
||||||
import { RegistrationService } from './registration.service';
|
import { RegistrationService } from './registration.service';
|
||||||
|
|
||||||
//import { CreditCardValidator } from './creditcardvalidator.directive'
|
|
||||||
import { UsernameValidator } from './validators/username.validator'
|
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()
|
@Injectable()
|
||||||
export class GamesService {
|
export class GamesService {
|
||||||
|
|
||||||
APIURL = "http://192.241.155.78/ludosdata/api.php";
|
APIURL = "http://192.241.155.78/api.php";
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private http: HttpClient
|
private http: HttpClient
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import { RegistrationService } from '../registration.service';
|
|||||||
import { UsernameValidator } from '../validators/username.validator'
|
import { UsernameValidator } from '../validators/username.validator'
|
||||||
|
|
||||||
|
|
||||||
//import { ValidateUserName } from '../validators/username.validator';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-register',
|
selector: 'app-register',
|
||||||
templateUrl: './register.component.html',
|
templateUrl: './register.component.html',
|
||||||
@@ -17,7 +15,6 @@ export class RegisterComponent implements OnInit {
|
|||||||
|
|
||||||
form: any;
|
form: any;
|
||||||
loading = false;
|
loading = false;
|
||||||
//userNameValidator = new UserNameValidator(null);
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private registrationService: RegistrationService,
|
private registrationService: RegistrationService,
|
||||||
@@ -79,8 +76,6 @@ export class RegisterComponent implements OnInit {
|
|||||||
}else if( key == "max" ) {
|
}else if( key == "max" ) {
|
||||||
formValidators.push(Validators.max(validators[key]));
|
formValidators.push(Validators.max(validators[key]));
|
||||||
}else if( key == "ValidateUserName" ){
|
}else if( key == "ValidateUserName" ){
|
||||||
//formValidators.push( this.validateUserName );
|
|
||||||
//formValidators.push( CreditCardValidator.validateCcNumber );
|
|
||||||
formValidators.push( this.usernameValidator.checkUsername.bind( this.usernameValidator ) );
|
formValidators.push( this.usernameValidator.checkUsername.bind( this.usernameValidator ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import 'rxjs/add/operator/map';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class RegistrationService {
|
export class RegistrationService {
|
||||||
|
|
||||||
APIURL = "http://192.241.155.78/ludosdata/api.php";
|
APIURL = "http://192.241.155.78/api.php";
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private http: HttpClient
|
private http: HttpClient
|
||||||
@@ -25,8 +25,9 @@ export class RegistrationService {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
validateUserName( userName ): Observable<any> {
|
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 => {
|
.map(res => {
|
||||||
|
console.log(res)
|
||||||
return(
|
return(
|
||||||
res
|
res
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,21 +4,18 @@ import { RegistrationService } from '../registration.service';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsernameValidator {
|
export class UsernameValidator {
|
||||||
|
|
||||||
debouncer: any;
|
debouncer: any;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private registrationService: RegistrationService
|
||||||
|
){ }
|
||||||
|
|
||||||
constructor(private registrationService: RegistrationService){
|
checkUsername( control: FormControl ): any{
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
checkUsername(control: FormControl): any {
|
|
||||||
|
|
||||||
clearTimeout(this.debouncer);
|
clearTimeout(this.debouncer);
|
||||||
|
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
|
||||||
this.debouncer = setTimeout(() => {
|
this.debouncer = setTimeout(() => {
|
||||||
|
|
||||||
this.registrationService.validateUserName(control.value).subscribe((res) => {
|
this.registrationService.validateUserName(control.value).subscribe((res) => {
|
||||||
if(res.ok){
|
if(res.ok){
|
||||||
resolve(null);
|
resolve(null);
|
||||||
@@ -26,10 +23,7 @@ export class UsernameValidator {
|
|||||||
}, (err) => {
|
}, (err) => {
|
||||||
resolve({'usernameInUse': true});
|
resolve({'usernameInUse': true});
|
||||||
});
|
});
|
||||||
|
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user