Skip to content

Commit

Permalink
Merge branch 'release/1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krämer committed May 25, 2013
2 parents a1f2bcf + 01c962e commit 3df8ffe
Show file tree
Hide file tree
Showing 46 changed files with 767 additions and 321 deletions.
4 changes: 2 additions & 2 deletions Config/Migration/001_initialize_users_schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/**
* Users CakePHP Plugin
*
* Copyright 2010 - 2011, Cake Development Corporation
* Copyright 2010 - 2013, Cake Development Corporation
* 1785 E. Sahara Avenue, Suite 490-423
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @Copyright 2010 - 2011, Cake Development Corporation
* @Copyright 2010 - 2013, Cake Development Corporation
* @link http://github.com/CakeDC/users
* @package plugins.users.config.migrations
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
Expand Down
4 changes: 2 additions & 2 deletions Config/Migration/002_renaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/**
* Users CakePHP Plugin
*
* Copyright 2010 - 2011, Cake Development Corporation
* Copyright 2010 - 2013, Cake Development Corporation
* 1785 E. Sahara Avenue, Suite 490-423
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @Copyright 2010 - 2011, Cake Development Corporation
* @Copyright 2010 - 2013, Cake Development Corporation
* @link http://github.com/CakeDC/users
* @package plugins.users.config.migrations
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
Expand Down
4 changes: 2 additions & 2 deletions Config/Migration/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/**
* Users CakePHP Plugin
*
* Copyright 2010 - 2011, Cake Development Corporation
* Copyright 2010 - 2013, Cake Development Corporation
* 1785 E. Sahara Avenue, Suite 490-423
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @Copyright 2010 - 2011, Cake Development Corporation
* @Copyright 2010 - 2013, Cake Development Corporation
* @link http://github.com/CakeDC/users
* @package plugins.users.config.migrations
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
Expand Down
4 changes: 2 additions & 2 deletions Config/Schema/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/**
* Users CakePHP Plugin
*
* Copyright 2010 - 2011, Cake Development Corporation
* Copyright 2010 - 2013, Cake Development Corporation
* 1785 E. Sahara Avenue, Suite 490-423
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @Copyright 2010 - 2011, Cake Development Corporation
* @Copyright 2010 - 2013, Cake Development Corporation
* @link http://github.com/CakeDC/users
* @package plugins.users.config.schema
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
Expand Down
197 changes: 197 additions & 0 deletions Controller/Component/RememberMeComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
<?php
/**
* Copyright 2010 - 2013, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2013, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('Component', 'Controller');

/**
* RememberMe Component
*
* Logs an user back in if the cookie with the credentials is found
*
* @property CookieComponent $Cookie
* @property AuthComponent $Auth
*/
class RememberMeComponent extends Component {

/**
* Components
*
* @var array
*/
public $components = array(
'Cookie',
'Auth');

/**
* Request object
*
* @var CakeRequest
*/
public $request;

/**
* Settings
*
* @var array
*/
public $settings = array();

/**
* Default settings
*
* @var array
*/
protected $_defaults = array(
'autoLogin' => true,
'userModel' => 'User',
'cookieKey' => 'rememberMe',
'cookie' => array(
'name' => 'User'),
'fields' => array(
'email',
'username',
'password'));

/**
* Constructor
*
* @param ComponentCollection $collection A ComponentCollection for this component
* @param array $settings Array of settings.
*/
public function __construct(ComponentCollection $collection, $settings = array()) {
parent::__construct($collection, $settings);
$this->settings = Set::merge($this->_defaults, $settings);
$this->configureCookie($this->settings['cookie']);
}

/**
* Initializes RememberMeComponent for use in the controller
*
* @param Controller $controller A reference to the instantiating controller object
* @return void
*/
public function initialize(Controller $controller) {
$this->request = $controller->request;
}

/**
* startup
*
* @param Controller $controller
* @return void
*/
public function startup(Controller $controller) {
if ($this->settings['autoLogin'] == true && !$this->Auth->loggedIn()) {
$this->restoreLoginFromCookie();
}
}

/**
* Logs the user again in based on the cookie data
*
* @param boolean $checkLoginStatus
* @return boolean True on login success, false on failure
*/
public function restoreLoginFromCookie($checkLoginStatus = true) {
if ($checkLoginStatus && $this->Auth->loggedIn()) {
return true;
}

extract($this->settings);
$cookie = $this->Cookie->read($cookieKey);

if (!empty($cookie)) {
$request = $this->request->data;

foreach ($fields as $field) {
if (!empty($cookie[$field])) {
$this->request->data[$userModel][$field] = $cookie[$field];
}
}

$result = $this->Auth->login();

if (!$result) {
$this->request->data = $request;
}

return $result;
}
}

/**
* Sets the cookie with the specified fields
*
* @param array Optional, login credentials array in the form of Model.field, if empty this->request['<model>'] will be used
* @return boolean
*/
public function setCookie($data = array()) {
extract($this->settings);

if (empty($data)) {
$data = $this->request->data;
if (empty($data)) {
$data = $this->Auth->user();
}
}

if (empty($data)) {
return false;
}

$cookieData = array();

foreach ($fields as $field) {
if (isset($data[$userModel][$field]) && !empty($data[$userModel][$field])) {
$cookieData[$field] = $data[$userModel][$field];
}
}

return $this->Cookie->write($cookieKey, $cookieData, true, '+99 years');
}

/**
* Destroys the remember me cookie
*
* @return void
*/
public function destroyCookie() {
extract($this->settings);
if (isset($_COOKIE[$cookie['name']])) {
$this->Cookie->name = $cookie['name'];
$this->Cookie->destroy();
}
}

/**
* Configures the cookie component instance
*
* @param array $options
* @throws InvalidArgumentException Thrown if an invalid option key was passed
* @return void
*/
public function configureCookie($options = array()) {
$validProperties = array('domain', 'key', 'name', 'path', 'secure', 'time');
$defaults = array(
'time' => '1 month',
'name' => 'User');

$options = array_merge($defaults, $options);

foreach ($options as $key => $value) {
if (in_array($key, $validProperties)) {
$this->Cookie->{$key} = $value;
} else {
throw new InvalidArgumentException(__('users', 'Invalid options %s', $key));
}
}
}
}
16 changes: 8 additions & 8 deletions Controller/UserDetailsController.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
/**
* Copyright 2010 - 2011, Cake Development Corporation (http://cakedc.com)
* Copyright 2010 - 2013, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2011, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2010 - 2013, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down Expand Up @@ -39,13 +39,13 @@ class UserDetailsController extends UsersAppController {
* @return void
*/
public function index() {
$user_details = $this->UserDetail->find('all', array(
$userDetails = $this->UserDetail->find('all', array(
'contain' => array(),
'conditions' => array(
'UserDetail.user_id' => $this->Auth->user('id'),
'UserDetail.field LIKE' => 'user.%'),
'order' => 'UserDetail.position DESC'));
$this->set('user_details', $user_details);
$this->set('user_details', $userDetails);
}

/**
Expand All @@ -70,8 +70,8 @@ public function view($id = null) {
public function add() {
if (!empty($this->request->data)) {
$userId = $this->Auth->user('id');
foreach($this->request->data as $group => $options) {
foreach($options as $key => $value) {
foreach ($this->request->data as $group => $options) {
foreach ($options as $key => $value) {
$field = $group . '.' . $key;
$this->UserDetail->updateAll(
array('Detail.value' => "'$value'"),
Expand Down Expand Up @@ -102,8 +102,8 @@ public function edit($section = 'user') {
}

if (empty($this->request->data)) {
$detail = $this->UserDetail->getSection($this->Auth->user('id'), $section);
$this->request->data['UserDetail'] = $detail[$section];
$detail = $this->UserDetail->getSection($this->Auth->user('id'), $section);
$this->request->data['UserDetail'] = $detail[$section];
}

$this->set('section', $section);
Expand Down
9 changes: 5 additions & 4 deletions Controller/UsersAppController.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
/**
* Copyright 2010 - 2011, Cake Development Corporation (http://cakedc.com)
* Copyright 2010 - 2013, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2011, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2010 - 2013, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand All @@ -25,10 +25,11 @@ class UsersAppController extends AppController {
*
* This is called to see if a user (when logged in) is able to access an action
*
* @param array $user
* @return boolean True if allowed
*/
public function isAuthorized() {
return parent::isAuthorized;
public function isAuthorized($user) {
return parent::isAuthorized($user);
}

}
Loading

0 comments on commit 3df8ffe

Please sign in to comment.