Advertisement
GabrielRabeloLopes

Users.2.0.php

Feb 25th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.51 KB | None | 0 0
  1. <?php
  2.     require_once '../Modules/Routes.php';
  3.     require_once '../Modules/Definitions.php';
  4.     require_once '../Modules/Tools.php';
  5.  
  6.     Routes::POST(function(){
  7.         $name = isset($_POST['name']) ? trim($_POST['name']) : null;
  8.         $surname = isset($_POST['surname']) ? trim($_POST['surname']) : null;
  9.         $phone = isset($_POST['phone']) ? trim($_POST['phone']) : null;
  10.         $email = isset($_POST['email']) ? trim($_POST['email']) : null;
  11.         $password = isset($_POST['password']) ? trim($_POST['password']) : null;
  12.  
  13.  
  14.         if($name == null)
  15.             Tools::Response("Error", "400", "0x000", "Bad Request", "Name is null or was not setted");
  16.         if($surname == null)
  17.             Tools::Response("Error", "400", "0x000", "Bad Request", "Surname is null or was not setted");
  18.         if($phone == null)
  19.             Tools::Response("Error", "400", "0x000", "Bad Request", "Phone is null or was not setted");
  20.         if($email == null)
  21.             Tools::Response("Error", "400", "0x000", "Bad Request", "Email is null or was not setted");
  22.         if($password == null)
  23.             Tools::Response("Error", "400", "0x000", "Bad Request", "Password is null or was not setted");
  24.  
  25.  
  26.         if(!preg_match(REGEX_NAME, $name))
  27.             Tools::Response("Error", "400", "0x000", "Bad Request", "Name is wrong");
  28.         if(!preg_match(REGEX_SURNAME, $surname))
  29.             Tools::Response("Error", "400", "0x000", "Bad Request", "Surname is wrong");
  30.         if(!preg_match(REGEX_PHONE, $phone))
  31.             Tools::Response("Error", "400", "0x000", "Bad Request", "Phone is wrong");
  32.         if(!filter_var($email, FILTER_VALIDATE_EMAIL))
  33.             Tools::Response("Error", "400", "0x000", "Bad Request", "Email is wrong");
  34.         if(!preg_match(REGEX_PASSWORD, $password))
  35.             Tools::Response("Error", "400", "0x000", "Bad Request", "Password is wrong");
  36.        
  37.        
  38.         @$connection = mysqli_connect(DATABASE_ADDRESS, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME)
  39.             or die(Tools::Response("Error", "500", "0x000", "Internal Server Error", "Error connecting to database", "RETURN"));
  40.         @$selection = mysqli_select_db()
  41.             or die(Tools::Response("Error", "500", "0x000", "Internal Server Error", "Error selecting to database", "RETURN"));
  42.        
  43.        
  44.         @$query_0 = mysqli_query($connection, "SELECT `phone`, `email` FROM `users` WHERE `phone` = '$phone' OR `email` = '$email'")
  45.             or die(Tools::Response("Error", "500", "0x000", "Internal Server Error", "Error querying in database", "RETURN"));
  46.         @$query_0_fetched = mysqli_fetch_array($query_0)
  47.             or die(Tools::Response("Error", "500", "0x000", "Internal Server Error", "Error fetching response", "RETURN"));
  48.        
  49.        
  50.         if($query_0 -> num_rows > 0){
  51.             if($query_0_fetched['email'] == $email)
  52.                 Tools::Response("Error", "xxx", "0x000", "xxx xxx xxx", "This email is not available");
  53.             if($query_0_fetched['phone'] == $phone)
  54.                 Tools::Response("Error", "xxx", "0x000", "xxx xxx xxx", "This phone is not available");
  55.         }
  56.        
  57.         //CONTINUA
  58.         //CONTINUA
  59.         //CONTINUA
  60.     });
  61.  
  62.     Routes::GET(function(){
  63.         echo 'GET';
  64.     });
  65.  
  66.     Routes::PUT(function(){
  67.         echo 'PUT';
  68.     });
  69.  
  70.     Routes::PATCH(function(){
  71.         echo 'PATCH';
  72.     });
  73.  
  74.     Routes::DELETE(function(){
  75.         echo 'DELETE';
  76.     });
  77.  
  78.     Routes::ANY(function(){
  79.        echo 'ANY';
  80.     });
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement