Authentication Yii:成员的共享密码';s区
在Yii中设置共享密码保护区的最佳方法是什么 我希望有一个组模型的视图,可以通过该组所有者创建的共享密码访问该模型-组成员不必登录,只需输入此密码Authentication Yii:成员的共享密码';s区,authentication,yii,Authentication,Yii,在Yii中设置共享密码保护区的最佳方法是什么 我希望有一个组模型的视图,可以通过该组所有者创建的共享密码访问该模型-组成员不必登录,只需输入此密码 Yii内置的auth工具是否仍应执行此操作或者有一个更简单的解决方案,记住有人可能想要访问几个组 您可以使用内置在PHP中的标准会话机制来实现这一点。当有人试图查看密码保护区域时,请检查会话变量,如果用户尚未输入密码,则使用密码表单将其重定向到某个页面(例如,您可以使用控制器过滤器进行检查) 提交表单后,检查密码的正确性,如果一切正常,将其写入会话。
Yii内置的auth工具是否仍应执行此操作或者有一个更简单的解决方案,记住有人可能想要访问几个组 您可以使用内置在PHP中的标准会话机制来实现这一点。当有人试图查看密码保护区域时,请检查会话变量,如果用户尚未输入密码,则使用密码表单将其重定向到某个页面(例如,您可以使用控制器过滤器进行检查) 提交表单后,检查密码的正确性,如果一切正常,将其写入会话。您可以通过组ID区分会话密钥。您可以使用功能在执行控制器操作之前触发代码,并阻止不允许的操作 我将为您的所有组页面创建一个公共控制器,并在需要时从该页面继承其他控制器 在过滤器中,我将设置代码以检查/提示密码,并将其保留在会话中 例如,我们有一个过滤器设置来检测用户是否接受我们修订的条款和条件。过滤器将检测并阻止对控制器的访问,直到用户不确认为止
class TocConfirmFilter extends CFilter {
/**
* Initializes the filter.
* This method is invoked after the filter properties are initialized
* and before {@link preFilter} is called.
* You may override this method to include some initialization logic.
*/
public function init() {
}
/**
* Performs the pre-action filtering.
* @param CFilterChain the filter chain that the filter is on.
* @return boolean whether the filtering process should continue and the action
* should be executed.
*/
protected function preFilter($filterChain) {
// do not perform this filter on this action
if ($filterChain->action->controller->id . '/' . $filterChain->action->id == 'public/onePublicPage') {
return true;
}
if (isset(Yii::app()->user->id)) {
$user = user::model()->findbyPk(Yii::app()->user->id);
if ($user === null)
throw new CHttpException(404, 'The requested user does not exist.');
if ($user->tocconfirmed == 0) {
Yii::app()->getRequest()->redirect(Yii::app()->createAbsoluteUrl('authorize/confirm'));
return false;
}
}
return true;
}
/**
* Performs the post-action filtering.
* @param CFilterChain the filter chain that the filter is on.
*/
protected function postFilter($filterChain) {
}
}