cakephp菜鸟笔记-auth组件简单说明
2012-02-18 22:04
369 查看
Auth是简单的登陆组件,一般都是先建立user表,字段username,password,如果不是这样就必须另行显式说明。
<?php
class AppController extends Controller {
var $components = array('Auth','Session');
function beforeFilter() {
//Configure AuthComponent配置Auth组件,Auth组件采用SHA1的加密方法。
$this->Auth->allowedActions = array('display','logout','login');
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'products', 'action' => 'index');
if(!$this->Session->check('lang'))
{
$this->Session->write('lang',0);
}
date_default_timezone_set('Asia/Chongqing');
}
}
现在app_controller进行基本的设置,还要建立user的model和controller,建立login和louout方法。它使用SHA1进行加密。可以更改成md5。
进行以上设置后,加入user记录后,就没有被Auth->allowedActions的就会被禁止。
一般在每个controller使用这个来进行allow的方法设置,放行一些方法,免得被禁止权限。
这只是简单的Auth组件使用,更详细的权限使用还需要使用ACL。
<?php
class AppController extends Controller {
var $components = array('Auth','Session');
function beforeFilter() {
//Configure AuthComponent配置Auth组件,Auth组件采用SHA1的加密方法。
$this->Auth->allowedActions = array('display','logout','login');
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'products', 'action' => 'index');
if(!$this->Session->check('lang'))
{
$this->Session->write('lang',0);
}
date_default_timezone_set('Asia/Chongqing');
}
}
现在app_controller进行基本的设置,还要建立user的model和controller,建立login和louout方法。它使用SHA1进行加密。可以更改成md5。
进行以上设置后,加入user记录后,就没有被Auth->allowedActions的就会被禁止。
function beforeFilter() { parent::beforeFilter(); $this->Auth->allow('*'); }
一般在每个controller使用这个来进行allow的方法设置,放行一些方法,免得被禁止权限。
这只是简单的Auth组件使用,更详细的权限使用还需要使用ACL。
相关文章推荐
- sunburnt 学习笔记 (二) solr配置的简单说明
- cakephp学习:大部分动作使用Auth组件来控制权限,但少部分不用,如何实现?
- 菜鸟学Linux 第084篇笔记 lvs持久连接和awk简单使用
- 用CornerStone配置SVN,HTTP及svn简单使用说明 (以前用versions感觉很难用的样子所以有个笔记)
- cakephp菜鸟笔记——Js引擎jQuery使用
- android菜鸟学习笔记13----Android控件(二) 自定义控件简单示例
- cocos2d-x 菜鸟学习笔记十七(简单的碰撞检测 实践篇 下)
- 菜鸟学Linux 第002篇笔记 Linux简单介绍
- 安卓开发笔记——关于开源组件PullToRefresh实现下拉刷新和上拉加载(一分钟搞定,超级简单)
- 用一个简单的示例说明日志记录组件log4net的使用
- cakephp菜鸟笔记3
- android菜鸟学习笔记21----ContentProvider(一)ContentProvider的简单使用
- kafka笔记NO.1 基础组件说明
- 使用DotNetOpenAuth搭建OAuth2.0授权框架——Demo代码简单说明
- cakephp菜鸟笔记4
- CakePHP的Auth组件
- ExtJS学习笔记三:简单组件
- android菜鸟学习笔记12----Android控件(一) 几个常用的简单控件
- cocos2d-x 菜鸟学习笔记十五(简单的碰撞检测 实践篇 上)
- 菜鸟学Linux 第047篇笔记 bind97简单配置