當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AuthComponent::redirect方法代碼示例

本文整理匯總了PHP中AuthComponent::redirect方法的典型用法代碼示例。如果您正苦於以下問題:PHP AuthComponent::redirect方法的具體用法?PHP AuthComponent::redirect怎麽用?PHP AuthComponent::redirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AuthComponent的用法示例。


在下文中一共展示了AuthComponent::redirect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: callback

 /**
  * OAuth callback
  */
 public function callback($datasource = null)
 {
     $this->Twitter->setTwitterSource($datasource);
     // 正當な返り値かチェック
     if (!$this->Twitter->isRequested()) {
         $this->Twitter->deleteAuthorizeCookie();
         $this->flash(__d('twitter_kit', 'Authorization failure.'), '/', 5);
         return;
     }
     // $tokenを取得
     $token = $this->Twitter->getAccessToken();
     if (is_string($token)) {
         $this->flash(__d('twitter_kit', 'Authorization Error: %s', $token), '/', 5);
         return;
     }
     if (class_exists('TwitterUser') || (true || App::uses('TwitterUser', 'Model')) && class_exists('TwitterUser')) {
         /* @var $model TwitterUser */
         $model = ClassRegistry::init('TwitterUser');
     } else {
         /* @var $model TwitterKitUser */
         $model = ClassRegistry::init('TwitterKit.TwitterKitUser');
     }
     // 保存データの作成
     $data = $model->createSaveDataByToken($token);
     if (!$model->save($data)) {
         $this->flash(__d('twitter_kit', 'The user could not be saved'), array('plugin' => 'twitter_kit', 'controller' => 'users', 'action' => 'login'), 5);
         return;
     }
     $this->Auth->login($data);
     // Redirect
     if (ini_get('session.referer_check') && env('HTTP_REFERER')) {
         $this->flash(__d('twiter_kit', 'Redirect to %s', Router::url($this->Auth->redirect(), true) . ini_get('session.referer_check')), $this->Auth->redirect(), 0);
         return;
     }
     $this->redirect($this->Auth->redirect());
 }
開發者ID:rasken2003,項目名稱:trpg-ranking,代碼行數:39,代碼來源:OauthController.php

示例2: callback

 /**
  * OAuth callback
  */
 public function callback($datasource = null)
 {
     $this->Twitter->setTwitterSource($datasource);
     // 正當な返り値かチェック
     if (empty($this->params['url']['oauth_token']) || empty($this->params['url']['oauth_verifier'])) {
         $this->Twitter->deleteAuthorizeCookie();
         $this->flash(__d('twitter_kit', 'Authorization failure.', true), '/', 5);
         return;
     }
     // $tokenを取得
     $token = $this->Twitter->getAccessToken();
     if (is_string($token)) {
         $this->flash(__d('twitter_kit', 'Authorization Error: ', true) . $token, '/', 5);
         return;
     }
     if (ClassRegistry::isKeySet('TwitterUser')) {
         /* @var $model TwitterUser */
         $model = ClassRegistry::init('TwitterUser');
     } else {
         /* @var $model TwitterKitUser */
         $model = ClassRegistry::init('TwitterKit.TwitterKitUser');
     }
     // 保存データの作成
     $data = $model->createSaveDataByToken($token);
     if (!$model->save($data)) {
         $this->flash(__d('twitter_kit', 'The user could not be saved', true), array('plugin' => 'twitter_kit', 'controller' => 'users', 'action' => 'login'), 5);
         return;
     }
     $this->Auth->login($data);
     // Redirect
     if (ini_get('session.referer_check') && env('HTTP_REFERER')) {
         $this->flash(sprintf(__d('twiter_kit', 'Redirect to %s', true), Router::url($this->Auth->redirect(), true) . ini_get('session.referer_check')), $this->Auth->redirect(), 0);
         return;
     }
     $this->redirect($this->Auth->redirect());
 }
開發者ID:hiromi2424,項目名稱:twitter_kit,代碼行數:39,代碼來源:oauth_controller.php

