This commit is contained in:
2018-04-27 21:06:19 -04:00
parent 0e4ceac959
commit 732065c7b5
7 changed files with 208 additions and 94 deletions

View File

@@ -1,20 +1,28 @@
<?php <?php
$key = $_GET("key"); $userName = $_GET("username");
$type = $_GET("type"); $password = $_GET("password");
$value = $_GET("value"); $id = $username . $date->getTimestamp();
$ $returnData = array();
$date = new DateTime();
switch( $key ){ $passwordSalt = "sexfamemoney$U046qKlL$moneyfamesex";
case "validation":
break; $hashedPassword = crypt( $password, $passwordSalt );
case "create": $hashedId = crypt( $id, $passwordSalt );
break; /*
default: For login:
echo "false"; if (hash_equals($hashed_password, crypt($user_input, $hashed_password))) {
echo "Password verified!";
} }
*/
$returnData["password"] = $hashed_password;
$returnData["id"] = $hashedId;
echo( json_encode( $returnData ) );
?> ?>

67
registrationCreation.php Normal file
View File

@@ -0,0 +1,67 @@
<?php
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$email = $_POST["email"];
$userName = $_POST["userName"];
$password = $_POST["password"];
$returnData = array();
$date = new DateTime();
$id = $date->getTimestamp() . $userName . $date->getTimestamp();
$passwordSalt = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824";
$hashedPassword = crypt( $password, $passwordSalt );
$hashedId = crypt( $id, $passwordSalt );
/*
For login:
if (hash_equals($hashed_password, crypt($user_input, $hashed_password))) {
echo "Password verified!";
}
*/
$returnData["password"] = $hashedPassword;
$returnData["id"] = $hashedId;
//echo( json_encode( $returnData ) );
$url = 'http://192.241.155.78/api.php/users/';
$fields = array(
'firstName' => urlencode( $firstName ),
'lastName' => urlencode( $lastName ),
'email' => urlencode( $email ),
'userName' => urlencode( $userName ),
'password' => urlencode( $hashedPassword ),
'id' => urlencode( $hashedId )
);
//url-ify the data for the POST
//foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
//rtrim($fields_string, '&');
//open connection
$ch = curl_init( $url );
//set the url, number of POST vars, POST data
//curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec( $ch );
//close connection
curl_close( $ch );
echo( $result );
exit();
?>

View File

@@ -27,6 +27,7 @@ import { RegisterComponent } from './register/register.component';
import { RegistrationService } from './registration.service'; import { RegistrationService } from './registration.service';
import { UsernameValidator } from './validators/username.validator' import { UsernameValidator } from './validators/username.validator'
import { EmailValidator } from './validators/email.validator'
@@ -53,7 +54,7 @@ import { UsernameValidator } from './validators/username.validator'
MatPaginatorModule, MatPaginatorModule,
MatFormFieldModule MatFormFieldModule
], ],
providers: [GamesService, RegistrationService, UsernameValidator], providers: [GamesService, RegistrationService, UsernameValidator, EmailValidator],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })
export class AppModule { } export class AppModule { }

View File

