Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class SignupController extends Signup {
- private $username;
- private $password;
- private $repeat_password;
- private $email;
- public function __construct($username, $password, $repeat_password, $email)
- {
- $this->username = $username;
- $this->password = $password;
- $this->repeat_password = $repeat_password;
- $this->email = $email;
- }
- public function signup_user()
- {
- if($this->empty_input() == false) {
- // echo "Empty Input!";
- header("location: ../index.php?error=emptyinput");
- exit();
- }
- if($this->invalid_username() == false) {
- // echo "Invalid username!";
- header("location: ../index.php?error=invalidusername");
- exit();
- }
- if($this->invalid_email() == false) {
- // echo "Invalid Email!";
- header("location: ../index.php?error=invalidemail");
- exit();
- }
- if($this->password_match() == false) {
- // echo "Password Mismatch!";
- header("location: ../index.php?error=passwordmismatch");
- exit();
- }
- if($this->username_taken() == false) {
- // echo "username or email already exists";
- header("location: ../index.php?error=unknownusername");
- exit();
- }
- $this->set_user($this->username, $this->password, $this->email);
- }
- private function empty_input()
- {
- $result = true;
- if(empty($this->username) || empty($this->password) ||
- empty($this->repeat_password) || empty($this->email))
- {
- $result = false;
- }
- return $result;
- }
- private function invalid_username()
- {
- $result = true;
- if(!preg_match("/^[a-zA-Z0-9]*$/", $this->username))
- {
- $result = false;
- }
- return $result;
- }
- private function invalid_email()
- {
- $result = true;
- if(!filter_var($this->email, FILTER_VALIDATE_EMAIL))
- {
- $result = false;
- }
- return $result;
- }
- private function password_match()
- {
- $result = true;
- if($this->password !== $this->repeat_password)
- {
- $result = false;
- }
- return $result;
- }
- private function username_taken(){
- $result = true;
- if(!$this->check_user($this->username, $this->email))
- {
- $result = false;
- }
- return $result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment