0
votes

I have a problem related to redirecting one action to another on live site.(http://marwarishaadicentre.in/) I post the Auth Controller code in this code in Authenticate Action can authenticate successfully but not redirect on admin or profile route.

 public function authenticateAction()
{
    $user_session = new Container('user');
        $form = $this->getForm();
        $redirect = 'member/login';

        $request = $this->getRequest();

        if($request->isPost())
        {

            $form ->setData($request->getPost());

            if($form->isValid())
            {
                $username = $request->getPost('username');
                $password = $request->getPost('password');
                $credential = $this->getAuthService()->getAdapter()
                                   ->setIdentity($request->getPost('username'))
                                   ->setCredential($request->getPost('password'));
                $is_active = $this->getUserTable()->checkActivation($username,$password);
                $is_admin = $this->getUserTable()->checkAdmin($username);
                 $is_verify = $this->getUserTable()->checkVerify($username);

                $user_session = new \Zend\Session\Container('user');
                $user_session->is_admin=$is_admin->is_admin;

                foreach($is_active as $row)
                {

                    $a = $row->is_active;

                }


                $credential->getDbSelect()->where('is_active = TRUE');

                $result = $this->getAuthService()->authenticate();

                switch ($result->getCode()) {

                    case Result::FAILURE_IDENTITY_NOT_FOUND:
                        /** do stuff for nonexistent identity **/
                        if($a == 0)
                        {
                            $this->flashMessenger()->addMessage('Your account could not be verified!
                            Or Wrong Username was entered');
                        }
                        else
                        {
                            $this->flashMessenger()->addMessage('Please check your username !!!');
                        }

                        break;

                    case Result::FAILURE_CREDENTIAL_INVALID:
                        /** do stuff for invalid credential **/
                        $this->flashMessenger()->addMessage('Wrong Password entered!!!');
                        break;

                    case Result::SUCCESS:
                        /** do stuff for successful authentication **/
                        $user_session->username = $request->getPost('username');
                        $redirect_admin = 'admin';
                        $redirect_mem='profile';

                        if($request -> getPost('rememberme') == 1)
                        {
                                $this->getSessionStorage() ->setRememberMe(1);
                                $this ->getAuthService() -> setStorage($this -> getSessionStorage());
                        }
                        $this->getAuthService()->setStorage($this->getSessionStorage());
                        $this->getAuthService()->getStorage()->write($request->getPost('username'));
                        break;

                    case Result::FAILURE_UNCATEGORIZED:
                        $this->flashMessenger()->addMessage('Uncategorized Failure occurred. Please try again later!!!');
                        break;

                    default:
                        /** do stuff for other failure **/
                        $this->flashMessenger()->addMessage('Something unexpected went. Please try again later!!!');
                        break;
                }
            }
        }

        if($is_admin->is_admin=='Y')
        {
          return $this -> redirect() -> toRoute($redirect_admin);
        }

       if($a==NULL)
       {
        $this->flashMessenger()->addMessage('Your account could not be verified!
                            Or Wrong Username was entered');
       }
        if($is_verify->is_verify==0)
        {
            return $this -> redirect()->toUrl('http://marwarishaadicentre.in/profile/edit/'.$is_verify->mem_code);
        }
        else
        {
            return $this -> redirect() -> toRoute('profile');
        }
}

I create my site in zend framework-2 and deployed on Linux Server but at the time of redirecting it should not work. It will stop on previous action. ex:- At the time of authentication it can authenticate successfully but on redirect it will stop. $this->redirect()->toRoute('admin'); this code is not work and in whole project any where redirect is not working. toRoute('admin') or toUrl('http://marwarishaadicentre.in/admin') these functions are not work.

2
Codes, we need them codes :) - Sam
sir actually its a redirect problem. It is not redirect on other route on live site.How to solve it?? - Prashant Patle
We need your controller code (i.e. where you are redirecting) and then the routing config, it may just be a simple typo / uppper/lower-case problematic or whatnot. Without code, we can't solve it. The framework isn't at fault and probably not the server either ;) - Sam
I post the Auth Controller code in this code in Authenticate Action can authenticate successfully but not redirect on admin or profile route. - Prashant Patle
post your module.config.php file and if possible Module.php too - noobie-php

2 Answers

0
votes

Try this, I think you just do not have the variable $is_admin

\Zend\Debug\Debug::dump($is_admin); // !!!!!!!!

if($is_admin->is_admin=='Y')
{
    return $this -> redirect() -> toRoute($redirect_admin);
}
0
votes

I am struggled with the same kind of problem too. I have solved this issue with the following redirection method:

 return $this->redirect()->toUrl($redirect_admin);

Please make sure your assigned url variable has forward slash ("/") in front of your module name as below.

 $redirect_admin = '/admin';

I hope this works for you.