Hi I am relatively new to cakephp. I try to create a simple app as learning&practice. I implemented a simple user handling system using Auth component. I made a custom isAuthorized method in the user model. After registration the user need to activate himself/herself in order to be able to login. If the user is not active, is Authorized gives back a false and also I want to inform the user that he isn't activated. But I do not know how to set the flash message inside this method (I tried without a success).
function isAuthorized($user, $controller, $action) {
// We have simply user-rights system. There are admins and non-admins.
// This function makes a decision if the user have rights to do what requested.
if($user['User']['active']==0) { // if the user has not been activated yet then gets no rights
$authed=false;
$this->Auth->authError = __("Please activate your user first!",true);
} else {
$this->Auth->authError = __("Sorry, you do not have access to this area.",true);
if($user['User']['admin']==1) { //all admins has all rights
$authed=true;
} else {
if($controller=='Areas' or $controller=='Rooms' or $controller=='Categories') {
if($action=='read') {
$authed=true;
} else {
$authed=false; //non-admin users are not authorized to add or edit rooms or areas
}
} else {
$authed=true; // however they are allowed to do other tasks. the per task rights are controlled within the controllers
}
}
}
//debug($authed);
return $authed;
As you see I tried, but I failed :) it does not work.
I also tried to put
$this->Auth->authError = __("Please activate your user first!",true);
in users controller login() without success