@@ -4,6 +4,7 @@ import { FormBuilder, FormGroup, FormControl, Validators, AbstractControl } from
import { RegistrationService } from '../registration.service'; import { RegistrationService } from '../registration.service';
import { UsernameValidator } from '../validators/username.validator' import { UsernameValidator } from '../validators/username.validator'
import { EmailValidator } from '../validators/email.validator'
@Component({ @Component({
@@ -18,7 +19,10 @@ export class RegisterComponent implements OnInit {
constructor( constructor(
private registrationService: RegistrationService, private registrationService: RegistrationService,
private usernameValidator: UsernameValidator private usernameValidator: UsernameValidator,
private emailValidator: EmailValidator,
public formBuilder: FormBuilder
){ } ){ }
ngOnInit() { ngOnInit() {
@@ -27,83 +31,47 @@ export class RegisterComponent implements OnInit {
} }
buildForm(){ buildForm(){
const formGroup = {};
formGroup["firstName"] = new FormControl( "", this.mapValidators({ this.form = this.formBuilder.group({
required: true, firstName: ['', Validators.compose([
min: "3", Validators.maxLength(50),
max: "50" Validators.minLength(3),
}) ); Validators.required
formGroup["lastName"] = new FormControl( "", this.mapValidators({ ])],
required: true, lastName: ['', Validators.compose([
min: "3", Validators.maxLength(50),
max: "50" Validators.minLength(3),
}) ); Validators.required
formGroup["email"] = new FormControl( "", this.mapValidators({ ])],
required: true, email: ['', Validators.compose([
email: true, Validators.maxLength(100),
max: "100" Validators.email,
}) ); Validators.required
formGroup["userName"] = new FormControl( "", this.mapValidators({ ]),
ValidateUserName: true, this.emailValidator.checkEmail.bind(this.emailValidator)
required: true, ],
min: "5", userName: ['', Validators.compose([
max: "25" Validators.maxLength(25),
}) ); Validators.minLength(5),
formGroup["password"] = new FormControl( "", this.mapValidators({ Validators.required
required: true, ]),
min: "7", this.usernameValidator.checkUsername.bind(this.usernameValidator)
max: "25" ],
}) ); password: ['', Validators.compose([
Validators.maxLength(25),
this.form = new FormGroup(formGroup); Validators.minLength(5),
Validators.required
])]
});
} }
private mapValidators(validators) { onSubmit( form ){
const formValidators = []; this.registrationService.createNewUser( form ).subscribe( data => {
console.log(data);
//this.router.navigateByUrl("/login");
});
for( var key in validators ){
if( key == "required" ) {
if( validators.required ){
formValidators.push( Validators.required );
}
}else if( key == "email" ) {
if( validators.email ){
formValidators.push( Validators.email );
}
}else if( key == "min" ) {
formValidators.push(Validators.min(validators[key]));
}else if( key == "max" ) {
formValidators.push(Validators.max(validators[key]));
}else if( key == "ValidateUserName" ){
formValidators.push( this.usernameValidator.checkUsername.bind( this.usernameValidator ) );
}
}
return formValidators;
} }
}
/*
validateUserName( control: AbstractControl ){
this.registrationService.validateUserName( control.value ).subscribe( data => {
console.log( data );
if( control.value != data.username ){
return{
validUserName: true
};
}
return null;
});
}
*/
}

View File

@@ -1,31 +1,53 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' })
}
@Injectable() @Injectable()
export class RegistrationService { export class RegistrationService {
APIURL = "http://192.241.155.78/api.php"; APIURL = "http://192.241.155.78/api.php";
registrationUrl = "http://192.241.155.78/registrationCreation.php";
/* Needed for post, could be moved to local method variable */
params;
constructor( constructor(
private http: HttpClient private http: HttpClient
){ } ){ }
/*
validateUserName( userName ): Observable<any> { validateUserName( userName ): Observable<any> {
return this.http.get( "http://www.pugludos.com/registration.php?key=validation&type=username&value=" + userName ) return this.http.get( this.APIURL + "/users?filter=userName,eq," + userName + "&transform=1" )
.map(res => { .map(res => {
return( return(
res res
); );
}); });
} }
*/
validateUserName( userName ): Observable<any> { validateEmail( email ): Observable<any> {
return this.http.get( this.APIURL + "/users?filter=userName,cs," + userName + "&transform=1" ) return this.http.get( this.APIURL + "/users?filter=email,eq," + email + "&transform=1" )
.map(res => {
return(
res
);
});
}
createNewUser( userData ): Observable<any>{
/* needed for content-type x-www */
this.params = new HttpParams({
fromObject: userData
});
return this.http.post( this.registrationUrl, this.params, httpOptions )
.map(res => { .map(res => {
console.log(res) console.log(res)
return( return(
@@ -34,4 +56,5 @@ export class RegistrationService {
}); });
} }
} }

View File

@@ -0,0 +1,38 @@
import { Injectable } from '@angular/core';
import { FormControl } from '@angular/forms';
import { RegistrationService } from '../registration.service';
@Injectable()
export class EmailValidator {
debouncer: any;
constructor(
private registrationService: RegistrationService
){ }
checkEmail( control: FormControl ): any{
clearTimeout(this.debouncer);
return new Promise(resolve => {
this.debouncer = setTimeout(() => {
this.registrationService.validateEmail(control.value).subscribe((res) => {
console.log(res.users.length)
if(res.users.length === 0){
resolve(null);
}else{
resolve({'emailInUse': true});
}
/*
if(res.ok){
resolve(null);
}
}, (err) => {
resolve({'usernameInUse': true});
*/
});
}, 1000);
});
}
}

View File

@@ -17,11 +17,20 @@ export class UsernameValidator {
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) => {
console.log(res.users.length)
if(res.users.length === 0){
resolve(null);
}else{
resolve({'usernameInUse': true});
}
/*
if(res.ok){ if(res.ok){
resolve(null); resolve(null);
} }
}, (err) => { }, (err) => {
resolve({'usernameInUse': true}); resolve({'usernameInUse': true});
*/
}); });
}, 1000); }, 1000);
}); });