我正在尝试将 if/else 添加到 CakePHP 中的登录操作。登录操作有很多行,当我在 LoginValidate 之后添加 if/else 时,登录操作的括号现在无法正确关闭。
会话确实被写入,但是当在 sublime text2 中使用括号荧光笔时,最上面的括号不会被突出显示。这是代码。如果用户不在 UserGroup 'Admin' 中,我想要做的是将 KCFinder 的会话变量写入'true',如果用户在 UserGroup 'Admin' 中,则为 false。
public function login() {
    print_r($this -> Session -> read());
    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);
            $UserGroup = $this->User->UserGroup;
            if (empty($user)) {
                $user = $this->User->findByEmail($email);
                if (empty($user)) {
                    $this->Session->setFlash(__('Incorrect Email/Username or Password'));
                    return;
                }
            }
                //write session value for kcfinder
            if ($user['UserGroup']['name']='Admin') {
                $this -> Session -> write("kcfinder", "false");
                $_SESSION['KCFINDER']['disabled']=false; //config from ckfinder
            } else {
                $this -> Session -> write("kcfinder", "true");
                return;
            }   
            // check for inactive account
            if ($user['User']['id'] != 1 and $user['User']['active']==0) {
                $this->Session->setFlash(__('Sorry your account is not active, please contact to Administrator'));
                return;
            }
            // check for verified account
            if ($user['User']['id'] != 1 and $user['User']['email_verified']==0) {
                $this->Session->setFlash(__('Your registration has not been confirmed please verify your email or contact to Administrator'));
                return;
            }
            if(empty($user['User']['salt'])) {
                $hashed = md5($password);
            } else {
                $hashed = $this->UserAuth->makePassword($password, $user['User']['salt']);
            }
            if ($user['User']['password'] === $hashed) {
                if(empty($user['User']['salt'])) {
                    $salt=$this->UserAuth->makeSalt();
                    $user['User']['salt']=$salt;
                    $user['User']['password']=$this->UserAuth->makePassword($password, $salt);
                    $this->User->save($user,false);
                }
                $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 : LOGIN_REDIRECT_URL;
                $this->redirect($redirect);
            } else {
                $this->Session->setFlash(__('Incorrect Email/Username or Password'));
                return;
            }
        }
    }
}
附加点:
1) 此代码来自用户管理插件: http: //usermgmt.ektasoftwares.com
2)我添加的部分是:
                //write session value for kcfinder
        if ($user['UserGroup']['name']='Admin') {
            $this -> Session -> write("kcfinder", "false");
            $_SESSION['KCFINDER']['disabled']=false; //config from ckfinder
        } else {
            $this -> Session -> write("kcfinder", "true");
            return;
        }
添加我的会话部分的结果是两个最上面的括号没有正确突出显示(再次使用 sublime text2 中的突出显示插件)
感谢您的评论和输入。