0

I am trying to sync a yii app with cake php . Main motive is to login into both systems if user fill form in one application . yii app is on root while the cake php app is in folder. hence the url are

for yii its http://192.168.1.31/Eb/
and for cake php its http://192.168.1.31/Eb/projectmanager/ these are local .

Now i have created a function in yii controller with curl and call this on login time.

private function logintoprojectmanager($post)
    {
        $fields = array(
                        'User'=>array(
                        'email' => 'manoj@rudrainnovatives.com',
                        'password' => 'manoj@41@'

                            )
                        );
        $urltopost="http://192.168.1.31/Eb/projectmanager/login";               
        $fields_string = http_build_query($fields);             
        $ch = curl_init ($urltopost);
        curl_setopt ($ch, CURLOPT_POST, true);
        curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, false);
        $returndata = curl_exec ($ch);
        curl_close ($ch);
        print_r($returndata); //display the reuslt*/
        die;
    }

and the login function in cake php application is

public function login()
    {
        $this->__login();
        $this->render('login');
    }
private function __login()
    {
        $this->layout = 'default';

        if (AuthComponent::user())
            $this->redirect(array('controller' => 'projects', 'action' => 'index'));

        if ($this->request->is('post'))
        {
            $this->User->set($this->request->data);
            if ($this->Auth->login())
            {
                echo "logged in ";
                if ($this->request->data['User']['remember_me'] == 1)
                {
                    unset($this->request->data['User']['remember_me']);
                    $this->request->data['User']['password'] = $this->Auth->password($this->request->data['User']['password']);
                    $this->Cookie->write('cepp_pauth', $this->request->data['User'], true, '2 weeks');
                }

                if (!AppAuth::is(UserRoles::Admin) && AppConfig::read('System.maintenance') === true)
                {
                    $this->Session->setFlash(__('The system is in maintenance mode.'), Flash::Error);
                    $this->redirect($this->Auth->logout());
                }

                $this->Session->setFlash(__('You successfully logged in.'), Flash::Success);
                if (!empty($this->request->params['admin']))
                    $this->redirect(array('controller' => 'projects', 'action' => 'index'));
                else
                    $this->redirect($this->Auth->redirectUrl());
            } else
            {
                echo "incorrect credentials";
                unset($this->request->data['User']['password']);
                $this->Session->setFlash(__('The username/password you provided were incorrect.'));
            }
        }
        $this->set('title_for_layout', __('Login'));
    }

I am getting curl response that "logged in" . But when i open the cake php app it redirects me to login form . Where i am wrong ??

any help will be appriciated. Thanks

Manoj Dhiman
  • 5,096
  • 6
  • 29
  • 68
  • No time for an extensive answer right now, so just a hint for now: Auth uses cookies (by default), the CURL request returns them (if configured) and you have to pass them on to the client, otherwise they are landing in nowhere, and the clients next "real" request of course wont authenticate. See also **http://stackoverflow.com/questions/895786/how-to-get-the-cookies-from-a-php-curl-into-a-variable** – ndm Jun 11 '15 at 13:23
  • no cookie return from curl request . can you please explain how it is possible?? – Manoj Dhiman Jun 11 '15 at 13:44

0 Answers0