【发布时间】:2010-08-13 13:30:12
【问题描述】:
嗨,我对 cakephp 比较陌生。我尝试创建一个简单的应用程序作为学习和实践。 我使用 Auth 组件实现了一个简单的用户处理系统。我在用户模型中创建了一个自定义 isAuthorized 方法。 注册后,用户需要激活自己才能登录。如果用户未激活,则授权返回 false,并且我想通知用户他未激活。 但是我不知道如何在这个方法里面设置 flash 消息(我试过没有成功)。
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;
如您所见,我尝试过,但失败了 :) 它不起作用。
我也试过了
$this->Auth->authError = __("Please activate your user first!",true);
在用户控制器 login() 中没有成功
【问题讨论】:
-
不,它没有。基本 authError 消息显示在 app_controller 中设置的内容。
标签: cakephp