如果重定向,在CakePHP中手动登录后不会登录,如果没有重定向,则登录 [英] Not logged in after manual login in CakePHP if redirected, logged in if no redirect

查看:137
本文介绍了如果重定向,在CakePHP中手动登录后不会登录,如果没有重定向,则登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Janrain登录到我的CakePHP网站,当处理用户数据时,我想使用$ this-> Auth-> login() - 函数自动登录。

I'm using Janrain engage to login to my CakePHP site, and when handling the user data, I want to automatically login using the $this->Auth->login()-function.

我设法登录罚款,如果我不调用后重定向,但如果我重定向,我没有登录。现在有人现在为什么或我可以做什么straigten这? p>

I manage to login fine if I don't redirect after the call, but if I redirect, I'm not logged in. Does anyone now why or what I can do to straigten this?

    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);          
        }


推荐答案

问题。然而我不能解决这个问题。尝试覆盖在PagesController(如果你使用它)和添加parent :: beforeFilter beforeFilter之前。

I have came accross the same problem. However i could not solve that problem. Try overriding beforeFilter on PagesController (if you are using it) and adding parent::beforeFilter in it.

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

然而,这也没有解决我的问题。最终我放弃了尝试。安装OPAuth,遇到了几个问题,但解决了他们。 Facebook,Twitter,谷歌等,现在工作正常,并与我的网站的内置身份验证系统集成。

However that did not solve my problem neither. Eventually i gave up trying. Installed OPAuth, came accross several problems, however solved them. Facebook, twitter, google, etc, now works fine and integrated with my site's built-in auth system.

链接: OPAuth网站 OPAuth下载 OPAuth CakePHP插件

这篇关于如果重定向,在CakePHP中手动登录后不会登录,如果没有重定向,则登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