Last active
July 5, 2021 04:37
-
-
Save wildroo/f7d594b2d14a1551ccfd4c9a3b580e79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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