CakePHP的验证基本只有合法的用户 [英] cakephp authenticate basic only valid users
本文介绍了CakePHP的验证基本只有合法的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的验证与身份验证基础。
有没有一种方法来检查用户是否激活= 1?
我想检查的形式和基本方法。
基本方法是使用,当用户从一个iPhone应用程序通过HTTP头发送的用户名和密码登录。
公共$组件=阵列('会议','RequestHandler','验证'=>阵列(
的LoginAction =>阵列(
控制器=> API,
'行动'=> '登录'
)
'身份验证'=>阵列(
基本= GT;阵列(
'的usermodel'=> APPUSER',
'域'=>阵列(
用户名= GT; '名称'
)
)
形= GT;阵列(
'的usermodel'=> APPUSER',
'域'=>阵列(
用户名= GT; '名称'
)
)
)
));
解决方案
使用的AuthComponent的范围
设置并使用所有设置
常数:
公共$组件=阵列(
'验证'=>阵列(
的LoginAction =>阵列(
控制器=> API,
'行动'=> '登录'
)
'身份验证'=>阵列(
AuthComponent :: ALL =>阵列(//使用这个应用的通用设置
'的usermodel'=> APPUSER',
'域'=>阵列(
用户名= GT; '名称'
)
范围=>阵列(
Appuser.active'=> 1 //这是你所需要的支票
)
)
基本,
'形成'
)
)
);
有关更多信息,请参阅<一个href=\"http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#configuring-authentication-handlers\"相对=nofollow>书中本节。
I am using the Auth with authenticate Basic. Is there a way to check if the user is active = 1? I would like to check that for the Form and the Basic method. The Basic method is used, when a user log in from an iphone app sending username and password via http header.
public $components = array('Session', 'RequestHandler', 'Auth' => array(
'loginAction' => array(
'controller' => 'api',
'action' => 'login'
),
'authenticate' => array(
'Basic' => array(
'userModel' => 'Appuser',
'fields' => array(
'username' => 'name'
)
),
'Form' => array(
'userModel' => 'Appuser',
'fields' => array(
'username' => 'name'
)
)
)
));
解决方案
Use the scope
setting of the AuthComponent and set it using the ALL
constant:
public $components = array(
'Auth' => array(
'loginAction' => array(
'controller' => 'api',
'action' => 'login'
),
'authenticate' => array(
AuthComponent::ALL => array( // Use this to apply common settings
'userModel' => 'Appuser',
'fields' => array(
'username' => 'name'
),
'scope' => array(
'Appuser.active' => 1 // This is the check you need
)
),
'Basic',
'Form'
)
)
);
For more info, refer to this section in the book.
这篇关于CakePHP的验证基本只有合法的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文