示例#1
0
文件: User.php 项目: EGreg/PHP-On-Pie
 /**
  * Starts the process of adding a mobile to a saved user object.
  * Also modifies and saves this user object back to the database.
  * @param string $mobile_number
  *  The mobile number to add.
  * @param string $activation_mobile_view
  *  The view to use for the body of the activation mobile to send.
  * @param boolean $html
  *  Defaults to true. Whether to send as HTML mobile.
  * @param array $fields
  *  An array of additional fields to pass to the mobile view.
  * @return boolean
  *  Returns true on success.
  *  Returns false if this mobile number is already verified for this user.
  * @throws Pie_Exception_WrongType
  *  If the mobile number is in an invalid format, this is thrown.
  * @throws Users_Exception_AlreadyVerified
  *  If the mobile number already exists and has been verified for
  *  another user, then this exception is thrown.
  */
 function addMobile($mobile_number, $activation_mobile_subject = null, $activation_mobile_view = null, $html = true, $fields = array())
 {
     // TODO: Implement Users_Mobile::sendMessage
     if (!Pie_Valid::mobile($mobile_number)) {
         throw new Pie_Exception_WrongValue(array('field' => 'Mobile phone', 'range' => 'a valid number'), 'mobile_number');
     }
     Pie::event('users/validate/mobile_number', array('mobile_number' => &$mobile_number));
     $m = new Users_Mobile();
     $m->number = $mobile_number;
     if ($m->retrieve() and $m->state !== 'unverified') {
         if ($m->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' => $m->number, 'user_id' => $m->user_id), 'mobile_number');
     }
     // If we are here, then the mobile record either
     // doesn't exist, or hasn't been verified yet.
     // In either event, update the record in the database,
     // and re-send the mobile.
     $minutes = Pie_Config::get('users', 'activationCodeExpires', 60 * 24 * 7);
     $m->state = 'unverified';
     $m->user_id = $this->id;
     $m->activation_code = Pie_Utils::unique(5);
     $m->activation_code_expires = new Db_Expression("CURRENT_TIMESTAMP + INTERVAL {$minutes} MINUTE");
     $m->auth_code = md5(microtime() + mt_rand());
     $m->save();
     if (!isset($activation_message_view)) {
         $activation_message_view = Pie_Config::get('users', 'activationMessageView', 'users/message/activation.php');
     }
     $fields2 = array_merge($fields, array('user' => $this, 'message' => $m));
     $m->sendMessage($activation_mobile_view, $fields2, array('html' => $html));
     Pie::event('users/addMobile', compact('mobile_number'), 'after');
 }
示例#2
0
文件: User.php 项目: dmitriz/Platform
 /**
  * Starts the process of adding a mobile to a saved user object.
  * Also modifies and saves this user object back to the database.
  * @method addMobile
  * @param {string} $mobileNumber
  *  The mobile number to add.
  * @param {string} [$activationMessageView=null]
  *  The view to use for the body of the activation message to send.
  * @param {array} [$fields=array()]
  *  An array of additional fields to pass to the mobile view.
  * @param {array} $options=array()
  *  Array of options. Can include:<br/>
  *  "delay" => A delay, in milliseconds, to wait until sending email. Only works if Node server is listening.
  * @return {boolean}
  *  Returns true on success.
  *  Returns false if this mobile number is already verified for this user.
  * @throws {Q_Exception_WrongValue}
  *  If the mobile number is in an invalid format, this is thrown.
  * @throws {Users_Exception_AlreadyVerified}
  *  If the mobile number already exists and has been verified for
  *  another user, then this exception is thrown.
  */
 function addMobile($mobileNumber, $activationMessageView = null, $fields = array(), $options = array())
 {
     if (!Q_Valid::phone($mobileNumber, $normalized)) {
         throw new Q_Exception_WrongValue(array('field' => 'Mobile phone', 'range' => 'a valid number'), 'mobileNumber');
     }
     $mobile = new Users_Mobile();
     $mobile->number = $normalized;
     if ($mobile->retrieve('*', array('ignoreCache' => true)) and $mobile->state !== 'unverified') {
         if ($mobile->userId === $this->id) {
             $mobile->set('user', $this);
             return $mobile;
         }
         // Otherwise, say it's verified for another user,
         // even if it unsubscribed or was suspended.
         throw new Users_Exception_AlreadyVerified(array('key' => 'mobile number', 'userId' => $mobile->userId), 'mobileNumber');
     }
     $user = $this;
     // If we are here, then the mobile record either
     // doesn't exist, or hasn't been verified yet.
     // In either event, update the record in the database,
     // and re-send the mobile.
     $minutes = Q_Config::get('Users', 'activation', 'expires', 60 * 24 * 7);
     $mobile->state = 'unverified';
     $mobile->userId = $this->id;
     $mobile->activationCode = strtolower(Q_Utils::unique(7));
     $mobile->activationCodeExpires = new Db_Expression("CURRENT_TIMESTAMP + INTERVAL {$minutes} MINUTE");
     $number = $mobile->number;
     if (substr($number, 0, 2) == '+1') {
         $number = substr($number, 2);
     }
     $mobile->authCode = md5(microtime() + mt_rand());
     $link = 'Users/activate?code=' . urlencode($mobile->activationCode) . ' mobileNumber=' . urlencode($number);
     /**
      * @event Users/addIdentifier {before}
      * @param {string} user
      * @param {string} mobile
      */
     Q::event('Users/addIdentifier', compact('user', 'mobile', 'link'), 'before');
     $mobile->save();
     $this->mobileNumberPending = $normalized;
     $this->save();
     if (!isset($activationMessageView)) {
         $activationMessageView = Q_Config::get('Users', 'transactional', 'activation', 'sms', 'Users/sms/activation.php');
     }
     $fields2 = array_merge($fields, array('user' => $this, 'mobile' => $mobile, 'app' => Q_Config::expect('Q', 'app'), 'baseUrl' => Q_Request::baseUrl(), 'link' => $link));
     $mobile->sendMessage($activationMessageView, $fields2, $options);
     Q_Response::removeNotice('Users/mobile');
     /**
      * @event Users/addIdentifier {after}
      * @param {string} user
      * @param {string} mobile
      */
     Q::event('Users/addIdentifier', compact('user', 'mobile', 'link'), 'after');
 }
示例#3
0
function Assets_after_Assets_charge($params)
{
    $user = $payments = $amount = $currency = $charge = $adapter = $options = null;
    extract($params, EXTR_OVERWRITE);
    $description = 'a product or service';
    $stream = Q::ifset($options, 'stream', null);
    if ($stream) {
        $publisherId = $stream->publisherId;
        $publisher = Users_User::fetch($publisherId, true);
        if ($stream->type === 'Assets/subscription') {
            $plan = Streams::fetchOne($stream->getAttribute('planPublisherId'), $stream->getAttribute('planPublisherId'), $stream->getAttribute('planStreamName'), true);
            $months = $stream->getAttribute('months');
            $startDate = $stream->getAttribute('startDate');
            $endDate = $stream->getAttribute('endDate');
        }
        $description = $stream->title;
    } else {
        $publisherId = Users::communityId();
        $publisher = Users_User::fetch($publisherId, true);
    }
    if (isset($options['description'])) {
        $description = $options['description'];
    }
    $currencies = Q::json_decode(file_get_contents(ASSETS_PLUGIN_CONFIG_DIR . DS . 'currencies.json'), true);
    if (!isset($currencies['symbols'][$currency])) {
        throw new Q_Exception_BadValue(array('internal' => 'currency', 'problem' => 'no symbol found'), 'currency');
    }
    if (!isset($currencies['names'][$currency])) {
        throw new Q_Exception_BadValue(array('internal' => 'currency', 'problem' => 'no name found'), 'currency');
    }
    $symbol = $currencies['symbols'][$currency];
    $currencyName = $currencies['names'][$currency];
    $communityId = Users::communityId();
    $communityName = Users::communityName();
    $communitySuffix = Users::communitySuffix();
    $link = Q_Request::baseUrl('action.php') . "/Assets/payment?publisherId={$publisherId}&userId=" . $user->id;
    $fields = compact('user', 'publisher', 'publisherId', 'communityId', 'communityName', 'communitySuffix', 'description', 'subscription', 'stream', 'plan', 'currency', 'name', 'symbol', 'currencyName', 'amount', 'months', 'startDate', 'endDate', 'link');
    if ($user->emailAddress) {
        $email = new Users_Email();
        $email->address = $user->emailAddress;
        $email->retrieve(true);
        $emailSubject = Q_Config::get('Assets', 'transactional', 'charged', 'subject', false);
        $emailView = Q_Config::get('Assets', 'transactional', 'charged', 'body', false);
        if ($emailSubject !== false and $emailView) {
            $email->sendMessage($emailSubject, $emailView, $fields);
        }
    } else {
        if ($user->mobileNumber) {
            $mobile = new Users_Mobile();
            $mobile->number = $user->mobileNumber;
            $mobile->retrieve(true);
            if ($mobileView = Q_Config::get('Assets', 'transactional', 'charged', 'sms', false)) {
                $mobile->sendMessage($mobileView, $fields);
            }
        }
    }
    if ($publisher->emailAddress) {
        $email = new Users_Email();
        $email->address = $publisher->emailAddress;
        $email->retrieve(true);
        $emailSubject = Q_Config::get('Assets', 'transactional', 'charge', 'subject', false);
        $emailView = Q_Config::get('Assets', 'transactional', 'charge', 'body', false);
        if ($emailSubject !== false and $emailView) {
            $email->sendMessage($emailSubject, $emailView, $fields);
        }
    } else {
        if ($publisher->mobileNumber) {
            $mobile = new Users_Mobile();
            $mobile->number = $publisher->mobileNumber;
            $mobile->retrieve(true);
            if ($mobileView = Q_Config::get('Assets', 'transactional', 'charge', 'sms', false)) {
                $mobile->sendMessage($mobileView, $fields);
            }
        }
    }
}