Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // allow the Config
- define('__CONFIG__', true);
- // require the config
- require_once '../inc/config.php';
- if($_SERVER['REQUEST_METHOD']=='POST' or 1==1){
- // Always return JSON Format
- //header('Content-Type : application/json');
- $return = [];
- $email = Filter::String($_POST['email']);
- //make sure the user does not exist
- $findUser = $con->prepare('SELECT user_id FROM users WHERE email= LOWER(:email) LIMIT 1');
- $findUser->bindParam(':email' ,$email, PDO::PARAM_STR);
- $findUser->execute();
- if(findUser -> rowCount == 1){
- // user exist
- $return['error'] = 'the email address already registered in our database.';
- $return['is_logged_in'] = false;
- }else{
- // user can be register
- $password = password_hash($_POST['password'], PASSWORD_DEFAULT);
- $addUser = $con->prepare('INSERT INTO users(LOWER(email), password) VALUES(LOWER(:email) , :password)');
- $addUser->bindParam(':email' , $email, PDO::PARAM_STR);
- $addUser->bindParam(':password' , $password, PDO::PARAM_STR);
- $addUser->execute();
- $user_id = $con -> lastInserId();
- $_SESSION['user_id'] = int() $user_id;
- $return['redirect'] = '/dashboard.php?message=welcome';
- $return['is_logged_in'] = true;
- }
- echo json_encode($return, JSON_PRETTY_PRINT); exit;
- }else{
- exit('invalid URL');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement