function createaccountAction() { $xn_uid = $this->_source_id; $currentTime = date("Y-m-d H:i:s"); // save new consumer $consumerModel = new Consumer(); $row = $consumerModel->createRow(); $row->name = "校内用户"; $row->email = "xiaonei_" . $xn_uid; $row->password = md5($xn_uid); $row->save(); $db = Zend_Registry::get('db'); $select_new_consumer = $db->select(); $select_new_consumer->from('consumer', '*'); $select_new_consumer->where('email=?', 'xiaonei_' . $xn_uid); $new_consumer = $db->fetchRow($select_new_consumer); $externalConsumerModel = new ExternalConsumer(); $row = $externalConsumerModel->createRow(); $row->source_id = $xn_uid; $row->source_type = 'xiaonei'; $row->consumer_id = $new_consumer['id']; $row->start_date = $currentTime; $row->save(); $this->_currentUser = $new_consumer; }
public function indexAction() { $lang = $this->_request->getParam('lang'); $langNamespace = new Zend_Session_Namespace('Lang'); $langNamespace->lang = $lang; // Zend_Debug::dump($_SERVER["HTTP_REFERER"]); if (isset($this->_currentUser->id)) { $consumerModel = new Consumer(); $consumer = $consumerModel->fetchRow('id = ' . $this->_currentUser->id); if ($consumer != null) { $consumer->language_pref = $lang; $consumer->save(); } else { $adminModel = new Admin(); $admin = $adminModel->fetchRow('id = ' . $this->_currentUser->id); if ($admin != null) { $admin->language_pref = $lang; $admin->save(); } } } $messageArray = $this->_flashMessenger->getMessages(); if ($messageArray != null) { foreach ($messageArray as $message) { $this->_flashMessenger->addMessage($message); } } $this->_helper->redirector->gotoUrl($_SERVER["HTTP_REFERER"]); }
public function setUp() { $consumer = new Consumer(); $consumer->addBrokers('localhost:9092'); $this->consumerTopic = $consumer->newTopic('test'); $this->queue = $consumer->newQueue(); }
/** * Generate the oauth_signature parameter * @return string */ public function generateSignature() { $keyString = rawurlencode($this->consumer->getSecret()) . '&'; if ($this->accessCredential !== null) { $keyString .= \rawurlencode($this->accessCredential->getSecret()); } $baseString = $this->request->getBaseString(self::SIGNATURE_METHOD); return \base64_encode(hash_hmac('sha1', $baseString, $keyString, true)); }
function adminajaxsearchAction() { $this->_helper->layout->disableLayout(); if ($this->_request->isPost()) { $formData = $this->_request->getPost(); $consumerNum = $formData['consumerphone']; $consumerModel = new Consumer(); $consumers = $consumerModel->fetchAll('login_phone like "%' . $consumerNum . '%" or phone like "%' . $consumerNum . '%"'); $consumer = $consumers[0]; $this->view->consumer = $consumer; } }
public function loginAction() { $request = $this->getRequest(); $config = Zend_Registry::get('config'); // Check if we have a POST request if (!$request->isPost()) { $this->_helper->redirector('index', 'index'); } $lang = $this->getRequest()->getPost('lang'); if (isset($lang) && $lang != null) { $langNamespace = new Zend_Session_Namespace('Lang'); $langNamespace->lang = $lang; } // Get our form and validate it $form = new LoginForm(); if (!$form->isValid($request->getPost())) { // Invalid entries $this->_flashMessenger->addMessage('Email or Password is required and its length should between 6 and 20'); $this->view->form = $form; $this->_helper->redirector('loginfailed', 'index'); } // Get our authentication adapter and check credentials $adapter = new LoginAuthAdapter($form->getValue('email'), $form->getValue('password')); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($adapter); if ($result->isValid()) { // We're authenticated! Redirect to the home page $db = Zend_Registry::get('db'); $consumer_id = $db->fetchOne("SELECT id FROM consumer WHERE email = :temp or login_phone = :temp and state='ACTIVE'", array('temp' => $form->getValue('email'))); $consumerModel = new Consumer(); $consumer = $consumerModel->find($consumer_id)->current(); $authNamespace = new Zend_Session_Namespace('Zend_Auth'); $authNamespace->user = $consumer; $authNamespace->role = 'consumer'; //log $logModel = new Log(); $logId = $logModel->insert(array('consumer_id' => $consumer->id, 'date' => date("Y-m-d H:i:s"), 'event' => 'LOGIN')); $url = $form->getValue('url'); if (isset($url) && !empty($url)) { $this->_redirector = $this->_helper->getHelper('Redirector'); $this->_redirector->gotoUrl($url); } else { $this->_helper->redirector('index', 'home'); } } else { // Invalid credentials $this->_flashMessenger->addMessage('Invalid credentials provided'); $this->view->form = $form; $this->_helper->redirector('loginfailed', 'index'); } }
public function testConsumeShouldExecuteGivenCallback() { $eventDispatcher = new \Armadillo\EventDispatcher(); $consumer = new Consumer($this->queue, $eventDispatcher); $callbackWasExecuted = false; $eventDispatcherClass = ""; $consumeCallback = function ($message, $eventDispatcher) use(&$callbackWasExecuted, &$eventDispatcherClass) { $callbackWasExecuted = true; $eventDispatcherClass = get_class($eventDispatcher); }; $consumer->consume($consumeCallback); $this->assertTrue($callbackWasExecuted); $this->assertEquals("Armadillo\\EventDispatcher", $eventDispatcherClass); }
public function authenticate() { $db = Zend_Registry::get('db'); $rs = $db->fetchAll("SELECT id FROM consumer WHERE weiboid=:weiboid and state='ACTIVE'", array('weiboid' => $this->_weiboid)); if (count($rs) > 0) { return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->_weiboid); } else { if (isset($this->_weiboid) && '' != $this->_weiboid) { $consumerModel = new Consumer(); $consumerModel->insert(array('name' => '微博用户', 'weiboid' => $this->_weiboid, 'state' => 'ACTIVE')); } return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $this->_weiboid); } }
function lookup_consumer($consumer_key) { $con = Consumer::staticGet('consumer_key', $consumer_key); if (!$con) { $con = new Consumer(); $con->consumer_key = $consumer_key; $con->seed = common_good_rand(16); $con->created = DB_DataObject_Cast::dateTime(); if (!$con->insert()) { return null; } } return new OAuthConsumer($con->consumer_key, ''); }
public function setUp() { $producer = new Producer(); $producer->addBrokers('localhost:9092'); /** @var ProducerTopic $producerTopic */ $producerTopic = $producer->newTopic('test'); $producerTopic->produce(RD_KAFKA_PARTITION_UA, self::PARTITION, 'test message 2', 'key_2'); $consumer = new Consumer(); $consumer->addBrokers('localhost:9092'); /** @var ConsumerTopic $consumerTopic */ $consumerTopic = $consumer->newTopic('test'); $consumerTopic->consumeStart(self::PARTITION, self::OFFSET); $this->message = $consumerTopic->consume(self::PARTITION, 1000); $consumerTopic->consumeStop(self::PARTITION); }
function lookup_consumer($consumerKey) { $con = Consumer::getKV('consumer_key', $consumerKey); if (!$con instanceof Consumer) { // Create an anon consumer and anon application if one // doesn't exist already if ($consumerKey == 'anonymous') { common_debug("API OAuth - creating anonymous consumer"); $con = new Consumer(); $con->consumer_key = $consumerKey; $con->consumer_secret = $consumerKey; $con->created = common_sql_now(); $result = $con->insert(); if (!$result) { // TRANS: Server error displayed when trying to create an anynymous OAuth consumer. $this->serverError(_('Could not create anonymous consumer.')); } $app = Oauth_application::getByConsumerKey('anonymous'); if (!$app) { common_debug("API OAuth - creating anonymous application"); $app = new OAuth_application(); $app->owner = 1; // XXX: What to do here? $app->consumer_key = $con->consumer_key; $app->name = 'anonymous'; $app->icon = 'default-avatar-stream.png'; // XXX: Fix this! $app->description = "An anonymous application"; // XXX: allow the user to set the access type when // authorizing? Currently we default to r+w for anonymous // OAuth client applications $app->access_type = 3; // read + write $app->type = 2; // desktop $app->created = common_sql_now(); $id = $app->insert(); if (!$id) { // TRANS: Server error displayed when trying to create an anynymous OAuth application. $this->serverError(_("Could not create anonymous OAuth application.")); } } } else { return null; } } return new OAuthConsumer($con->consumer_key, $con->consumer_secret); }
/** * ツイートを更新 * @param Model $Model * @param boolean $status * @return mixed 成功時:XML / 失敗時:エラーメッセージ */ function update(&$Model, $status) { if (mb_strlen($status, 'UTF-8') > 140) { return false; } return $this->consumer->post($this->accessTokenKey, $this->accessTokenSecret, $this->updateUri, array('status' => $status)); }
public function testCreateConsumerFromXML() { $xml = file_get_contents(__DIR__ . '/../samples/consumer.xml'); $sxe = new \SimpleXMLElement($xml); $xmlElement = $sxe->consumer; $correctConsumer = new Consumer('f4e3c8b7f1c0b57a2313bd92dbeff7c2', '94238234899842389743298897247892', 'testchannel'); $this->assertEquals($correctConsumer, Consumer::parseFromXml($xmlElement)); }
function lookup_consumer($consumer_key) { $con = Consumer::staticGet('consumer_key', $consumer_key); if (!$con) { return null; } return new OAuthConsumer($con->consumer_key, $con->consumer_secret); }
public function testConsumerProperties() { $consumer = new Consumer(); $consumerKey = 'testConsumerKey'; $consumer->setConsumerKey($consumerKey); $consumerSecret = 'testConsumerSecret'; $consumer->setConsumerSecret($consumerSecret); $consumerName = 'testConsumer'; $consumer->setName($consumerName); $this->assertEquals($consumerKey, $consumer->getConsumerKey()); $this->assertEquals($consumerSecret, $consumer->getConsumerSecret()); $this->assertEquals($consumerName, $consumer->getName()); }
/** * Attempt a request based on the current configured OAuth Request Scheme and * return the resulting HTTP Response. * * @param array $params * @return \Zend\Http\Response */ protected function _attemptRequest(array $params) { switch ($this->_preferredRequestScheme) { case OAuth::REQUEST_SCHEME_HEADER: $httpClient = $this->getRequestSchemeHeaderClient($params); break; case OAuth::REQUEST_SCHEME_POSTBODY: $httpClient = $this->getRequestSchemePostBodyClient($params); break; case OAuth::REQUEST_SCHEME_QUERYSTRING: $httpClient = $this->getRequestSchemeQueryStringClient($params, $this->_consumer->getRequestTokenUrl()); break; } return $httpClient->send(); }
//echo $tweet_object; // Ignore tweets without a properly formed tweet id value if (!isset($tweet_object->id_str)) { return; } $tweet_id = $tweet_object->id_str; $raw_tweet = base64_encode(serialize($tweet_object)); $field_values = 'raw_tweet = "' . $raw_tweet . '", ' . 'tweet_id = ' . $tweet_id; $this->oDB->insert('json_cache', $field_values); } } //Connection to the local database $con = new config(DB_HOST, DB_USER, DB_PASS, DB_NAME); $db = new Database($con); $db->openConnection(); // Open a persistent connection to the Twitter streaming API $stream = new Consumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); // Establish a MySQL database connection $stream->db_connect(); $hashtagArray = array(); $query = $db->query('SELECT hashtagName FROM tbl_hashtag'); if ($db->hasRows($query) > 0) { while ($row = $db->fetchAssoc($query)) { array_push($hashtagArray, $row['hashtagName']); } //$stream->setTrack($hashtagArray); } $stream->setTrack(array('#IfCBIRaids')); // Start collecting tweets // Automatically call enqueueStatus($status) with each tweet's JSON data $stream->consume();
/** * @covers MediaCore\OAuth\Consumer::getSecret */ public function testSecret() { $this->assertEquals('mySecret', $this->consumer->getSecret()); }
function adminaddreportAction() { $this->_helper->layout->setLayout("layout_admin"); $consumer = $this->_request->getParam('uid'); if ($this->_request->getParam('file')) { $file = explode('&', $this->_request->getParam('file')); $file = $file[0]; $this->view->file = "./surveys/" . $file . ".phtml"; $this->_helper->layout->setLayout("layout_questionnaire"); } $campaignModel = new Campaign(); $campaignData = $campaignModel->fetchAll(); $this->view->campaigns = $campaignData; $this->view->sources = array('application', 'phone', 'email', 'sms'); $postData = $this->_request->getPost(); if (count($postData)) { $this->view->campaign = $postData['campaign']; $this->view->source = $postData['source']; $adminAddSession = new Zend_Session_Namespace('adminAddSession'); $adminAddSession->consumer = $consumer; $adminAddSession->source = $postData['source']; $adminAddSession->campaign = $postData['campaign']; foreach ($campaignData as $campaign) { if ($campaign->id == $postData['campaign']) { $this->view->link = $campaign->i2_survey_id; $this->view->surveyId = $campaign->i2_survey_id; } } } if ($this->_request->getParam('survey')) { $this->view->surveyId = $this->_request->getParam('survey'); } $consumerModel = new Consumer(); $this->view->consumer = $consumerModel->fetchRow('id=' . $consumer); $this->view->uid = $consumer; }
/** * Reset an application's Consumer key and secret * * XXX: Should this be moved to its own page with a confirm? * */ function resetKey() { $this->application->query('BEGIN'); $oauser = new Oauth_application_user(); $oauser->application_id = $this->application->id; $result = $oauser->delete(); if ($result === false) { common_log_db_error($oauser, 'DELETE', __FILE__); $this->success = false; $this->msg = 'Unable to reset consumer key and secret.'; $this->showPage(); return; } $consumer = $this->application->getConsumer(); $result = $consumer->delete(); if ($result === false) { common_log_db_error($consumer, 'DELETE', __FILE__); $this->success = false; $this->msg = 'Unable to reset consumer key and secret.'; $this->showPage(); return; } $consumer = Consumer::generateNew(); $result = $consumer->insert(); if (empty($result)) { common_log_db_error($consumer, 'INSERT', __FILE__); $this->application->query('ROLLBACK'); $this->success = false; $this->msg = 'Unable to reset consumer key and secret.'; $this->showPage(); return; } $orig = clone $this->application; $this->application->consumer_key = $consumer->consumer_key; $result = $this->application->update($orig); if ($result === false) { common_log_db_error($application, 'UPDATE', __FILE__); $this->application->query('ROLLBACK'); $this->success = false; $this->msg = 'Unable to reset consumer key and secret.'; $this->showPage(); return; } $this->application->query('COMMIT'); $this->success = true; $this->msg = 'Consumer key and secret reset.'; $this->showPage(); }
/** * Get the base64 encoded OAuth signature * * @param Consumer $consumer * @param string $baseString * @return string */ public function buildSignature($consumer, $baseString) { $signingKey = rawurlencode($consumer->getSecret()) . '&'; return base64_encode(hash_hmac('sha1', $baseString, $signingKey, true)); }
function getConsumer() { return Consumer::staticGet('consumer_key', $this->consumer_key); }
function activateAction() { $this->_helper->layout->disableLayout(); $activateCode = $this->_request->getParam('p'); $message = ''; $activeLink = $this->view->home . '/public/register/activate/p/' . $activateCode; $temporaryLink = new TemporaryLink(); $temporaryLinkData = $temporaryLink->fetchRow('link like "%' . $activeLink . '%"'); $conumserModel = new Consumer(); $consumerData = $conumserModel->fetchRow('email like "%' . $temporaryLinkData->email . '%"'); if ($consumerData->state == 'ACTIVE') { $message = $this->view->translate('Has_actived'); } elseif ($temporaryLinkData->expire_date < date("Y-m-d H:i:s")) { $message = $this->view->translate('OutOfDate_register'); } else { $consumerData->state = 'ACTIVE'; $consumerData->save(); } $this->view->message = $message; }
require_once 'db_lib.php'; $this->oDB = new db(); } // This function is called automatically by the Phirehose class // when a new tweet is received with the JSON data in $status public function enqueueStatus($status) { $tweet_object = json_decode($status); // Ignore tweets without a properly formed tweet id value if (!isset($tweet_object->id_str)) { return; } $tweet_id = $tweet_object->id_str; // If there's a ", ', :, or ; in object elements, serialize() gets corrupted // You should also use base64_encode() before saving this $raw_tweet = base64_encode(serialize($tweet_object)); $field_values = 'raw_tweet = "' . $raw_tweet . '", ' . 'tweet_id = ' . $tweet_id; $this->oDB->insert('json_cache', $field_values); } } // Open a persistent connection to the Twitter streaming API $stream = new Consumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); // Establish a MySQL database connection $stream->db_connect(); // The keywords for tweet collection are entered here as an array // More keywords can be added as array elements // For example: array('recipe','food','cook','restaurant','great meal') $stream->setTrack(['#ExampleHashtag']); // Start collecting tweets // Automatically call enqueueStatus($status) with each tweet's JSON data $stream->consume();
# # GET https://<endpoint>/Consumer/LoginNameCheck/[LoginName] # $app->get('/LoginNameCheck/:LoginName', function ($LoginName) use($app) { $consumer = new Consumer($app); echo $consumer->checkLoginName($LoginName); }); # # ������ע�ᡪ���Ͷ�����֤�� # # POST https://<endpoint>/Consumer/SmsCode/ # # Request Body # { # "Telephone":"�绰" # } # $app->post('/SmsCode/', function () use($app) { $consumer = new Consumer($app); echo $consumer->postSmsCode(); }); # # ������ע�ᡪ��֤������ # # GET https://<endpoint>/Consumer/SmsCode/[SmsCodeId]/[UserSmsCode]/[Telephone] # $app->get('/SmsCode/:SmsCodeId/:UserSmsCode/:Telephone', function ($SmsCodeId, $UserSmsCode, $Telephone) use($app) { $consumer = new Consumer($app); echo $consumer->verifySmsCode($SmsCodeId, $UserSmsCode, $Telephone); }); });
private function trySave() { $name = $this->trimmed('name'); $description = $this->trimmed('description'); $source_url = $this->trimmed('source_url'); $organization = $this->trimmed('organization'); $homepage = $this->trimmed('homepage'); $callback_url = $this->trimmed('callback_url'); $type = $this->arg('app_type'); $access_type = $this->arg('default_access_type'); if (empty($name)) { // TRANS: Validation error shown when not providing a name in the "New application" form. $this->clientError(_('Name is required.')); } else { if ($this->nameExists($name)) { // TRANS: Validation error shown when providing a name for an application that already exists in the "New application" form. $this->clientError(_('Name already in use. Try another one.')); } elseif (mb_strlen($name) > 255) { // TRANS: Validation error shown when providing too long a name in the "New application" form. $this->clientError(_('Name is too long (maximum 255 characters).')); } elseif (empty($description)) { // TRANS: Validation error shown when not providing a description in the "New application" form. $this->clientError(_('Description is required.')); } elseif (Oauth_application::descriptionTooLong($description)) { $this->clientError(sprintf(_m('Description is too long (maximum %d character).', 'Description is too long (maximum %d characters).', Oauth_application::maxDesc()), Oauth_application::maxDesc())); } elseif (empty($source_url)) { // TRANS: Validation error shown when not providing a source URL in the "New application" form. $this->clientError(_('Source URL is required.')); } elseif (strlen($source_url) > 0 && !common_valid_http_url($source_url)) { // TRANS: Validation error shown when providing an invalid source URL in the "New application" form. $this->clientError(_('Source URL is not valid.')); } elseif (empty($organization)) { // TRANS: Validation error shown when not providing an organisation in the "New application" form. $this->clientError(_('Organization is required.')); } elseif (mb_strlen($organization) > 255) { // TRANS: Validation error shown when providing too long an arganisation name in the "Edit application" form. $this->clientError(_('Organization is too long (maximum 255 characters).')); } elseif (empty($homepage)) { // TRANS: Form validation error show when an organisation name has not been provided in the new application form. $this->clientError(_('Organization homepage is required.')); } elseif (strlen($homepage) > 0 && !common_valid_http_url($homepage)) { // TRANS: Validation error shown when providing an invalid homepage URL in the "New application" form. $this->clientError(_('Homepage is not a valid URL.')); } elseif (mb_strlen($callback_url) > 255) { // TRANS: Validation error shown when providing too long a callback URL in the "New application" form. $this->clientError(_('Callback is too long.')); } elseif (strlen($callback_url) > 0 && !common_valid_http_url($callback_url)) { // TRANS: Validation error shown when providing an invalid callback URL in the "New application" form. $this->clientError(_('Callback URL is not valid.')); } } // Login is checked in parent::prepare() assert(!is_null($this->scoped)); $app = new Oauth_application(); $app->query('BEGIN'); $app->name = $name; $app->owner = $this->scoped->id; $app->description = $description; $app->source_url = $source_url; $app->organization = $organization; $app->homepage = $homepage; $app->callback_url = $callback_url; $app->type = $type; // Yeah, I dunno why I chose bit flags. I guess so I could // copy this value directly to Oauth_application_user // access_type which I think does need bit flags -- Z if ($access_type == 'r') { $app->setAccessFlags(true, false); } else { $app->setAccessFlags(true, true); } $app->created = common_sql_now(); // generate consumer key and secret $consumer = Consumer::generateNew(); $result = $consumer->insert(); if (!$result) { common_log_db_error($consumer, 'INSERT', __FILE__); $app->query('ROLLBACK'); // TRANS: Server error displayed when an application could not be registered in the database through the "New application" form. $this->serverError(_('Could not create application.')); } $app->consumer_key = $consumer->consumer_key; $this->app_id = $app->insert(); if (!$this->app_id) { common_log_db_error($app, 'INSERT', __FILE__); $app->query('ROLLBACK'); // TRANS: Server error displayed when an application could not be registered in the database through the "New application" form. $this->serverError(_('Could not create application.')); } try { $app->uploadLogo(); } catch (Exception $e) { $app->query('ROLLBACK'); // TRANS: Form validation error messages displayed when uploading an invalid application logo. $this->clientError(_('Invalid image.')); } $app->query('COMMIT'); common_redirect(common_local_url('oauthappssettings'), 303); }
/** * 查找好友 * * @param int $user_id //用户id * @param string $nickname //查找好友昵称 * */ public function findFriend($user_id, $nickname) { $data = array(); //查看是否有此人 $friend_id = User::model()->getUserId($nickname); if ($friend_id < 1) { return false; } $info = Consumer::model()->getUserAll($friend_id); if (!empty($info)) { //查看是否已经建立了好友关系 $is_exist = UserFriend::model()->isFriend($user_id, $friend_id); if ($is_exist) { $data['status'] = 1; } else { $data['status'] = 0; } $data['friend_id'] = (int) $friend_id; $data['face_url'] = $info['avatar']; $data['nickname'] = $info['nickname']; $data['username'] = $info['username']; $data['exp'] = $info['point']; $data['level'] = $info['level']; } else { return false; } return $data; }
function registerAction() { $this->view->title = "Register New Account"; $this->view->messages = $this->_flashMessenger->getMessages(); $this->_helper->layout->disableLayout(); $lang = $this->_request->getParam('lang'); if (isset($lang)) { $langNamespace = new Zend_Session_Namespace('Lang'); $langNamespace->lang = $lang; $this->_helper->redirector->gotoSimple('register', 'register', null, array('a' => $this->_request->getParam('a'), 'i' => $this->_request->getParam('i'))); } $db = Zend_Registry::get('db'); $currentTime = date("Y-m-d H:i:s"); $loginform = new LoginForm(); $this->view->form = $loginform; $form = new RegisterForm(); $this->view->registerForm = $form; $signupAuthCodeModel = new SignupAuthCode(); $auth_code = $this->_request->getParam('a'); if ($auth_code) { $form->auth_code->setValue($auth_code); $code = $signupAuthCodeModel->fetchRow("use_date is null and auth_code = '" . $auth_code . "'"); } // auto-fill code and email address if (isset($code) && $code->id) { $this->view->codeId = $code->id; $select1 = $db->select(); $select1->from("invitation_email", "to"); $select1->where("invitation_email.signup_auth_code_id = ?", $code->id); $toEmail = $db->fetchOne($select1); $form->registerEmail->setValue($toEmail); $code->view_date = $currentTime; $code->save(); } //public link $invite_code = $this->_request->getParam('i'); if ($invite_code) { $code2 = $signupAuthCodeModel->fetchRow("public_signup_link = true and auth_code = '" . $invite_code . "'"); $publicLinkValid = false; if (isset($code2)) { $select2 = $db->select(); $select2->from('signup_auth_code', 'count(*)')->where('use_date>date_sub(now(),interval 1 day)')->where('sender =' . $code2->sender)->where('source = "PUBLIC_LINK"')->where('receiver is not null'); $registered = $db->fetchOne($select2); if (intval($registered) < 100) { $publicLinkValid = true; } } } if (isset($code2)) { if ($publicLinkValid) { $codePattern = '1234567890ABCDEFGHIJKLOMNOPQRSTUVWXYZ'; $generatedCode = ''; for ($codeCount = 0; $codeCount < 12; $codeCount++) { $generatedCode = $generatedCode . $codePattern[mt_rand(0, 35)]; } $signupAuthCode = $signupAuthCodeModel->createRow(); $signupAuthCode->auth_code = $generatedCode; $signupAuthCode->create_date = $currentTime; $signupAuthCode->sender = $code2->sender; $signupAuthCode->source = 'PUBLIC_LINK'; $signupAuthCode->auto_invitation = $code2->auto_invitation; $signupAuthCode->save(); $form->auth_code->setValue($generatedCode); } else { $this->_flashMessenger->addMessage($this->view->translate('Sorry_This_register_link_has_been_overused')); $this->_helper->redirector('register', 'register'); } } if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $db = Zend_Registry::get('db'); if ($form->getValue('registerPassword') == $form->getValue('repeat')) { // verify auth code $codeModel = new SignupAuthCode(); $code = $codeModel->fetchRow("auth_code='" . $form->getValue('auth_code') . "' and use_date is null"); if ($code) { //check pest if ($code->sender != null) { $consumerModel = new Consumer(); $consumer = $consumerModel->fetchRow("id = " . $code->sender); if ($consumer != null && $consumer->pest == '1') { return; } } //check duplicated email $result = $db->fetchOne("SELECT COUNT(*) FROM consumer WHERE email = :temp", array('temp' => $form->getValue('registerEmail'))); //check duplicated phone $phone_result = $db->fetchOne("SELECT COUNT(*) FROM consumer WHERE login_phone = :temp", array('temp' => $form->getValue('loginPhone'))); if ($result > 0) { $this->view->errMessage = $this->view->translate('Register_err') . $form->getValue('registerEmail') . $this->view->translate('Register_email_is_invalid'); } else { if ($phone_result > 0) { $this->view->errMessage = $this->view->translate('Register_err') . $form->getValue('loginPhone') . $this->view->translate('Register_phone_is_invalid'); } else { $currentTime = date("Y-m-d H:i:s"); // save new consumer $consumerModel = new Consumer(); $row = $consumerModel->createRow(); $row->name = $form->getValue('name'); $row->email = $form->getValue('registerEmail'); $row->login_phone = $form->getValue('loginPhone'); $row->password = md5($form->getValue('registerPassword')); $row->save(); //expire the auth_code $code->receiver = $row->id; $code->use_date = $currentTime; $code->save(); //add points for code sender // if (!empty($code->sender)&& $code->sender!=""){ // $pointRecordModel = new RewardPointTransactionRecord(); // $point = $pointRecordModel->createRow(); // $point->consumer_id = $code->sender; // $point->transaction_id = 2; // $point->date = $currentTime; // $point->point_amount = 5; // $point->save(); // } // send auto intivitaion if (!empty($code->auto_invitation) && $code->auto_invitation != 0) { $campaignInvitationModel = new CampaignInvitation(); $ci = $campaignInvitationModel->createRow(); $ci->consumer_id = $row->id; $ci->campaign_id = $code->auto_invitation; $ci->create_date = $currentTime; $ci->state = "NEW"; $ci->save(); } // Login Automatically $authAdapter = new Zend_Auth_Adapter_DbTable($db); $authAdapter->setTableName('consumer'); $authAdapter->setIdentityColumn('email'); $authAdapter->setCredentialColumn('password'); $authAdapter->setIdentity($form->getValue('registerEmail')); $authAdapter->setCredential(md5($form->getValue('registerPassword'))); $auth = Zend_Auth::getInstance(); $auth->authenticate($authAdapter); $authNamespace = new Zend_Session_Namespace('Zend_Auth'); $authNamespace->user = $row; $this->_flashMessenger->addMessage('Welcome!'); $this->_helper->redirector('index', 'home'); } } } else { $this->view->errMessage = $this->view->translate('Register_err') . $this->view->translate('Register_authcode_is_invalid'); } } else { $this->view->errMessage = $this->view->translate('Register_err') . $this->view->translate('Register_password_is_invalid'); } } else { $form->populate($formData); } } }
require_once 'db_lib.php'; $this->oDB = new db(); } // This function is called automatically by the Phirehose class // when a new tweet is received with the JSON data in $status public function enqueueStatus($status) { $tweet_object = json_decode($status); // Ignore tweets without a properly formed tweet id value if (!isset($tweet_object->id_str)) { return; } $tweet_id = $tweet_object->id_str; // If there's a ", ', :, or ; in object elements, serialize() gets corrupted // You should also use base64_encode() before saving this $raw_tweet = base64_encode(serialize($tweet_object)); $field_values = 'raw_tweet = "' . $raw_tweet . '", ' . 'tweet_id = ' . $tweet_id; $this->oDB->insert('json_cache', $field_values); } } // Open a persistent connection to the Twitter streaming API $stream = new Consumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); // Establish a MySQL database connection $stream->db_connect(); // The keywords for tweet collection are entered here as an array // More keywords can be added as array elements // For example: array('recipe','food','cook','restaurant','great meal') $stream->setTrack(array('#ris_zh', 'tympaan', '#tympaan', '@tympaan_inst', '@Tympaan_inst', 'Tympaan', '#databankzh')); // Start collecting tweets // Automatically call enqueueStatus($status) with each tweet's JSON data $stream->consume();
/** * @param \SimpleXMLElement $xmlElement * @return Token */ public static function parseFromXml(\SimpleXMLElement $xmlElement) { $token = new self(); if (!empty($xmlElement->token)) { $token->setToken((string) $xmlElement->token); } if (!empty($xmlElement->tokenSecret)) { $token->setTokenSecret((string) $xmlElement->tokenSecret); } if (!empty($xmlElement->user)) { $userObject = User::parseFromXml($xmlElement->user); $token->setUser($userObject); } if (!empty($xmlElement->consumer)) { $consumerObject = Consumer::parseFromXml($xmlElement->consumer); $token->setConsumer($consumerObject); } return $token; }