Skip to content

Commit e3daf6f

Browse files
author
Florian Krämer
committed
Merge branch 'develop' into feature/remember-me
Conflicts: Controller/Component/RememberMeComponent.php
2 parents dcf41f6 + d1017ec commit e3daf6f

57 files changed

Lines changed: 1540 additions & 1672 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
language: php
2+
3+
php:
4+
- 5.2.8
5+
- 5.3
6+
- 5.4
7+
8+
before_script:
9+
- git clone --depth 1 git://github.com/cakephp/cakephp ../cakephp && cd ../cakephp
10+
- git clone --depth 1 --branch develop git://github.com/CakeDC/search plugins/search
11+
- cd plugins/Search
12+
- git submodule update --init --recursive
13+
- cd ../../
14+
- mv ../Users plugins/Users
15+
- sh -c "mysql -e 'CREATE DATABASE cakephp_test;'"
16+
- chmod -R 777 ../cakephp/app/tmp
17+
- echo "<?php
18+
class DATABASE_CONFIG {
19+
public \$test = array(
20+
'datasource' => 'Database/Mysql',
21+
'database' => 'cakephp_test',
22+
'host' => '0.0.0.0',
23+
'login' => 'travis',
24+
'persistent' => false,
25+
);
26+
}" > ../cakephp/app/Config/database.php
27+
28+
script:
29+
- ./lib/Cake/Console/cake test Users AllUsersPlugin --stderr
30+
31+
notifications:
32+
email: false

