Taximaniac

My version of signup-controller.classes.php from youtube video https://www.youtube.com/watch?v=BaEm2

Mar 18th, 2022
1,504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.62 KB | None | 0 0
  1. <?php
  2.  
  3. class SignupController extends Signup {
  4.  
  5.     private $username;
  6.     private $password;
  7.     private $repeat_password;
  8.     private $email;
  9.  
  10.     public function __construct($username, $password, $repeat_password, $email)
  11.     {
  12.         $this->username = $username;
  13.         $this->password = $password;
  14.         $this->repeat_password = $repeat_password;
  15.         $this->email = $email;
  16.     }
  17.  
  18.     public function signup_user()
  19.     {
  20.         if($this->empty_input() == false) {
  21.             // echo "Empty Input!";
  22.             header("location: ../index.php?error=emptyinput");
  23.             exit();
  24.         }
  25.  
  26.         if($this->invalid_username() == false) {
  27.             // echo "Invalid username!";
  28.             header("location: ../index.php?error=invalidusername");
  29.             exit();
  30.         }
  31.  
  32.         if($this->invalid_email() == false) {
  33.             // echo "Invalid Email!";
  34.             header("location: ../index.php?error=invalidemail");
  35.             exit();
  36.         }
  37.  
  38.         if($this->password_match() == false) {
  39.             // echo "Password Mismatch!";
  40.             header("location: ../index.php?error=passwordmismatch");
  41.             exit();
  42.         }
  43.  
  44.         if($this->username_taken() == false) {
  45.             // echo "username or email already exists";
  46.             header("location: ../index.php?error=unknownusername");
  47.             exit();
  48.         }
  49.  
  50.         $this->set_user($this->username, $this->password, $this->email);
  51.     }
  52.  
  53.     private function empty_input()
  54.     {
  55.         $result = true;
  56.  
  57.         if(empty($this->username) || empty($this->password) ||
  58.            empty($this->repeat_password) || empty($this->email))
  59.         {
  60.             $result = false;        
  61.         }
  62.  
  63.         return $result;
  64.     }
  65.  
  66.     private function invalid_username()
  67.     {
  68.         $result = true;
  69.  
  70.         if(!preg_match("/^[a-zA-Z0-9]*$/", $this->username))
  71.         {
  72.             $result = false;
  73.         }
  74.  
  75.         return $result;
  76.     }
  77.  
  78.     private function invalid_email()
  79.     {
  80.         $result  = true;
  81.  
  82.         if(!filter_var($this->email, FILTER_VALIDATE_EMAIL))
  83.         {
  84.             $result = false;
  85.         }
  86.  
  87.         return $result;
  88.     }
  89.  
  90.     private function password_match()
  91.     {
  92.         $result = true;
  93.  
  94.         if($this->password !== $this->repeat_password)
  95.         {
  96.             $result = false;
  97.         }
  98.  
  99.         return $result;
  100.     }
  101.  
  102.     private function username_taken(){
  103.         $result = true;
  104.  
  105.         if(!$this->check_user($this->username, $this->email))
  106.         {
  107.             $result = false;
  108.         }
  109.  
  110.         return $result;
  111.     }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment