0

我有一个与将一个操作重定向到实时站点上的另一个操作相关的问题。(http://marwarishaadicentre.in/)我在 Authenticate Action 中的此代码中发布了 Auth Controller 代码,可以成功验证,但不能在管理员或配置文件路由上重定向。

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

我在 zend framework-2 中创建我的站点并部署在 Linux 服务器上,但在重定向时它不应该工作。它将停止先前的操作。例如:- 在身份验证时,它可以成功进行身份验证,但在重定向时它将停止。$this->redirect()->toRoute('admin'); 此代码不起作用,并且在整个项目中重定向不起作用的任何地方。toRoute('admin') 或 toUrl(' http://marwarishaadicentre.in/admin ') 这些功能不起作用。

4

2 回答 2

0

我也在为同样的问题而苦苦挣扎。我已经使用以下重定向方法解决了这个问题:

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

请确保您分配的 url 变量在您的模块名称前面有正斜杠(“/”),如下所示。

 $redirect_admin = '/admin';

我希望这对你有用。

于 2013-10-09T04:36:37.637 回答
0

试试这个,我想你只是没有变量 $is_admin

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

if($is_admin->is_admin=='Y')
{
    return $this -> redirect() -> toRoute($redirect_admin);
}
于 2013-08-08T16:24:02.533 回答