2011-01-02 05:57:23 +00:00
|
|
|
<?php
|
2011-01-02 17:31:48 +00:00
|
|
|
/**
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2011-01-02 17:31:48 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2011-01-02 17:31:48 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
2011-03-05 22:10:42 +00:00
|
|
|
|
|
|
|
App::uses('BaseAuthenticate', 'Controller/Component/Auth');
|
2011-01-02 05:57:23 +00:00
|
|
|
|
2011-01-02 17:31:48 +00:00
|
|
|
/**
|
|
|
|
* An authentication adapter for AuthComponent. Provides the ability to authenticate using POST
|
|
|
|
* data. Can be used by configuring AuthComponent to use it via the AuthComponent::$authenticate setting.
|
|
|
|
*
|
|
|
|
* {{{
|
|
|
|
* $this->Auth->authenticate = array(
|
|
|
|
* 'Form' => array(
|
|
|
|
* 'scope' => array('User.active' => 1)
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* }}}
|
|
|
|
*
|
|
|
|
* When configuring FormAuthenticate you can pass in settings to which fields, model and additional conditions
|
|
|
|
* are used. See FormAuthenticate::$settings for more information.
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Controller.Component.Auth
|
2011-01-02 17:31:48 +00:00
|
|
|
* @since 2.0
|
2011-01-02 18:21:21 +00:00
|
|
|
* @see AuthComponent::$authenticate
|
2011-01-02 17:31:48 +00:00
|
|
|
*/
|
2011-01-21 23:09:41 +00:00
|
|
|
class FormAuthenticate extends BaseAuthenticate {
|
2011-01-02 05:57:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Authenticates the identity contained in a request. Will use the `settings.userModel`, and `settings.fields`
|
|
|
|
* to find POST data that is used to find a matching record in the `settings.userModel`. Will return false if
|
|
|
|
* there is no post data, either username or password is missing, of if the scope conditions have not been met.
|
|
|
|
*
|
|
|
|
* @param CakeRequest $request The request that contains login information.
|
2011-01-22 00:56:23 +00:00
|
|
|
* @param CakeResponse $response Unused response object.
|
2011-01-02 05:57:23 +00:00
|
|
|
* @return mixed. False on login failure. An array of User data on success.
|
|
|
|
*/
|
2011-01-22 00:56:23 +00:00
|
|
|
public function authenticate(CakeRequest $request, CakeResponse $response) {
|
2011-01-02 05:57:23 +00:00
|
|
|
$userModel = $this->settings['userModel'];
|
2011-01-03 23:17:27 +00:00
|
|
|
list($plugin, $model) = pluginSplit($userModel);
|
|
|
|
|
2011-01-02 05:57:23 +00:00
|
|
|
$fields = $this->settings['fields'];
|
2011-01-03 23:17:27 +00:00
|
|
|
if (empty($request->data[$model])) {
|
2011-01-02 05:57:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (
|
2011-01-03 23:17:27 +00:00
|
|
|
empty($request->data[$model][$fields['username']]) ||
|
|
|
|
empty($request->data[$model][$fields['password']])
|
2011-01-02 05:57:23 +00:00
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-01-22 01:52:38 +00:00
|
|
|
return $this->_findUser(
|
|
|
|
$request->data[$model][$fields['username']],
|
|
|
|
$request->data[$model][$fields['password']]
|
2011-01-02 05:57:23 +00:00
|
|
|
);
|
|
|
|
}
|
2011-01-21 21:22:29 +00:00
|
|
|
|
2011-01-02 05:57:23 +00:00
|
|
|
}
|