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