示例3: callback

 /**
  * OAuth callback
  */
 public function callback($datasource = null)
 {
     $this->Twitter->setTwitterSource($datasource);
     // 正當な返り値かチェック
     if (!$this->Twitter->isRequested()) {
         $this->Twitter->deleteAuthorizeCookie();
         $this->flash(__d('twitter_kit', 'Authorization failure.'), '/', 5);
         return;
     }
     // $tokenを取得
     $token = $this->Twitter->getAccessToken();
     if (is_string($token)) {
         $this->flash(__d('twitter_kit', 'Authorization Error: %s', $token), '/', 5);
         return;
     }
     if (class_exists('TwitterUser') || (true || App::uses('TwitterUser', 'Model')) && class_exists('TwitterUser')) {
         /* @var $model TwitterUser */
         $model = ClassRegistry::init('TwitterUser');
     } else {
         /* @var $model TwitterKitUser */
         //$model = ClassRegistry::init('TwitterKit.TwitterKitUser');
         $model = ClassRegistry::init('User');
     }
     $create_flg = false;
     //既に登録済みか?
     $tmp = $model->findTwitterUser($token['user_id']);
     if (!empty($tmp)) {
         $data = $model->updateSaveDataByToken($tmp, $token);
     } else {
         // 保存データの作成
         $data = $model->createSaveDataByToken($token);
         $model->create();
         $create_flg = true;
     }
     if (!$model->save($data, false)) {
         $this->flash(__d('twitter_kit', 'The user could not be saved'), array('plugin' => 'twitter_kit', 'controller' => 'users', 'action' => 'login'), 5);
         return;
     }
     if ($create_flg == true) {
         $data['User']['id'] = $model->getLastInsertId();
         //新規會員登録の際
         $ds = $this->Twitter->getTwitterSource();
         $ds->setToken($data['User']);
         //プロフィール畫像の取得
         $params = array();
         $params['id'] = $data['User']['twitter_user_id'];
         $result = $ds->users_show($data['User']['twitter_user_id']);
         if (!empty($result['profile_image_url'])) {
             $image_url = str_replace("_normal", "", $result['profile_image_url']);
             $image_data = file_get_contents($image_url);
             //MIMEタイプの取得
             $finfo = finfo_open(FILEINFO_MIME_TYPE);
             $mime_type = finfo_buffer($finfo, $image_data);
             finfo_close($finfo);
             //出力
             switch ($mime_type) {
                 case 'image/gif':
                     $ext = "gif";
                     break;
                 case 'image/png':
                     $ext = "png";
                     break;
                 case 'image/jpg':
                 case 'image/jpeg':
                     $ext = "jpg";
                     break;
             }
             $file_name = md5(date("YmdHis") . $data['User']['id']) . "." . $ext;
             file_put_contents(IMAGES . 'profileImg/' . $file_name, $image_data);
             //profile_imgを更新
             $model->id = $data['User']['id'];
             $model->saveField('profile_img', $file_name);
             $data['User']['profile_img'] = $file_name;
         }
         //メール送信
         $email = new CakeEmail('smtp');
         $email->to('info@sanrentan-box.com');
         $email->subject('twitterから會員登録がありました');
         $email->emailFormat('text');
         $email->template('regist');
         $postData['User']['nickname'] = $data['User']['nickname'];
         $email->viewVars(compact('postData'));
         $email->send();
     }
     $this->Auth->login($data['User']);
     // Redirect
     if (ini_get('session.referer_check') && env('HTTP_REFERER')) {
         $this->flash(__d('twiter_kit', 'Redirect to %s', Router::url($this->Auth->redirect(), true) . ini_get('session.referer_check')), $this->Auth->redirect(), 0);
         return;
     }
     //ログイン履歴を保存
     $this->LoginHistory->saveLoginHistory($data['User']['id'], $this->request);
     //$this->redirect($this->Auth->redirect());
     if ($create_flg == true) {
         $this->redirect("/users/edit");
     } else {
         $this->redirect("/");
//.........這裏部分代碼省略.........
開發者ID:sanrentan,項目名稱:sanrentan,代碼行數:101,代碼來源:OauthController.php


注:本文中的AuthComponent::redirect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。