Exemplo n.º 1
0
 public function register()
 {
     $resp = verifyRecaptcha($this->captcha);
     if ($resp->success == false) {
         $gcotd_msg .= "" . "The reCAPTCHA wasn't entered correctly. " . "Go back and try it again.";
         $this->setOutput(self::$FAIL, $gcotd_msg);
     } else {
         if ($resp->success == true) {
             $plainTxtPassword = getNewPassword();
             $memip = $_SERVER['REMOTE_ADDR'];
             $date = date("Y-m-d H:i:s");
             if ($this->email == NULL or $this->firstname == NULL or $this->lastname == NULL) {
                 $gcotd_msg .= "Please complete the form.";
                 $this->setOutput(self::$FAIL, $gcotd_msg);
             } else {
                 if (!preg_match('/^[a-z\\d_]{1,30}$/i', $this->firstname)) {
                     $gcotd_msg .= "Your first name must be " . "between 1 and 30 characters cannot contain spaces or " . "special characters.";
                     $this->setOutput(self::$FAIL, $gcotd_msg);
                 } else {
                     if (!preg_match('/^[a-z\\d_]{1,30}$/i', $this->lastname)) {
                         $gcotd_msg .= "Your last name must be " . "between 1 and 30 characters cannot contain spaces or " . "special characters.";
                         $this->setOutput(self::$FAIL, $gcotd_msg);
                     } else {
                         if ($this->firstname === $this->lastname) {
                             $gcotd_msg .= "Your first name cannot " . "equal your last name.";
                             $this->setOutput(self::$FAIL, $gcotd_msg);
                         } else {
                             if (!preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,})\$/i", $this->email)) {
                                 $gcotd_msg .= "" . $this->email . " is " . "not a valid email address.";
                                 $this->setOutput(self::$FAIL, $gcotd_msg);
                             } else {
                                 $check_user_stmt = $this->getDb()->prepare("SELECT * FROM users WHERE email = :email");
                                 $check_user_stmt->bindValue(':email', $this->email, PDO::PARAM_STR);
                                 $check_user_stmt->execute();
                                 if ($check_user_stmt->rowCount() > 0) {
                                     $gcotd_msg .= "Someone with " . "this email has already registered.";
                                     $this->setOutput(self::$FAIL, $gcotd_msg);
                                 } else {
                                     $password = password_hash($plainTxtPassword, PASSWORD_DEFAULT);
                                     return $this->registerUser($this->firstname, $this->lastname, $this->email, $memip, $date, $password, $plainTxtPassword, null);
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             $gcotd_msg .= "Failed to verify captcha.";
             $this->setOutput(self::$FAIL, $gcotd_msg);
         }
     }
 }
Exemplo n.º 2
0
 public function forgot()
 {
     $resp = verifyRecaptcha($this->captcha);
     if ($resp->success == false) {
         $gcotd_msg = "" . "The reCAPTCHA wasn't entered correctly. " . "Go back and try it again.";
         $this->setOutput(self::$FAIL, $gcotd_msg);
     } else {
         if ($resp->success == true) {
             if ($this->postedusername == NULL and $this->postedemail == NULL) {
                 $gcotd_msg = "Please complete the form.";
                 $this->setOutput(self::$FAIL, $gcotd_msg);
             } else {
                 if ($this->postedusername != null) {
                     $check_user_stmt = $this->getDb()->prepare("SELECT * FROM users WHERE name = :username");
                     $check_user_stmt->bindValue(':username', $this->postedusername, PDO::PARAM_STR);
                     $check_user_stmt->execute();
                     if ($check_user_stmt->rowCount() > 0) {
                         $get_user_data = $check_user_stmt->fetch(PDO::FETCH_ASSOC);
                         $user_id = $get_user_data['id'];
                         $resetPassword = $this->resetPassword($user_id);
                         if ($resetPassword != false) {
                             $this->sendResetEmail($this->postedusername, $get_user_data['email'], $resetPassword);
                             $gcotd_msg = "An email has been sent \n\t\t\t\t\t\t\t\tto the email address registered for that username.";
                             $this->setOutput(self::$SUCCESS, $gcotd_msg);
                         }
                     } else {
                         $gcotd_msg = "This user name does not exist.";
                         $this->setOutput(self::$FAIL, $gcotd_msg);
                     }
                 } else {
                     if ($this->postedemail != null) {
                         if (!eregi("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$", $this->postedemail)) {
                             $gcotd_msg = "Your email address is not valid.";
                             $this->setOutput(self::$FAIL, $gcotd_msg);
                         } else {
                             $check_user_stmt = $this->getDb()->prepare("SELECT * FROM users WHERE email=:email");
                             $check_user_stmt->bindValue(':email', $this->postedemail, PDO::PARAM_STR);
                             $check_user_stmt->execute();
                             if ($check_user_stmt->rowCount() > 0) {
                                 $get_user_data = $check_user_stmt->fetch(PDO::FETCH_ASSOC);
                                 $user_id = $get_user_data['id'];
                                 $resetPassword = $this->resetPassword($user_id);
                                 if ($resetPassword != false) {
                                     $this->sendResetEmail($get_user_data['name'], $this->postedemail, $resetPassword);
                                     $gcotd_msg = "An email has been sent \n\t\t\t\t\t\t\t\t\tto the email address registered for that username.";
                                     $this->setOutput(self::$SUCCESS, $gcotd_msg);
                                 } else {
                                     $gcotd_msg = "Your password could not be reset.";
                                     $this->setOutput(self::$FAIL, $gcotd_msg);
                                 }
                             } else {
                                 $gcotd_msg = "This email does not exist.";
                                 $this->setOutput(self::$FAIL, $gcotd_msg);
                             }
                         }
                     }
                 }
             }
         } else {
             $gcotd_msg = "Failed to verify captcha.";
             $this->setOutput(self::$FAIL, $gcotd_msg);
         }
     }
 }