コード例 #1
0
ファイル: LoginSystem.php プロジェクト: sXule/BranchFeed
 public function Register($handle, $email, $pass1, $pass2, $rights = 0)
 {
     try {
         if ($this->is_empty($handle, $email, $pass1, $pass2)) {
             throw new Exception(FORMINCOMPLETE_ERROR_MSG);
         }
         if (!Validate::CheckHandle($handle)) {
             throw new Exception(HANDLEVALIDATION_ERROR_MSG);
         }
         if ($this->userExists($handle)) {
             throw new Exception(NAMETAKEN_ERROR_MSG);
         }
         if (!Validate::CheckEmail($email)) {
             throw new Exception(EMAILVALIDATION_ERROR_MSG);
         }
         if ($this->emailExists($email)) {
             throw new Exception(EMAILTAKEN_ERROR_MSG);
         }
         if ($pass1 != $pass2) {
             throw new Exception(PASSWORDCONFIRM_ERROR_MSG);
         }
         if (!Validate::CheckPassword($pass1)) {
             throw new Exception(PASSWORDVALIDATION_ERROR_MSG);
         }
         $sql = "INSERT INTO users (handle,hash,email,rights) VALUES (?,?,?,?)";
         if (!($stmt = $this->db->prepare($sql))) {
             throw new Exception(STMT_ERROR_MSG);
         }
         $hash = Bcrypt::CreateHash($pass1);
         // Convert Date String to MySQL format
         date_default_timezone_set('America/Chicago');
         $birthdate = date('Y-m-d', strtotime($birthdate));
         // Execute Statement (run query)
         $stmt->bind_param('sssi', $handle, $hash, $email, $rights);
         if (!$stmt->execute()) {
             throw new Exception(EXECUTE_ERROR_MSG);
         }
         $stmt->close();
         return true;
     } catch (Exception $e) {
         $this->error = $e->getMessage();
     }
     return false;
 }