Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function create($vars = ''){
- $forbiddenNames = configItem("forbiddenNames");
- $error = array();
- // Gather data.
- // Filter out disallowed account names.
- // Check Account name and/or email.
- $accountName = $this->input->post("username");
- $password = $this->input->post("password");
- $passwordC = $this->input->post("passwordcheck");
- $email = $this->input->post("email");
- $emailcheck = $this->input->post("emailcheck");
- if(strlen($accountName) < 4){
- // To short account name
- $error["usernameError"] = "Username is to short.";
- }
- if(!filter_var($email, FILTER_VALIDATE_EMAIL) or ($email != $emailcheck)){
- // Email not email or did not match.
- $error["emailError"] = 'Email was incorrect or already in use.';
- }
- if(strlen($password) < 8 or ($password != $passwordC)){
- // Password to short or did not match.
- if(strlen($password) < 8){
- $error["passwordError"] = 'Password is to short';
- } else {
- $error["passwordError"] = 'Passwords did not match';
- }
- }
- if(count($error) > 0){
- $this->data["email"] = $email;
- $this->data["account"] = $accountName;
- // Add all errors to view.
- foreach($error as $key => $value){
- $this->data[$key] = $value;
- }
- $this->views->template("register/index", $this->data);
- } else {
- // We can now start checking against already existing accounts.
- $this->db->query("SELECT id FROM accounts WHERE email = :email or name = :name");
- $this->db->bind(":email", $email);
- $this->db->bind(":name", $accountName);
- $this->db->execute();
- if($this->db->rowcount() > 0){
- // Either email or account name already exist
- $this->data["email"] = $email;
- $this->data["account"] = $accountName;
- $this->data["usernameError"] = "Account name already in use or invalid.";
- $this->views->template("register/index", $this->data);
- } else {
- // Starts processing the account and create it.
- $this->db->query("INSERT INTO accounts (name, password, email, creation, type) VALUES(:name, :password, :email, :creation, :type)");
- $this->db->bind(":name", $accountName);
- $this->db->bind(":password", sha1($password));
- $this->db->bind(":email", $email);
- $this->db->bind(":creation", time());
- $this->db->bind(":type", 1);
- if($this->db->execute()){
- // Account should have been created now. Excellent.
- $this->data["accountname"] = $accountName;
- $this->views->template("register/success", $this->data);
- } else {
- // Something went wrong. Ask user to try again.
- $this->views->template('register/index', $this->data);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement