我正在使用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);
}
你使用:http://code.42dh.com/openid/? (基于JanRain) – 2012-11-17 08:40:55
我不记得了,我也没有收到消息。 – andersem 2012-11-19 09:06:10