Created
January 5, 2012 15:15
-
-
Save mozmorris/1565672 to your computer and use it in GitHub Desktop.
ExtendedFormAuthenticate class that overrides CakePhp's FormAuthenticate class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('FormAuthenticate', 'Controller/Component/Auth'); | |
class ExtendedFormAuthenticate extends FormAuthenticate | |
{ | |
public function authenicate(CakeRequest $request, CakeResponse $response) { | |
$userModel = $this->settings['userModel']; | |
list($plugin, $model) = pluginSplit($userModel); | |
$fields = $this->settings['fields']; | |
if (empty($request->data[$model])) { | |
return false; | |
} | |
if ( | |
empty($request->data[$model][$fields['username']]) || | |
empty($request->data[$model][$fields['password']]) | |
) { | |
return false; | |
} | |
return $this->_findUser( | |
$request->data[$model][$fields['username']], | |
$request->data[$model][$fields['password']] | |
); | |
} | |
protected function _findUser($username, $password) | |
{ | |
$userModel = $this->settings['userModel']; | |
list($plugin, $model) = pluginSplit($userModel); | |
$fields = $this->settings['fields']; | |
$conditions = array( | |
$model . '.' . $fields['username'] => $username, | |
$model . '.' . $fields['password'] => $this->_password($password), | |
); | |
if (!empty($this->settings['scope'])) { | |
$conditions = array_merge($conditions, $this->settings['scope']); | |
} | |
$result = ClassRegistry::init($userModel)->find('first', array( | |
'conditions' => $conditions, | |
'recursive' => -1 | |
)); | |
if (empty($result) || empty($result[$model])) { | |
return false; | |
} | |
unset($result[$model][$fields['password']]); | |
return $result[$model]; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment