dongqieli4164 2014-08-21 06:16
浏览 55

如果用户已登录并转到用户/登录URL,则转到用户/索引

Hello i am using Auth component for Authentication only(Which pages to be given access to which users). I did Login myself using MD5 password .

The problem is When i hit usrs/login URL , it still shows login screen Even If i am logged in.What should be done for that .I tried following ,but didnt work.

//In User controller 

function beforeFilter()
{

    //Here set Which pages should be accessable to various users
    $adminPages =array('index','logout','changeProfPic','add','edit','delete','resetpwd','updatepwd');
    $allUsersPages = array('login','forgot','resetpwd','updatepwd','index','logout');
    $withoutLoginPages = array('login','forgot','resetpwd');

    //Pages for owner only
    if($this->Session->check('userID') && ($this->Session->read('role')== SUPER_ADMIN || $this->Session->read('role')== ADMIN))
    {
        $this->Auth->allow($adminPages);
    }
    else if($this->Session->check('userID') && ($this->Session->read('role')== STAFF || $this->Session->read('role')== USER))
    {
         $this->Auth->allow($allUsersPages);
    }
    else
    {
         $this->Auth->allow($withoutLoginPages);
    }
//For all the users

}

// In same controller Login func.

function login($id=null)
{
    //If form is posted
    if(!empty($this->data))
    {
        //$hashedPassword=Security::hash($this->data['User']['password'],NULL,TRUE); //Hash password
        $hashedPassword= md5($this->data['User']['password']); //Hash password

        $conditionsLogIn = array(
            'user_name' => trim($this->data['User']['username']),
            'password' => $hashedPassword
        );

        $userDetails=$this->User->find('first',array('conditions'=>$conditionsLogIn));

        if($userDetails)
        {
            $this->Session->write('fname',$userDetails['User']['first_name']);
            $this->Session->write('lname',$userDetails['User']['last_name']);
            $this->Session->write('role',$userDetails['User']['user_type_id']);
            $this->Session->write('userID',$userDetails['User']['id']);
            $this->Session->write('userType',$userDetails['UserType']['name']);             

            $this->redirect(array('controller'=>'users','action'=>'index'));
        }
        else
        {
            $this->Session->setFlash('Incorrect Username or Password.','default', array ('class' => 'msgflashError'),'invalidFlag1');
        }
    }
}
  • 写回答

1条回答 默认 最新

  • dqm4675 2014-08-21 06:33
    关注

    I got solution : I commented All App-controller .And added following code in login method

    function login($id=null)
    {
    
        if($this->Session->check('userID')) 
        {
            $this->redirect(array('controller'=>'users','action'=>'index'));
        }
    

    .....Other code

    评论

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装
  • ¥40 复杂的限制性的商函数处理