Skip to content

Instantly share code, notes, and snippets.

@wildroo
Last active Jul 5, 2021
Embed
What would you like to do?
<?php
/**
* This is a short snapshot to show an idea. The complete project is tored here:
* https://github.com/wildroo/medium/blob/main/react_php_task
*/
class UserHelper{
private $usersTable = "users";
private $profilesTable = "profiles";
public function createUser($connection, $input){
//check inputs
if(!isset($input['email']) || !isset($input['password']))
{
return $json = array("success" => false, "Info" => "Invalid Inputs");
}
//sanitise inputs
$email = htmlspecialchars(strip_tags($input['email']));
$password = htmlspecialchars(strip_tags(base64_decode($input['password'])));
//check if valid email
if($this->validEmail($email)===false)
{
return $json = array("success" => false, "Info" => "Invalid Email");
}
//check email exists START
$sql = "SELECT * FROM $this->profilesTable WHERE email =:email";
$stmt = $connection->prepare($sql);
$stmt->bindParam(":email",$email);
$stmt->execute();
$profile = $stmt->fetch();
if(isset($profile[0]))
{
return $json = array("success" => false, "Info" => "Email Already Exists");
}
//SET @VAR $UID
$uid = md5(time().rand());
$public_name = $this->splitEmail($email);
//The rest of the function is here:
//https://github.com/wildroo/medium/blob/main/react_php_task/phpbackend/helpers/userHelper.php
}
/**
* The complete project with all other functions and components is here:
* https://github.com/wildroo/medium/blob/main/react_php_task
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment