示例#1
0
function Users_user_validate()
{
    if (isset($_REQUEST['userIds']) or isset($_REQUEST['batch'])) {
        return;
    }
    $type = isset($_REQUEST['identifierType']) ? $_REQUEST['identifierType'] : Q_Config::get("Users", "login", "identifierType", "email,mobile");
    $parts = explode(',', $type);
    $accept_mobile = true;
    $expected = 'email address or mobile number';
    $fields = array('emailAddress', 'mobileNumber', 'identifier');
    if (count($parts) === 1) {
        if ($parts[0] === 'email') {
            $expected = 'email address';
            $fields = array('emailAddress', 'identifier');
            $accept_mobile = false;
        } else {
            if ($parts[0] === 'mobile') {
                $expected = 'mobile number';
                $fields = array('mobileNumber', 'identifier');
            }
        }
    }
    if (!isset($_REQUEST['identifier'])) {
        throw new Q_Exception("a valid {$expected} is required", $fields);
    }
    if (!Q_Valid::email($_REQUEST['identifier'])) {
        if (!$accept_mobile) {
            throw new Q_Exception("a valid {$expected} is required", $fields);
        }
        if (!Q_Valid::phone($_REQUEST['identifier'])) {
            throw new Q_Exception("a valid {$expected} is required", $fields);
        }
    }
    $identifier = Users::requestedIdentifier($type);
    // check our db
    if ($user = Users::userFromContactInfo($type, $identifier)) {
        $verified = !!Users::identify($type, $identifier);
        return array('exists' => $user->id, 'verified' => $verified, 'username' => $user->username, 'icon' => $user->icon, 'passphrase_set' => !empty($user->passphraseHash), 'fb_uid' => $user->fb_uid ? $user->fb_uid : null);
    }
    if ($type === 'email') {
        $email = new Users_Email();
        Q_Valid::email($identifier, $normalized);
        $email->address = $normalized;
        $exists = $email->retrieve();
    } else {
        if ($type === 'mobile') {
            $mobile = new Users_Mobile();
            Q_Valid::phone($identifier, $normalized);
            $mobile->number = $normalized;
            $exists = $mobile->retrieve();
        }
    }
    if (empty($exists) and Q_Config::get('Users', 'login', 'noRegister', false)) {
        $nicetype = $type === 'email' ? 'email address' : 'mobile number';
        throw new Q_Exception("This {$nicetype} was not registered", array('identifier'));
    }
}
示例#2
0
文件: data.php 项目: dmitriz/Platform
function Users_user_response_data($params)
{
    $identifier = Users::requestedIdentifier($type);
    // check our db
    if ($user = Users::userFromContactInfo($type, $identifier)) {
        $verified = !!Users::identify($type, $identifier);
        return array('exists' => $user->id, 'verified' => $verified, 'username' => $user->username, 'icon' => $user->icon, 'passphrase_set' => !empty($user->passphraseHash), 'fb_uid' => $user->fb_uid ? $user->fb_uid : null);
    }
    if ($type === 'email') {
        $email = new Users_Email();
        Q_Valid::email($identifier, $normalized);
        $email->address = $normalized;
        $exists = $email->retrieve();
    } else {
        if ($type === 'mobile') {
            $mobile = new Users_Mobile();
            Q_Valid::phone($identifier, $normalized);
            $mobile->number = $normalized;
            $exists = $mobile->retrieve();
        }
    }
    if (empty($exists) and Q_Config::get('Users', 'login', 'noRegister', false)) {
        $nicetype = $type === 'email' ? 'email address' : 'mobile number';
        throw new Q_Exception("This {$nicetype} was not registered", array('identifier'));
    }
    // Get Gravatar info
    // WARNING: INTERNET_REQUEST
    $hash = md5(strtolower(trim($identifier)));
    $thumbnailUrl = Q_Request::baseUrl() . "/action.php/Users/thumbnail?hash={$hash}&size=80&type=" . Q_Config::get('Users', 'login', 'iconType', 'wavatar');
    $json = @file_get_contents("http://www.gravatar.com/{$hash}.json");
    $result = json_decode($json, true);
    if ($result) {
        if ($type === 'email') {
            $result['emailExists'] = !empty($exists);
        } else {
            if ($type === 'mobile') {
                $result['mobileExists'] = !empty($exists);
            }
        }
        return $result;
    }
    // otherwise, return default
    $email_parts = explode('@', $identifier, 2);
    $result = array("entry" => array(array("id" => "571", "hash" => "357a20e8c56e69d6f9734d23ef9517e8", "requestHash" => "357a20e8c56e69d6f9734d23ef9517e8", "profileUrl" => "http://gravatar.com/test", "preferredUsername" => ucfirst($email_parts[0]), "thumbnailUrl" => $thumbnailUrl, "photos" => array(), "displayName" => "", "urls" => array())));
    if ($type === 'email') {
        $result['emailExists'] = !empty($exists);
    } else {
        $result['mobileExists'] = !empty($exists);
    }
    if ($terms_label = Users::termsLabel('register')) {
        $result['termsLabel'] = $terms_label;
    }
    return $result;
}
示例#3
0
文件: post.php 项目: EGreg/PHP-On-Pie
function users_activate_post()
{
    $email_address = Pie_Dispatcher::uri()->email_address;
    $mobile_number = Pie_Dispatcher::uri()->mobile_number;
    $email = null;
    $mobile = null;
    if ($email_address) {
        $email = new Users_Email();
        $email->address = $email_address;
        // NOTE: not sharded by user_id
        if (!$email->retrieve()) {
            throw new Pie_Exception_MissingRow(array('table' => 'email', 'criteria' => "address = {$email_address}"));
        }
        $user = new Users_User();
        $user->id = $email->user_id;
        if (!$user->retrieve()) {
            throw new Pie_Exception_MissingRow(array('table' => 'user', 'criteria' => 'id = ' . $user->id));
        }
        if ($email->activation_code != $_REQUEST['code']) {
            throw new Pie_Exception("The activation code does not match.", 'code');
        }
        $user->setEmailAddress($email->address);
        // may throw exception
        $type = "email address";
    }
    if ($mobile_number) {
        $mobile = new Users_Mobile();
        $mobile->number = $mobile_number;
        // NOTE: not sharded by user_id
        if (!$mobile->retrieve()) {
            throw new Pie_Exception_MissingRow(array('table' => 'mobile phone', 'criteria' => "number = {$mobile_number}"));
        }
        $user = new Users_User();
        $user->id = $mobile->user_id;
        if (!$user->retrieve()) {
            throw new Pie_Exception_MissingRow(array('table' => 'user', 'criteria' => 'id = ' . $user->id));
        }
        if ($mobile->activation_code != $_REQUEST['code']) {
            throw new Pie_Exception("The activation code does not match.", 'code');
        }
        $user->setMobileNumber($mobile->number);
        // may throw exception
        $type = "mobile number";
    }
    if ($type) {
        Pie_Response::addNotice("users/activate", "Your {$type} has been activated.");
    }
    Users::$cache['user'] = $user;
}
示例#4
0
文件: tool.php 项目: dmitriz/Platform
function Users_identifier_tool($options)
{
    $defaults = array('uri' => 'Users/identifier', 'omit' => array(), 'fields' => array(), 'title' => "Contact Info", 'collapsed' => false, 'toggle' => false, 'editing' => true, 'complete' => true, 'inProcess' => false, 'prompt' => "In order for things to work, we must be able to reach you.", 'button_content' => 'OK');
    extract(array_merge($defaults, $options));
    $default_fields = array('emailAddress' => array('type' => 'text', 'label' => 'Email'));
    $fields = array_merge($default_fields, $fields);
    $user = Users::loggedInUser(true);
    $email = null;
    if (isset($user->emailAddress)) {
        $fields['emailAddress']['value'] = $user->emailAddress;
    } else {
        if ($user->emailAddressPending) {
            $link = Q_Html::a('#resend', array('class' => 'Users_idenfitier_tool_resend'), "You can re-send the activation email");
            $email = new Users_Email();
            $email->address = $user->emailAddressPending;
            if ($email->retrieve()) {
                switch ($email->state) {
                    case 'active':
                        if ($email->userId == $user->id) {
                            $message = "Please confirm this email address.<br>{$link}";
                        } else {
                            $message = "This email seems to belong to another user";
                        }
                        break;
                    case 'suspended':
                        $message = "This address has been suspended.";
                        break;
                    case 'unsubscribed':
                        $message = "The owner of this address has unsubscribed";
                        break;
                    case 'unverified':
                    default:
                        $message = "Not verified yet.<br>{$link}";
                        break;
                }
                $fields['emailAddress']['value'] = $email->address;
                $fields['emailAddress']['message'] = $message;
            } else {
                // something went wrong, so we'll try to correct it
                $user->emailAddressPending = "";
                $user->save();
            }
        }
    }
    $onSuccess = Q_Request::special('onSuccess', Q_Request::url());
    $form = $static = compact('fields');
    return Q::tool('Q/panel', compact('uri', 'onSuccess', 'form', 'static', 'title', 'collapsed', 'toggle', 'complete', 'editing', 'inProcess', 'setSlots'));
}
示例#5
0
function users_before_pie_response_notices()
{
    if ($user = Users::loggedInUser()) {
        if (empty($user->email_address)) {
            $email = new Users_Email();
            $email->user_id = $user->id;
            if ($email->retrieve()) {
                $resend_button = "<button id='notices_set_email'>try again</button>";
                Pie_Response::addNotice('email', "Please check your email to activate your account. Any problems, {$resend_button}");
            } else {
                $set_email_button = "<button id='notices_set_email'>set an email address</button> for your account.";
                Pie_Response::addNotice('email', "You need to {$set_email_button}");
            }
            Pie_Response::addScriptLine("jQuery(function() {\n\t\t\t\t\$('#notices_set_email').click(function() { Pie.Users.setEmail(); });\n\t\t\t}); ");
        }
    }
}
示例#6
0
文件: data.php 项目: dmitriz/Platform
function Streams_user_response_data($params)
{
    $identifier = Users::requestedIdentifier($type);
    $hash = md5(strtolower(trim($identifier)));
    $icon = Q_Config::get('Users', 'register', 'icon', 'leaveDefault', false) ? $url = "plugins/Users/img/icons/default/80.png" : Q_Request::baseUrl() . "/action.php/Users/thumbnail?hash={$hash}&size=80&type=" . Q_Config::get('Users', 'login', 'iconType', 'wavatar');
    // check our db
    if ($user = Users::userFromContactInfo($type, $identifier)) {
        $displayname = Streams::displayName($user);
        $verified = !!Users::identify($type, $identifier);
        return array('exists' => $user->id, 'verified' => $verified, 'username' => $user->username, 'displayName' => $displayname, 'icon' => $verified ? $icon : $user->icon, 'passphrase_set' => !empty($user->passphraseHash), 'fb_uid' => $user->fb_uid ? $user->fb_uid : null);
    }
    if ($type === 'email') {
        $email = new Users_Email();
        Q_Valid::email($identifier, $normalized);
        $email->address = $normalized;
        $exists = $email->retrieve();
    } else {
        if ($type === 'mobile') {
            $mobile = new Users_Mobile();
            Q_Valid::phone($identifier, $normalized);
            $mobile->number = $normalized;
            $exists = $mobile->retrieve();
        }
    }
    if (empty($exists) and Q_Config::get('Users', 'login', 'noRegister', false)) {
        $nicetype = $type === 'email' ? 'email address' : 'mobile number';
        throw new Q_Exception("This {$nicetype} was not registered", array('identifier'));
    }
    $result = array("entry" => array(array("thumbnailUrl" => $icon)));
    if ($type === 'email') {
        $result['emailExists'] = !empty($exists);
    } else {
        $result['mobileExists'] = !empty($exists);
    }
    if ($terms_label = Users::termsLabel('register')) {
        $result['termsLabel'] = $terms_label;
    }
    return $result;
}
示例#7
0
function Users_activate_objects_email($emailAddress, &$email)
{
    Q_Response::removeNotice('Users/activate/objects');
    $email = new Users_Email();
    if (!Q_Valid::email($emailAddress, $normalized)) {
        return;
    }
    $email->address = $normalized;
    if (!$email->retrieve()) {
        throw new Q_Exception_MissingRow(array('table' => 'email', 'criteria' => "address {$normalized}"));
    }
    $user = Users::loggedInUser();
    if ($user) {
        if ($user->id != $email->userId) {
            throw new Q_Exception("You are logged in as a different user. Please log out first.");
        }
    } else {
        $user = new Users_User();
        $user->id = $email->userId;
        if (!$user->retrieve()) {
            throw new Q_Exception("Missing user corresponding to this email address.", "emailAddress");
        }
    }
    if ($email->activationCode != $_REQUEST['code']) {
        throw new Q_Exception("The activation code does not match. Did you get a newer email?", 'code');
    }
    $timestamp = Users_Email::db()->getCurrentTimestamp();
    if ($timestamp > Users_Email::db()->fromDateTime($email->activationCodeExpires)) {
        throw new Q_Exception("Activation code expired");
    }
    if (Q_Request::method() !== 'POST' and empty($_REQUEST['p']) and isset($user->emailAddress) and $user->emailAddress == $email->address) {
        $displayName = Streams::displayName($user);
        Q_Response::setNotice('Users/activate/objects', "{$normalized} has already been activated for {$displayName}", true);
        return $user;
    }
    return $user;
}
示例#8
0
文件: tool.php 项目: dmitriz/Platform
/**
 * Subscription tool
 * @param array $options
 *  "publisherId" => the id of the user who is publishing the stream
 *  "streamName" => the name of the stream for which to edit access levels
 */
function Streams_subscription_tool($options)
{
    $subscribed = 'no';
    extract($options);
    $user = Users::loggedInUser(true);
    if (!isset($publisherId)) {
        $publisherId = Streams::requestedPublisherId(true);
    }
    if (!isset($streamName)) {
        $streamName = Streams::requestedName();
    }
    $stream = Streams::fetchOne($user->id, $publisherId, $streamName);
    if (!$stream) {
        throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => compact('publisherId', 'streamName')));
    }
    $streams_participant = new Streams_Participant();
    $streams_participant->publisherId = $publisherId;
    $streams_participant->streamName = $streamName;
    $streams_participant->userId = $user->id;
    if ($streams_participant->retrieve()) {
        $subscribed = $streams_participant->subscribed;
    }
    $types = Q_Config::get('Streams', 'types', $stream->type, 'messages', array());
    $messageTypes = array();
    foreach ($types as $type => $msg) {
        $name = Q::ifset($msg, 'title', $type);
        /*
         * group by name
         */
        foreach ($messageTypes as $msgType) {
            if ($msgType['name'] == $name) {
                continue 2;
            }
        }
        $messageTypes[] = array('value' => $type, 'name' => $name);
    }
    $usersFetch = array('userId' => $user->id, 'state' => 'active');
    $devices = array();
    $emails = Users_Email::select('address')->where($usersFetch)->fetchAll(PDO::FETCH_COLUMN);
    $mobiles = Users_Mobile::select('number')->where($usersFetch)->fetchAll(PDO::FETCH_COLUMN);
    foreach ($emails as $email) {
        $devices[] = array('value' => Q::json_encode(array('email' => $email)), 'name' => 'my email');
    }
    foreach ($mobiles as $mobile) {
        $devices[] = array('value' => Q::json_encode(array('mobile' => $mobile)), 'name' => 'my mobile');
    }
    $items = array();
    $rules = Streams_Rule::select('deliver, filter')->where(array('ofUserId' => $user->id, 'publisherId' => $publisherId, 'streamName' => $streamName))->fetchAll(PDO::FETCH_ASSOC);
    while ($rule = array_pop($rules)) {
        $filter = json_decode($rule['filter']);
        /*
         * group by name
         */
        foreach ($rules as $val) {
            if (json_decode($val['filter'])->labels == $filter->labels) {
                continue 2;
            }
        }
        $items[] = array('deliver' => json_decode($rule['deliver']), 'filter' => $filter);
    }
    Q_Response::addScript("plugins/Streams/js/Streams.js");
    Q_Response::addScript("plugins/Streams/js/tools/subscription.js");
    Q_Response::setToolOptions(compact('items', 'subscribed', 'messageTypes', 'devices', 'publisherId', 'streamName'));
}
示例#9
0
文件: User.php 项目: dmitriz/Platform
 /**
  * @method setEmailAddress
  * @param {string} $emailAddress
  * @param {boolean} [$verified=false]
  * @throws {Q_Exception_MissingRow}
  *	If e-mail address is missing
  * @throws {Users_Exception_AlreadyVerified}
  *	If user is already verified
  * @throws {Users_Exception_WrongState}
  *	If verification state is wrong
  */
 function setEmailAddress($emailAddress, $verified = false)
 {
     $email = new Users_Email();
     Q_Valid::email($emailAddress, $normalized);
     $email->address = $normalized;
     $retrieved = $email->retrieve('*', array('ignoreCache' => true));
     if (empty($email->activationCode)) {
         $email->activationCode = '';
         $email->activationCodeExpires = '0000-00-00 00:00:00';
     }
     $email->authCode = md5(microtime() + mt_rand());
     if ($verified) {
         $email->userId = $this->id;
     } else {
         if (!$retrieved) {
             throw new Q_Exception_MissingRow(array('table' => "an email", 'criteria' => "address {$emailAddress}"), 'emailAddress');
         }
         if ($email->userId != $this->id) {
             // We're going to tell them it's verified for someone else,
             // even though it may not have been verified yet.
             // In the future, might throw a more accurate exception.
             throw new Users_Exception_AlreadyVerified(array('key' => 'email address', 'userId' => $email->userId));
         }
         if (!in_array($email->state, array('unverified', 'active'))) {
             throw new Users_Exception_WrongState(array('key' => $email->address, 'state' => $email->state), 'emailAddress');
         }
     }
     // Everything is okay. Assign it!
     $email->state = 'active';
     $email->save();
     $ui = new Users_Identify();
     $ui->identifier = "email_hashed:" . Q_Utils::hash($normalized);
     $ui->state = 'verified';
     $ui->userId = $this->id;
     $ui->save(true);
     $this->emailAddressPending = '';
     $this->emailAddress = $emailAddress;
     $this->save();
     $user = $this;
     Q_Response::removeNotice('Users/email');
     /**
      * @event Users/setEmailAddress {after}
      * @param {string} user
      * @param {string} email
      */
     Q::event('Users/setEmailAddress', compact('user', 'email'), 'after');
     return true;
 }
示例#10
0
function Shipping_scheduled_post()
{
    $env = Shipping::getVars();
    if (empty($_REQUEST["streamName"])) {
        throw new Q_Exception_WrongValue(array('field' => 'streamName', 'range' => "not empty"));
    }
    if (empty($_REQUEST["to"]["street"])) {
        throw new Q_Exception_WrongValue(array('field' => 'destination address street', 'range' => "not empty"));
    }
    if (empty($_REQUEST["to"]["city"])) {
        throw new Q_Exception_WrongValue(array('field' => 'destination address city', 'range' => "not empty"));
    }
    if (empty($_REQUEST["to"]["zipcode"])) {
        throw new Q_Exception_WrongValue(array('field' => 'destination address zipcode', 'range' => "not empty"));
    }
    if (empty($_REQUEST["to"]["country"])) {
        throw new Q_Exception_WrongValue(array('field' => 'destination address country', 'range' => "not empty"));
    }
    //if(empty($_REQUEST["to"]["state"])) throw new Q_Exception_WrongValue(array('field' => 'destination address state', 'range' => "not empty"));
    if (empty($_REQUEST["from"]["street"])) {
        throw new Q_Exception_WrongValue(array('field' => 'origin address street', 'range' => "not empty"));
    }
    if (empty($_REQUEST["from"]["city"])) {
        throw new Q_Exception_WrongValue(array('field' => 'origin address city', 'range' => "not empty"));
    }
    if (empty($_REQUEST["from"]["zipcode"])) {
        throw new Q_Exception_WrongValue(array('field' => 'origin address zipcode', 'range' => "not empty"));
    }
    if (empty($_REQUEST["from"]["country"])) {
        throw new Q_Exception_WrongValue(array('field' => 'origin address country', 'range' => "not empty"));
    }
    //if(empty($_REQUEST["from"]["state"])) throw new Q_Exception_WrongValue(array('field' => 'original address state', 'range' => "not empty"));
    if (empty($_REQUEST['packages'])) {
        throw new Q_Exception_WrongValue(array('field' => 'packages', 'range' => "not empty"));
    }
    if (empty($_REQUEST["carrier"]) || !count($_REQUEST["carrier"])) {
        throw new Q_Exception_WrongValue(array('field' => 'carrier', 'range' => "not empty"));
    }
    if (empty($_REQUEST["dateScheduled"])) {
        throw new Q_Exception_WrongValue(array('field' => 'dateScheduled', 'range' => "not empty"));
    }
    if (empty($_REQUEST["asUser"])) {
        $_REQUEST["asUser"] = $env->userId;
    }
    $user = Users::loggedInUser(true);
    //print_r($user); exit;
    $email = new Users_Email();
    $email->address = $user->emailAddress ?: $user->emailAddressPending;
    $email->userId = $user->id;
    //$email->save();
    //$shipmentStream = Shipping::shipment();
    $shipmentStream = Streams::fetchOne($env->communityId, $env->communityId, $_REQUEST["streamName"]);
    //$shipmentStream->clearAllAttributes();
    $shipmentStream->title = Q::ifset($_REQUEST, 'title', "(empty)");
    $shipmentStream->userId = $env->userId;
    $shipmentStream->destination = json_encode($_REQUEST["to"]);
    $shipmentStream->origin = json_encode($_REQUEST["from"]);
    $shipmentStream->receiver = json_encode(Q::ifset($_REQUEST, 'receiver', new StdClass()));
    $shipmentStream->dateScheduled = Q::ifset($_REQUEST, 'dateScheduled', "");
    // set packages
    $packages = Q::ifset($_REQUEST, 'packages', new StdClass());
    if (!is_object($packages)) {
        $packages["totalWeight"] = 0;
        $packages["totalVolume"] = 0;
        $packages["totalAmount"] = 0;
        foreach ($packages["packages"] as $key => $package) {
            if (!isset($package['weight'])) {
                throw new Q_Exception("One of the packages doesn't have its weight set");
            }
            $packages["totalWeight"] += $package["weight"];
            $volume = round((double) $package["width"] * (double) $package["height"] * (double) $package["length"], 3);
            $packages["totalVolume"] += $volume;
            $packages["packages"][$key]["volume"] = $volume;
            //$totalValue = round((float)$package["value"] * (int)$package["quantity"], 2);
            //$packages["packages"][$key]["totalValue"] = $totalValue;
            //$packages["totalInvoiceValue"] += $totalValue;
            $packages["totalAmount"]++;
        }
    }
    // set products
    $products = Q::ifset($_REQUEST, 'products', new StdClass());
    if (!is_object($products)) {
        $products["totalWeight"] = 0;
        $products["totalAmount"] = 0;
        $products["totalInvoiceValue"] = 0;
        foreach ($products["packages"] as $key => $product) {
            // $products["totalWeight"] += $product["weight"];
            //$volume = round($product["w"] * $product["h"] * $product["l"], 3);
            //$packages["totalVolume"] += $volume;
            //$products["packages"][$key]["volume"] = $volume;
            $totalValue = round((double) $product["value"] * (int) $product["quantity"], 2);
            $products["packages"][$key]["totalValue"] = $totalValue;
            $products["totalInvoiceValue"] += $totalValue;
            $products["totalAmount"]++;
        }
    }
    $shipmentStream->packages = json_encode($packages);
    $shipmentStream->products = json_encode($products);
    $shipmentStream->carrier = json_encode(Shipping_Carrier::createCarrier($shipmentStream, $_REQUEST["carrier"]));
    $shipmentStream->invoiceOptions = json_encode(Q::ifset($_REQUEST, 'invoice', new StdClass()));
    $shipmentStream->collectInstructions = json_encode(Q::ifset($_REQUEST, 'collect', new StdClass()));
    // set template attributes
    $isTemplate = (bool) $_REQUEST["isTemplate"];
    if ($isTemplate) {
        $shipmentStream->setAttribute("isTemplate", true);
        $shipmentStream->setAttribute("templateName", $_REQUEST["template"]["templateName"]);
    } else {
        $shipmentStream->clearAttribute("isTemplate");
        $shipmentStream->clearAttribute("templateName");
    }
    // set asUser attribute
    $shipmentStream->setAttribute("asUser", $_REQUEST["asUser"]);
    $shipmentStream->setAttribute("fromUser", $env->userId);
    $shipmentStream->save();
    $isPickupLater = (bool) $_REQUEST["isPickupLater"];
    //throw new exception("Test!");
    // return if action = invoice preview
    if ($_REQUEST["isPreview"]) {
        return;
    }
    // relate to category stream "Shipping/templates"
    if ($isTemplate) {
        Shipping::shipmentToTemplate($shipmentStream);
    }
    // create carrier object
    if (empty($_REQUEST["carrier"]["name"])) {
        throw new Q_Exception_WrongValue(array('field' => 'carrier name', 'range' => "not empty"));
    }
    $carrierClassName = "Shipping_Carrier_" . $_REQUEST["carrier"]["name"];
    if (!class_exists($carrierClassName)) {
        throw new exception("carrier class " . $carrierClassName . " don't exist!");
    }
    $carrier = new $carrierClassName();
    // trying to send shipment
    $carrier->ship($shipmentStream, $isPickupLater);
    // send shipment confirmation to user
    if ($email->address) {
        $email->sendMessage(Q_Config::get('Users', 'transactional', 'scheduled', 'subject', false), Q_Config::get('Users', 'transactional', 'scheduled', 'body', false), array('user' => $user, 'shipment' => $shipmentStream), array('html' => false));
        // may throw exception if badly configured
    }
    //Q_Request::requireFields(array('streamName'), $_REQUEST, true);
    //$params = Q::take($_REQUEST, array("streamName"));
    //$stream = Streams::fetchOne($userId, $userId, $params["streamName"]);
}
示例#11
0
文件: User.php 项目: EGreg/PHP-On-Pie
 function setEmailAddress($email_address)
 {
     $e = new Users_Email();
     $e->address = $email_address;
     if (!$e->retrieve()) {
         throw new Pie_Exception_MissingRow(array('table' => "an email", 'criteria' => "address {$email_address}"), 'email_address');
     }
     if ($e->user_id != $this->id) {
         // We're going to tell them it's verified for someone else,
         // even though it may not have been verified yet.
         // In the future, might throw a more accurate exception.
         throw new Users_Exception_AlreadyVerified(array('key' => $e->address, 'user_id' => $e->user_id));
     }
     if ($e->state != 'unverified') {
         throw new Users_Exception_WrongState(array('key' => $e->address, 'state' => $e->state), 'email_address');
     }
     // Everything is okay. Assign it!
     $this->email_address = $email_address;
     $e->state = 'active';
     $e->save();
     Pie::event('users/setEmailAddress', compact('email_address'), 'after');
     return true;
 }
示例#12
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);
            }
        }
    }
}