Inheritance: extends Model
示例#1
0
 /**
  * Perform the necessary actions to send a password reset mail
  *
  * @param $user_name_or_email string Username or user's email
  * @param $captcha string Captcha string
  *
  * @return bool success status
  */
 public static function requestPasswordReset($user_name_or_email, $captcha)
 {
     if (!CaptchaModel::checkCaptcha($captcha)) {
         Session::add('feedback_negative', Text::get('FEEDBACK_CAPTCHA_WRONG'));
         return false;
     }
     if (empty($user_name_or_email)) {
         Session::add('feedback_negative', Text::get('FEEDBACK_USERNAME_EMAIL_FIELD_EMPTY'));
         return false;
     }
     // check if that username exists
     $result = UserModel::getUserDataByUserNameOrEmail($user_name_or_email);
     if (!$result) {
         Session::add('feedback_negative', Text::get('FEEDBACK_USER_DOES_NOT_EXIST'));
         return false;
     }
     // generate integer-timestamp (to see when exactly the user (or an attacker) requested the password reset mail)
     // generate random hash for email password reset verification (40 char string)
     $temporary_timestamp = time();
     $user_password_reset_hash = sha1(uniqid(mt_rand(), true));
     // set token (= a random hash string and a timestamp) into database ...
     $token_set = self::setPasswordResetDatabaseToken($result->user_name, $user_password_reset_hash, $temporary_timestamp);
     if (!$token_set) {
         return false;
     }
     // ... and send a mail to the user, containing a link with username and token hash string
     $mail_sent = self::sendPasswordResetMail($result->user_name, $user_password_reset_hash, $result->user_email);
     if ($mail_sent) {
         return true;
     }
     // default return
     return false;
 }
示例#2
0
 /**
  * Validates the registration input
  *
  * @param $captcha
  * @param $user_name
  * @param $user_password_new
  * @param $user_password_repeat
  * @param $user_email
  *
  * @return bool
  */
 public static function registrationInputValidation($captcha, $user_name, $user_password_new, $user_password_repeat, $user_email)
 {
     // perform all necessary checks
     if (!CaptchaModel::checkCaptcha($captcha)) {
         Session::add('feedback_negative', Text::get('FEEDBACK_CAPTCHA_WRONG'));
         return false;
     }
     // if username, email and password are all correctly validated
     if (self::validateUserName($user_name) and self::validateUserEmail($user_email) and self::validateUserPassword($user_password_new, $user_password_repeat)) {
         return true;
     }
     // otherwise, return false
     return false;
 }
示例#3
0
 /**
  * Generate a captcha, write the characters into $_SESSION['captcha'] and returns a real image which will be used
  * like this: <img src="......./login/showCaptcha" />
  * IMPORTANT: As this action is called via <img ...> AFTER the real application has finished executing (!), the
  * SESSION["captcha"] has no content when the application is loaded. The SESSION["captcha"] gets filled at the
  * moment the end-user requests the <img .. >
  * Maybe refactor this sometime.
  */
 public function showCaptcha()
 {
     CaptchaModel::generateAndShowCaptcha();
 }
示例#4
0
 /**
  * Validates the registration input
  *
  * @param $captcha
  * @param $user_name
  * @param $user_password_new
  * @param $user_password_repeat
  * @param $user_email
  *
  * @return bool
  */
 public static function registrationInputValidation($captcha, $user_name, $user_password_new, $user_password_repeat, $user_email)
 {
     if (Config::get('RECAPTCHA_ENABLED')) {
         if (!CaptchaModel::checkRecaptcha($captcha)) {
             Session::add('feedback_negative', Language::getText('captcha-wrong'));
             return false;
         }
     } else {
         if (!CaptchaModel::checkCaptcha($captcha)) {
             Session::add('feedback_negative', Language::getText('captcha-wrong'));
             return false;
         }
     }
     // if username, email and password are all correctly validated
     if (self::validateUserName($user_name) && self::validateUserEmail($user_email) && self::validateUserPassword($user_password_new, $user_password_repeat)) {
         return true;
     }
     return false;
 }