daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Feb 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function create($vars = ''){
  2.         $forbiddenNames = configItem("forbiddenNames");
  3.         $error = array();
  4.         // Gather data.
  5.         // Filter out disallowed account names.
  6.         // Check Account name and/or email.
  7.         $accountName = $this->input->post("username");
  8.         $password    = $this->input->post("password");
  9.         $passwordC   = $this->input->post("passwordcheck");
  10.         $email       = $this->input->post("email");
  11.         $emailcheck  = $this->input->post("emailcheck");
  12.         if(strlen($accountName) < 4){
  13.             // To short account name
  14.             $error["usernameError"] = "Username is to short.";
  15.         }
  16.         if(!filter_var($email, FILTER_VALIDATE_EMAIL) or ($email != $emailcheck)){
  17.             // Email not email or did not match.
  18.             $error["emailError"] = 'Email was incorrect or already in use.';
  19.         }
  20.         if(strlen($password) < 8 or ($password != $passwordC)){
  21.             // Password to short or did not match.
  22.             if(strlen($password) < 8){
  23.                 $error["passwordError"] = 'Password is to short';
  24.             } else {
  25.                 $error["passwordError"] = 'Passwords did not match';
  26.             }
  27.  
  28.         }
  29.         if(count($error) > 0){
  30.             $this->data["email"] = $email;
  31.             $this->data["account"]  = $accountName;
  32.  
  33.             // Add all errors to view.
  34.             foreach($error as $key => $value){
  35.                 $this->data[$key] = $value;
  36.             }
  37.             $this->views->template("register/index", $this->data);
  38.         } else {
  39.             // We can now start checking against already existing accounts.
  40.             $this->db->query("SELECT id FROM accounts WHERE email = :email or name = :name");
  41.             $this->db->bind(":email", $email);
  42.             $this->db->bind(":name", $accountName);
  43.             $this->db->execute();
  44.             if($this->db->rowcount() > 0){
  45.                 // Either email or account name already exist
  46.                 $this->data["email"] = $email;
  47.                 $this->data["account"]  = $accountName;
  48.                 $this->data["usernameError"] = "Account name already in use or invalid.";
  49.                 $this->views->template("register/index", $this->data);
  50.             } else {
  51.                 // Starts processing the account and create it.
  52.                 $this->db->query("INSERT INTO accounts (name, password, email, creation, type) VALUES(:name, :password, :email, :creation, :type)");
  53.                 $this->db->bind(":name", $accountName);
  54.                 $this->db->bind(":password", sha1($password));
  55.                 $this->db->bind(":email", $email);
  56.                 $this->db->bind(":creation", time());
  57.                 $this->db->bind(":type", 1);
  58.                 if($this->db->execute()){
  59.                     // Account should have been created now. Excellent.
  60.                     $this->data["accountname"] = $accountName;
  61.                     $this->views->template("register/success", $this->data);
  62.                 } else {
  63.                     // Something went wrong. Ask user to try again.
  64.                     $this->views->template('register/index', $this->data);
  65.                 }
  66.             }
  67.         }
  68.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top