2010-09-21 135 views
0

我正在使用Janrain參與登錄到我的CakePHP站點,並且在處理用戶數據時,我想使用$ this-> Auth->登錄() - 功能。在CakePHP中手動登錄後未登錄如果重定向,如果沒有重定向登錄

我設法登錄罰款,如果我沒有重定向後的通話,但如果我重定向,我沒有登錄。現在有人爲什麼或我可以做什麼來straigten這個?

function janrain(){ 
    $rpxApiKey = 'kassdkfkafkkadskfkkdfkksdk'; 

    if(isset($_POST['token'])) { 

     /* STEP 1: Extract token POST parameter */ 
     $token = $_POST['token']; 

     /* STEP 2: Use the token to make the auth_info API call */ 
     $post_data = array('token' => $_POST['token'], 
         'apiKey' => $rpxApiKey, 
         'format' => 'json'); 

     $curl = curl_init(); 
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($curl, CURLOPT_URL, 'https://rpxnow.com/api/v2/auth_info'); 
     curl_setopt($curl, CURLOPT_POST, true); 
     curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); 
     curl_setopt($curl, CURLOPT_HEADER, false); 
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
     $raw_json = curl_exec($curl); 
     curl_close($curl); 


     /* STEP 3: Parse the JSON auth_info response */ 
     $auth_info = json_decode($raw_json, true); 

     if ($auth_info['stat'] == 'ok') { 

     /* STEP 3 Continued: Extract the 'identifier' from the response */ 
     $profile = $auth_info['profile']; 
     $identifier = $profile['identifier']; 

     if (isset($profile['photo'])) { 
      $photo_url = $profile['photo']; 
     } 

     if (isset($profile['displayName'])) { 
      $name = $profile['displayName']; 
     } 

     if (isset($profile['email'])) { 
      $email = $profile['email']; 
     } 

     $user = $this->User->findByUsername($identifier); 

     if($user){ 

      $this->Auth->login($user['User']); 
      if ($this->Session->read('Auth.User')) { 
        $this->Session->setFlash('You are logged in!'); 
        $this->redirect('/', null, false); 
       } 
     } 
     else{ 
      $this->User->create(); 
      $this->User->set('username',$identifier); 
      $this->User->set('displayname',$name); 
      if(isset($photo_url)){ 

      $this->User->set('photo_url', $photo_url); 
      } 
      $this->User->set('password', $this->Auth->password($identifier)); 
      $this->User->save(); 
      //$this->User->set('password', $identifier); 
      $this->Auth->login($this->User);   
     } 
+0

你使用:http://code.42dh.com/openid/? (基於JanRain) – 2012-11-17 08:40:55

+0

我不記得了,我也沒有收到消息。 – andersem 2012-11-19 09:06:10

回答

0

我有完全一樣的麻煩。如果我重定向,用戶不會被驗證。

我至今發現的唯一解決方案是在驗證用戶之後使用JavaScript進行重定向。我將URL傳遞作爲參數在嵌入的小部件定義的令牌網址重定向:

$url = urlencode($baseUrl.'users/rpx?redirect=' . 'lala');

<iframe src="http://lolo.rpxnow.com/openid/embed?token_url=<?php echo $url; ?>" scrolling="no" frameBorder="no" allowtransparency="true" style="width:350px;height:216px"></iframe> 

0

我真的不喜歡的的CakePHP的驗證組件。我遇到了與CakePHP 1.2完全相同的問題,但通過在core.php文件中將我的安全級別更改爲「低」來設法使事情正常運行。

Configure::write('Security.level', 'low'); 
1

我來過同一個問題。但是我無法解決這個問題。嘗試覆蓋PagesController上的beforeFilter(如果您正在使用它)並在其中添加parent :: beforeFilter。

public function beforeFilter() { 
    parent::beforeFilter(); 
} 

但是,這並沒有解決我的問題。最終我放棄了嘗試。安裝了OPAuth,遇到了幾個問題,但是解決了它們。 Facebook,Twitter,谷歌等,現在工作正常,並與我的網站的內置身份驗證系統集成。

鏈接:OPAuth WebsiteOPAuth DownloadOPAuth CakePHP Plugin