0

我目前正在使用 Usermgmt 插件进行登录功能和用户管理。我想要做的是在他们登录后根据 group_id 重定向特定页面。我现在迷失在蛋糕上。

这是来自 AppController 的代码。

    var $helpers = array('Form', 'Html', 'Session', 'Js', 'Usermgmt.UserAuth');
    public $components = array('Session','RequestHandler', 'Usermgmt.UserAuth');
    function beforeFilter(){
        $this->userAuth();
    }

    private function userAuth(){
        $this->UserAuth->beforeFilter($this);
    }

这是来自 UsersController 的登录功能。

  public function login() {
    if ($this->request -> isPost()) {
        $this->User->set($this->data);
        if($this->User->LoginValidate()) {
            $email  = $this->data['User']['email'];
            $password = $this->data['User']['password'];

            $user = $this->User->findByUsername($email);
            if (empty($user)) {
                $user = $this->User->findByEmail($email);
                if (empty($user)) {
                    $this->Session->setFlash(__('Incorrect Email/Username or Password'));
                    return;
                }
            }
            // check for inactive account
            if ($user['User']['id'] != 1 and $user['User']['active']==0) {
                $this->Session->setFlash(__('Your registration has not been confirmed please verify your email or contact to Administrator'));
                return;
            }
            $hashed = md5($password);
            if ($user['User']['password'] === $hashed) {
                $this->UserAuth->login($user);
                $remember = (!empty($this->data['User']['remember']));
                if ($remember) {
                    $this->UserAuth->persist('2 weeks');
                }
                $OriginAfterLogin=$this->Session->read('Usermgmt.OriginAfterLogin');
                $this->Session->delete('Usermgmt.OriginAfterLogin');
                $redirect = (!empty($OriginAfterLogin)) ? $OriginAfterLogin : loginRedirectUrl;
                $this->redirect($redirect);
            } else {
                $this->Session->setFlash(__('Incorrect Email/Username or Password'));
                return;
            }
        }
    }
}

任何帮助表示赞赏。谢谢你。

4

1 回答 1

0

如果您想将它们重定向到其他地方,请更改重定向行。这假设您的 User 模型与 Group 模型相关,并且递归级别允许您的 find 调用提取数据。

// original
$redirect = (!empty($OriginAfterLogin)) ? $OriginAfterLogin : loginRedirectUrl;
// new redirect, eg: /groups/view/3
$redirect = array(
  'controller' => 'groups', 
  'action' => 'view', 
  $user['Group']['id']
);
$this->redirect($redirect);
于 2012-07-31T13:56:26.507 回答