Config/Migration/001_initialize_users_schema.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
/**
33
* Users CakePHP Plugin
44
*
5-
* Copyright 2010 - 2012, Cake Development Corporation
5+
* Copyright 2010 - 2013, Cake Development Corporation
66
* 1785 E. Sahara Avenue, Suite 490-423
77
* Las Vegas, Nevada 89104
88
*
99
* Licensed under The MIT License
1010
* Redistributions of files must retain the above copyright notice.
1111
*
12-
* @Copyright 2010 - 2011, Cake Development Corporation
12+
* @Copyright 2010 - 2013, Cake Development Corporation
1313
* @link http://github.com/CakeDC/users
1414
* @package plugins.users.config.migrations
1515
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)

Config/Migration/002_renaming.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
/**
33
* Users CakePHP Plugin
44
*
5-
* Copyright 2010 - 2012, Cake Development Corporation
5+
* Copyright 2010 - 2013, Cake Development Corporation
66
* 1785 E. Sahara Avenue, Suite 490-423
77
* Las Vegas, Nevada 89104
88
*
99
* Licensed under The MIT License
1010
* Redistributions of files must retain the above copyright notice.
1111
*
12-
* @Copyright 2010 - 2011, Cake Development Corporation
12+
* @Copyright 2010 - 2013, Cake Development Corporation
1313
* @link http://github.com/CakeDC/users
1414
* @package plugins.users.config.migrations
1515
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)

Config/Migration/map.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
/**
33
* Users CakePHP Plugin
44
*
5-
* Copyright 2010 - 2012, Cake Development Corporation
5+
* Copyright 2010 - 2013, Cake Development Corporation
66
* 1785 E. Sahara Avenue, Suite 490-423
77
* Las Vegas, Nevada 89104
88
*
99
* Licensed under The MIT License
1010
* Redistributions of files must retain the above copyright notice.
1111
*
12-
* @Copyright 2010 - 2011, Cake Development Corporation
12+
* @Copyright 2010 - 2013, Cake Development Corporation
1313
* @link http://github.com/CakeDC/users
1414
* @package plugins.users.config.migrations
1515
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)

Config/Schema/schema.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
/**
33
* Users CakePHP Plugin
44
*
5-
* Copyright 2010 - 2012, Cake Development Corporation
5+
* Copyright 2010 - 2013, Cake Development Corporation
66
* 1785 E. Sahara Avenue, Suite 490-423
77
* Las Vegas, Nevada 89104
88
*
99
* Licensed under The MIT License
1010
* Redistributions of files must retain the above copyright notice.
1111
*
12-
* @Copyright 2010 - 2011, Cake Development Corporation
12+
* @Copyright 2010 - 2013, Cake Development Corporation
1313
* @link http://github.com/CakeDC/users
1414
* @package plugins.users.config.schema
1515
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
App::uses('BaseAuthenticate', 'Controller/Component/Auth');
3+
App::uses('AuthComponent', 'Controller/Component');
4+
App::uses('Router', 'Routing');
5+
6+
/**
7+
* An authentication adapter for AuthComponent. Provides the ability to authenticate using COOKIE
8+
*
9+
* {{{
10+
* $this->Auth->authenticate = array(
11+
* 'Authenticate.Cookie' => array(
12+
* 'fields' => array(
13+
* 'username' => 'username',
14+
* 'password' => 'password'
15+
* ),
16+
* 'userModel' => 'User',
17+
* 'scope' => array('User.active' => 1),
18+
* 'crypt' => 'rijndael', // Defaults to rijndael(safest), optionally set to 'cipher' if required
19+
* 'cookie' => array(
20+
* 'name' => 'RememberMe',
21+
* 'time' => '+2 weeks',
22+
* )
23+
* )
24+
* )
25+
* }}}
26+
*
27+
* @author Ceeram
28+
* @copyright Ceeram
29+
* @license MIT
30+
* @link https://github.com/ceeram/Authenticate
31+
*/
32+
class CookieAuthenticate extends BaseAuthenticate {
33+
34+
public function __construct(ComponentCollection $collection, $settings) {
35+
$this->settings['cookie'] = array(
36+
'name' => 'RememberMe',
37+
'time' => '+2 weeks',
38+
'base' => Router::getRequest()->base
39+
);
40+
$this->settings['crypt'] = 'rijndael';
41+
parent::__construct($collection, $settings);
42+
}
43+
44+
/**
45+
* Authenticates the identity contained in the cookie. Will use the `settings.userModel`, and `settings.fields`
46+
* to find COOKIE data that is used to find a matching record in the `settings.userModel`. Will return false if
47+
* there is no cookie data, either username or password is missing, of if the scope conditions have not been met.
48+
*
49+
* @param CakeRequest $request The unused request object
50+
* @return mixed False on login failure. An array of User data on success.
51+
* @throws CakeException
52+
*/
53+
public function getUser(CakeRequest $request) {
54+
if (!isset($this->_Collection->Cookie) || !$this->_Collection->Cookie instanceof CookieComponent) {
55+
throw new CakeException('CookieComponent is not loaded');
56+
}
57+
58+
$this->_Collection->Cookie->type($this->settings['crypt']);
59+
list(, $model) = pluginSplit($this->settings['userModel']);
60+
61+
$data = $this->_Collection->Cookie->read($model);
62+
if (empty($data)) {
63+
return false;
64+
}
65+
66+
extract($this->settings['fields']);
67+
if (empty($data[$username]) || empty($data[$password])) {
68+
return false;
69+
}
70+
71+
$user = $this->_findUser($data[$username], $data[$password]);
72+
if ($user) {
73+
$this->_Collection->Session->write(AuthComponent::$sessionKey, $user);
74+
return $user;
75+
}
76+
return false;
77+
}
78+
79+
public function authenticate(CakeRequest $request, CakeResponse $response) {
80+
return $this->getUser($request);
81+
}
82+
83+
public function logout($user) {
84+
$this->_Collection->Cookie->destroy();
85+
}
86+
87+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
App::uses('FormAuthenticate', 'Controller/Component/Auth');
3+
4+
/**
5+
* An authentication adapter for AuthComponent. Provides the ability to authenticate using POST
6+
* data. The username form input can be checked against multiple table columns, for instance username and email
7+
*
8+
* {{{
9+
* $this->Auth->authenticate = array(
10+
* 'Authenticate.MultiColumn' => array(
11+
* 'fields' => array(
12+
* 'username' => 'username',
13+
* 'password' => 'password'
14+
* ),
15+
* 'columns' => array('username', 'email'),
16+
* 'userModel' => 'User',
17+
* 'scope' => array('User.active' => 1)
18+
* )
19+
* )
20+
* }}}
21+
*
22+
* @author Ceeram
23+
* @copyright Ceeram
24+
* @license MIT
25+
* @link https://github.com/ceeram/Authenticate
26+
*/
27+
class MultiColumnAuthenticate extends FormAuthenticate {
28+
29+
/**
30+
* Settings for this object.
31+
*
32+
* - `fields` The fields to use to identify a user by.
33+
* - 'columns' array of columns to check username form input against
34+
* - `userModel` The model name of the User, defaults to User.
35+
* - `scope` Additional conditions to use when looking up and authenticating users,
36+
* i.e. `array('User.is_active' => 1).`
37+
*
38+
* @var array
39+
*/
40+
public $settings = array(
41+
'fields' => array(
42+
'username' => 'username',
43+
'password' => 'password'
44+
),
45+
'columns' => array(),
46+
'userModel' => 'User',
47+
'scope' => array()
48+
);
49+
50+
/**
51+
* Find a user record using the standard options.
52+
*
53+
* @param string $username The username/identifier.
54+
* @param string $password The unhashed password.
55+
* @return Mixed Either false on failure, or an array of user data.
56+
*/
57+
protected function _findUser($username, $password = null) {
58+
$userModel = $this->settings['userModel'];
59+
list($plugin, $model) = pluginSplit($userModel);
60+
$fields = $this->settings['fields'];
61+
$conditions = array($model . '.' . $fields['username'] => $username);
62+
if ($this->settings['columns'] && is_array($this->settings['columns'])) {
63+
$columns = array();
64+
foreach ($this->settings['columns'] as $column) {
65+
$columns[] = array($model . '.' . $column => $username);
66+
}
67+
$conditions = array('OR' => $columns);
68+
}
69+
$conditions = array_merge($conditions, array($model . '.' . $fields['password'] => $this->_password($password)));
70+
if (!empty($this->settings['scope'])) {
71+
$conditions = array_merge($conditions, $this->settings['scope']);
72+
}
73+
$result = ClassRegistry::init($userModel)->find('first', array(
74+
'conditions' => $conditions,
75+
'recursive' => 0
76+
));
77+
if (empty($result) || empty($result[$model])) {
78+
return false;
79+
}
80+
unset($result[$model][$fields['password']]);
81+
return $result[$model];
82+
}
83+
84+
}

0 commit comments

Comments
 (0)