Example #1
0
function users_activate_validate()
{
    $email_address = Pie_Dispatcher::uri()->email_address;
    $mobile_number = Pie_Dispatcher::uri()->mobile_number;
    if ($email_address && !Pie_Valid::email($email_address)) {
        throw new Pie_Exception_WrongValue(array('field' => 'email', 'range' => 'a valid email address'), 'email_address');
    }
    if ($mobile_number && !Pie_Valid::phone($mobile_number)) {
        throw new Pie_Exception_WrongValue(array('field' => 'mobile phone', 'range' => 'a valid phone number'), 'mobile_number');
    }
    if ($email_address or $mobile_number) {
        if (empty($_REQUEST['code'])) {
            throw new Pie_Exception("The activation code is missing");
        }
    }
    // This is one of the few places where we cheat,
    // and fill the $_POST array even though it probably wasn't filled.
    if ($email_address) {
        $_POST['email_address'] = $email_address;
    } else {
        if ($mobile_number) {
            $_POST['mobile_number'] = $mobile_number;
        }
    }
}
Example #2
0
function users_user_validate()
{
    if (!isset($_REQUEST['email_address'])) {
        throw new Pie_Exception('email address is missing', array('email_address'));
    }
    if (!Pie_Valid::email($_REQUEST['email_address'])) {
        throw new Pie_Exception('a valid email address is required', array('email_address'));
    }
}
Example #3
0
 /**
  * Starts the process of adding an email to a saved user object.
  * Also modifies and saves this user object back to the database.
  * @param string $email_address
  *  The email address to add.
  * @param string $activation_email_subject
  *  The subject of the activation email to send.
  * @param string $activation_email_view
  *  The view to use for the body of the activation email to send.
  * @param boolean $html
  *  Defaults to true. Whether to send as HTML email.
  * @param array $fields
  *  An array of additional fields to pass to the email view.
  * @return boolean
  *  Returns true on success.
  *  Returns false if this email address is already verified for this user.
  * @throws Pie_Exception_WrongType
  *  If the email address is in an invalid format, this is thrown.
  * @throws Users_Exception_AlreadyVerified
  *  If the email address already exists and has been verified for
  *  another user, then this exception is thrown.
  */
 function addEmail($email_address, $activation_email_subject = null, $activation_email_view = null, $html = true, $fields = array())
 {
     if (!Pie_Valid::email($email_address)) {
         throw new Pie_Exception_WrongValue(array('field' => 'Email', 'range' => 'a valid address'), 'email_address');
     }
     Pie::event('users/validate/email_address', array('email_address' => &$email_address));
     $e = new Users_Email();
     $e->address = $email_address;
     if ($e->retrieve() and $e->state !== 'unverified') {
         if ($e->user_id === $this->id) {
             return false;
         }
         // Otherwise, say it's verified for another user,
         // even if it unsubscribed or was suspended.
         throw new Users_Exception_AlreadyVerified(array('key' => $e->address, 'user_id' => $e->user_id), 'email_address');
     }
     // If we are here, then the email record either
     // doesn't exist, or hasn't been verified yet.
     // In either event, update the record in the database,
     // and re-send the email.
     $minutes = Pie_Config::get('users', 'activationCodeExpires', 60 * 24 * 7);
     $e->state = 'unverified';
     $e->user_id = $this->id;
     $e->activation_code = Pie_Utils::unique(5);
     $e->activation_code_expires = new Db_Expression("CURRENT_TIMESTAMP + INTERVAL {$minutes} MINUTE");
     $e->auth_code = md5(microtime() + mt_rand());
     $e->save();
     if (!isset($activation_email_view)) {
         $activation_email_view = Pie_Config::get('users', 'activationEmailView', 'users/email/activation.php');
     }
     if (!isset($activation_email_subject)) {
         $activation_email_subject = Pie_Config::get('users', 'activationEmailSubject', "Welcome! Please confirm your email address.");
     }
     $fields2 = array_merge($fields, array('user' => $this, 'email' => $e));
     $e->sendMessage($activation_email_subject, $activation_email_view, $fields2, array('html' => $html));
     Pie::event('users/addEmail', compact('email_address'), 'after');
 }