Example #1
0
 public function registerAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $item = $request->getPost();
         $oauth = new \Oauth\OauthService();
         $accessToken = array();
         if ($oauth->getStorage()->getAccessToken()) {
             $oauth->setServiceLocator($this->getServiceLocator());
             $oauth->initByAccessToken();
             $accessToken = $oauth->getAdapter()->getAccessToken();
         }
         $form = $accessToken ? new \User\Form\QuickRegisterForm() : new \User\Form\RegisterForm();
         $form->bind($item);
         if ($form->isValid()) {
             $callback = $this->params()->fromPost('callback');
             $callback = $callback ? $callback : '/';
             $item = $form->getData();
             $itemModel = Api::_()->getModel('User\\Model\\Register');
             $itemModel->setItem($item)->register();
             $userItem = $itemModel->getItem();
             $codeItem = $itemModel->getItem('User\\Item\\Code');
             $mail = new \Core\Mail();
             $mail->getMessage()->setSubject("Please Confirm Your Email Address")->setData(array('user' => $userItem, 'code' => $codeItem))->setTo($userItem->email, $userItem->userName)->setTemplatePath(Api::_()->getModulePath('User') . '/view/')->setTemplate('mail/active');
             $mail->send();
             $this->redirect()->toUrl($callback);
         } else {
         }
         return array('token' => $accessToken, 'form' => $form, 'item' => $item);
     } else {
         return array('item' => $this->getRequest()->getQuery());
     }
 }
Example #2
0
 public function getClient()
 {
     $oauth = new OauthService();
     $oauth->initByAccessToken($this->options);
     $adapter = $oauth->getAdapter();
     $client = $adapter->getHttpClient();
     return $client;
 }
 public function tokenAction()
 {
     $this->changeViewModel('json');
     $itemModel = Api::_()->getModel('Oauth\\Model\\Accesstoken');
     $dataClass = $itemModel->getItem()->getDataClass();
     $item = $dataClass->where(function ($where) {
         $where->equalTo('adapterKey', 'douban');
         $where->equalTo('tokenStatus', 'active');
         $where->equalTo('version', 'Oauth1');
         //$where->greaterThan('expireTime', 0);
         return $where;
     })->order('expireTime ASC')->find('one');
     $item = (array) $item;
     $oauth = new OauthService();
     //importent here to inject oauth1.0 Consumer key
     $oauth->setServiceLocator($this->getServiceLocator());
     $oauth->initByAccessToken($item);
     $adapter = $oauth->getAdapter();
     $client = $adapter->getHttpClient();
     //$client->setUri('https://api.weibo.com/2/users/show.json');
     //$client->setParameterGet(array(
     //    'screen_name' => 'Allo'
     //));
     //$client->setUri('https://api.douban.com/v2/user/~me');
     /*
     $client->setUri('https://api.twitter.com/1.1/users/show.json');
     $client->setParameterGet(array(
         'screen_name' => 'AlloVince'
     ));
     */
     //$response = $client->send();
     $client->setUri('http://api.douban.com/people/1291360/friends');
     //$client->setUri('http://api.linkedin.com/v1/people/~');
     $response = $client->send();
     p($client->getRequest()->toString());
     p($response->getBody());
     //$adapter->refreshAccessToken();
     //return new JsonModel();
 }