diff --git a/config/migrations/001_initialize_users_schema.php b/Config/Migration/001_initialize_users_schema.php similarity index 90% rename from config/migrations/001_initialize_users_schema.php rename to Config/Migration/001_initialize_users_schema.php index a7e5356e3..89f7d8f40 100644 --- a/config/migrations/001_initialize_users_schema.php +++ b/Config/Migration/001_initialize_users_schema.php @@ -31,7 +31,7 @@ class M49c3417a54874a9d276811502cedc421 extends CakeMigration { public $migration = array( 'up' => array( 'create_table' => array( - 'details' => array( + 'user_details' => array( 'id' => array('type'=>'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary'), 'user_id' => array('type'=>'string', 'null' => false, 'default' => NULL, 'length' => 36), 'position' => array('type'=>'float', 'null' => false, 'default' => '1', 'length' => 4), @@ -50,16 +50,16 @@ class M49c3417a54874a9d276811502cedc421 extends CakeMigration { 'id' => array('type'=>'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary'), 'username' => array('type'=>'string', 'null' => false, 'default' => NULL), 'slug' => array('type'=>'string', 'null' => false, 'default' => NULL), - 'passwd' => array('type'=>'string', 'null' => true, 'default' => NULL, 'length' => 128), + 'password' => array('type'=>'string', 'null' => true, 'default' => NULL, 'length' => 128), 'password_token' => array('type'=>'string', 'null' => true, 'default' => NULL, 'length' => 128), 'email' => array('type'=>'string', 'null' => true, 'default' => NULL), - 'email_authenticated' => array('type'=>'boolean', 'null' => true, 'default' => '0'), + 'email_verified' => array('type'=>'boolean', 'null' => true, 'default' => '0'), 'email_token' => array('type'=>'string', 'null' => true, 'default' => NULL), - 'email_token_expires' => array('type'=>'datetime', 'null' => true, 'default' => NULL), + 'email_token_expiry' => array('type'=>'datetime', 'null' => true, 'default' => NULL), 'tos' => array('type'=>'boolean', 'null' => true, 'default' => '0'), 'active' => array('type'=>'boolean', 'null' => true, 'default' => '0'), 'last_login' => array('type'=>'datetime', 'null' => true, 'default' => NULL), - 'last_activity' => array('type'=>'datetime', 'null' => true, 'default' => NULL), + 'last_action' => array('type'=>'datetime', 'null' => true, 'default' => NULL), 'is_admin' => array('type'=>'boolean', 'null' => true, 'default' => '0'), 'role' => array('type'=>'string', 'null' => true, 'default' => NULL), 'created' => array('type'=>'datetime', 'null' => true, 'default' => NULL), @@ -74,7 +74,7 @@ class M49c3417a54874a9d276811502cedc421 extends CakeMigration { ), 'down' => array( 'drop_table' => array( - 'users', 'details'), + 'users', 'user_details'), ) ); diff --git a/config/migrations/map.php b/Config/Migration/map.php similarity index 100% rename from config/migrations/map.php rename to Config/Migration/map.php diff --git a/config/schema/users.php b/Config/Schema/schema.php similarity index 88% rename from config/schema/users.php rename to Config/Schema/schema.php index 343ba9346..0653c4614 100644 --- a/config/schema/users.php +++ b/Config/Schema/schema.php @@ -24,7 +24,7 @@ function before($event = array()) { function after($event = array()) { } - var $details = array( + var $user_details = array( 'id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary'), 'user_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36), 'position' => array('type' => 'float', 'null' => false, 'default' => '1'), @@ -41,16 +41,16 @@ function after($event = array()) { 'id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary'), 'username' => array('type' => 'string', 'null' => false, 'default' => NULL, 'key' => 'index'), 'slug' => array('type' => 'string', 'null' => false, 'default' => NULL), - 'passwd' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 128), + 'password' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 128), 'password_token' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 128), 'email' => array('type' => 'string', 'null' => true, 'default' => NULL, 'key' => 'index'), - 'email_authenticated' => array('type' => 'boolean', 'null' => true, 'default' => '0'), + 'email_verified' => array('type' => 'boolean', 'null' => true, 'default' => '0'), 'email_token' => array('type' => 'string', 'null' => true, 'default' => NULL), - 'email_token_expires' => array('type' => 'datetime', 'null' => true, 'default' => NULL), + 'email_token_expiry' => array('type' => 'datetime', 'null' => true, 'default' => NULL), 'tos' => array('type' => 'boolean', 'null' => true, 'default' => '0'), 'active' => array('type' => 'boolean', 'null' => true, 'default' => '0'), 'last_login' => array('type' => 'datetime', 'null' => true, 'default' => NULL), - 'last_activity' => array('type' => 'datetime', 'null' => true, 'default' => NULL), + 'last_action' => array('type' => 'datetime', 'null' => true, 'default' => NULL), 'is_admin' => array('type' => 'boolean', 'null' => true, 'default' => '0'), 'role' => array('type' => 'string', 'null' => true, 'default' => NULL), 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), diff --git a/controllers/details_controller.php b/Controller/UserDetailsController.php similarity index 79% rename from controllers/details_controller.php rename to Controller/UserDetailsController.php index 164426b02..7f7225eba 100644 --- a/controllers/details_controller.php +++ b/Controller/UserDetailsController.php @@ -9,20 +9,22 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::uses('UsersAppController', 'Users.Controller'); + /** * Users Details Controller * * @package users * @subpackage users.controllers */ -class DetailsController extends UsersAppController { +class UserDetailsController extends UsersAppController { /** * Name * * @var string */ - public $name = 'Details'; + public $name = 'UserDetails'; /** * Helpers @@ -54,8 +56,8 @@ public function index() { */ public function view($id = null) { if (!$id) { - $this->Session->setFlash(__d('users', 'Invalid Detail.', true)); - $this->redirect(array('action'=>'index')); + $this->Session->setFlash(__d('users', 'Invalid Detail.')); + $this->redirect(array('action' => 'index')); } $this->set('detail', $this->Detail->read(null, $id)); } @@ -76,7 +78,7 @@ public function add() { array('Detail.user_id' => $userId, 'Detail.field' => $field)); } } - $this->Session->setFlash(__d('users', 'Saved', true)); + $this->Session->setFlash(__d('users', 'Saved')); } $this->redirect(array('action' => 'index')); } @@ -97,7 +99,7 @@ public function edit($section = 'user') { if (!empty($this->data)) { $this->Detail->saveSection($this->Auth->user('id'), $this->data, $section); $this->data['Detail'] = $this->Detail->getSection($this->Auth->user('id'), $section); - $this->Session->setFlash(sprintf(__d('users', '%s details saved', true), ucfirst($section))); + $this->Session->setFlash(sprintf(__d('users', '%s details saved'), ucfirst($section))); } if (empty($this->data)) { @@ -115,12 +117,12 @@ public function edit($section = 'user') { */ public function delete($id = null) { if (!$id) { - $this->Session->setFlash(__d('users', 'Invalid id for Detail', true)); - $this->redirect(array('action'=>'index')); + $this->Session->setFlash(__d('users', 'Invalid id for Detail')); + $this->redirect(array('action' => 'index')); } if ($this->Detail->delete($id)) { - $this->Session->setFlash(__d('users', 'Detail deleted', true)); - $this->redirect(array('action'=>'index')); + $this->Session->setFlash(__d('users', 'Detail deleted')); + $this->redirect(array('action' => 'index')); } } @@ -142,8 +144,8 @@ public function admin_index() { */ public function admin_view($id = null) { if (!$id) { - $this->Session->setFlash(__d('users', 'Invalid Detail.', true)); - $this->redirect(array('action'=>'index')); + $this->Session->setFlash(__d('users', 'Invalid Detail.')); + $this->redirect(array('action' => 'index')); } $this->set('detail', $this->Detail->read(null, $id)); } @@ -157,10 +159,10 @@ public function admin_add() { if (!empty($this->data)) { $this->Detail->create(); if ($this->Detail->save($this->data)) { - $this->Session->setFlash(__d('users', 'The Detail has been saved', true)); - $this->redirect(array('action'=>'index')); + $this->Session->setFlash(__d('users', 'The Detail has been saved')); + $this->redirect(array('action' => 'index')); } else { - $this->Session->setFlash(__d('users', 'The Detail could not be saved. Please, try again.', true)); + $this->Session->setFlash(__d('users', 'The Detail could not be saved. Please, try again.')); } } @@ -176,15 +178,15 @@ public function admin_add() { */ public function admin_edit($id = null) { if (!$id && empty($this->data)) { - $this->Session->setFlash(__d('users', 'Invalid Detail', true)); - $this->redirect(array('action'=>'index')); + $this->Session->setFlash(__d('users', 'Invalid Detail')); + $this->redirect(array('action' => 'index')); } if (!empty($this->data)) { if ($this->Detail->save($this->data)) { - $this->Session->setFlash(__d('users', 'The Detail has been saved', true)); - $this->redirect(array('action'=>'index')); + $this->Session->setFlash(__d('users', 'The Detail has been saved')); + $this->redirect(array('action' => 'index')); } else { - $this->Session->setFlash(__d('users', 'The Detail could not be saved. Please, try again.', true)); + $this->Session->setFlash(__d('users', 'The Detail could not be saved. Please, try again.')); } } if (empty($this->data)) { @@ -203,12 +205,12 @@ public function admin_edit($id = null) { */ public function admin_delete($id = null) { if (!$id) { - $this->Session->setFlash(__d('users', 'Invalid id for Detail', true)); - $this->redirect(array('action'=>'index')); + $this->Session->setFlash(__d('users', 'Invalid id for Detail')); + $this->redirect(array('action' => 'index')); } if ($this->Detail->delete($id)) { - $this->Session->setFlash(__d('users', 'Detail deleted', true)); - $this->redirect(array('action'=>'index')); + $this->Session->setFlash(__d('users', 'Detail deleted')); + $this->redirect(array('action' => 'index')); } } } diff --git a/users_app_controller.php b/Controller/UsersAppController.php similarity index 69% rename from users_app_controller.php rename to Controller/UsersAppController.php index 92b5400ae..ff2cdd581 100644 --- a/users_app_controller.php +++ b/Controller/UsersAppController.php @@ -16,4 +16,15 @@ * @subpackage users.controllers */ class UsersAppController extends AppController { + +/** + * Default isAuthorized method + * + * This is called to see if a user (when logged in) is able to access an action + * + * @return boolean True if allowed + */ + public function isAuthorized() { + return true; + } } diff --git a/controllers/users_controller.php b/Controller/UsersController.php similarity index 54% rename from controllers/users_controller.php rename to Controller/UsersController.php index 7d431718e..8d4a0b26c 100644 --- a/controllers/users_controller.php +++ b/Controller/UsersController.php @@ -9,6 +9,8 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::uses('UsersAppController', 'Users.Controller'); + /** * Users Users Controller * @@ -29,14 +31,14 @@ class UsersController extends UsersAppController { * * @var array */ - public $helpers = array('Html', 'Form', 'Session', 'Time', 'Text', 'Utils.Gravatar'); + public $helpers = array('Html', 'Form', 'Session', 'Time', 'Text'); /** * Components * * @var array */ - public $components = array('Auth', 'Session', 'Email', 'Cookie', 'Search.Prg'); + public $components = array('Auth', 'Session', 'Email', 'Cookie','Paginator'); /** * $presetVars @@ -49,21 +51,47 @@ class UsersController extends UsersAppController { array('field' => 'email', 'type' => 'value')); /** - * beforeFilter callback + * Constructor. * - * @return void + * @param CakeRequest $request Request object for this controller can be null for testing. + * But expect that features that use the params will not work. */ - public function beforeFilter() { - parent::beforeFilter(); - $this->Auth->allow('register', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password'); + public function __construct($request, $response) { + parent::__construct($request, $response); + $this->_setupComponents(); + $this->_setupHelpers(); + } - if ($this->action == 'register') { - $this->Auth->enabled = false; +/** + * Setup components based on plugin availability + * + * @return void + */ + protected function _setupComponents() { + if (App::import('Component', 'Search.Prg')) { + $this->components[] = 'Search.Prg'; } + } - if ($this->action == 'login') { - $this->Auth->autoRedirect = false; +/** + * Setup helpers based on plugin availability + * + * @return void + */ + protected function _setupHelpers() { + if (App::import('Helper', 'Goodies.Gravatar')) { + $this->helpers[] = 'Goodies.Gravatar'; } + } + +/** + * beforeFilter callback + * + * @return void + */ + public function beforeFilter() { + parent::beforeFilter(); + $this->_setupAuth(); $this->set('model', $this->modelClass); @@ -72,6 +100,23 @@ public function beforeFilter() { } } +/** + * Setup Authentication Component + * + * @return void + */ + public function _setupAuth() { + $this->Auth->allow('add', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password'); + + if ($this->action == 'add') { + $this->Components->disable('Auth'); + } + + if ($this->action == 'login') { + $this->Auth->autoRedirect = false; + } + } + /** * List of all users * @@ -80,13 +125,13 @@ public function beforeFilter() { public function index() { //$this->User->contain('Detail'); $searchTerm = ''; - $this->Prg->commonProcess($this->modelClass, $this->modelClass, 'index', false); + //$this->Prg->commonProcess($this->modelClass, $this->modelClass, 'index', false); - if (!empty($this->params['named']['search'])) { - if (!empty($this->params['named']['search'])) { - $searchTerm = $this->params['named']['search']; + if (!empty($this->request->params['named']['search'])) { + if (!empty($this->request->params['named']['search'])) { + $searchTerm = $this->request->params['named']['search']; } - $this->data[$this->modelClass]['search'] = $searchTerm; + $this->request->data[$this->modelClass]['search'] = $searchTerm; } $this->paginate = array( @@ -95,17 +140,13 @@ public function index() { 'order' => $this->modelClass . '.username ASC', 'by' => $searchTerm, 'conditions' => array( - 'OR' => array( - 'AND' => array( - $this->modelClass . '.active' => 1, - $this->modelClass . '.email_authenticated' => 1)))); - - + $this->modelClass . '.active' => 1, + $this->modelClass . '.email_verified' => 1)); $this->set('users', $this->paginate($this->modelClass)); $this->set('searchTerm', $searchTerm); - if (!isset($this->params['named']['sort'])) { - $this->params['named']['sort'] = 'username'; + if (!isset($this->request->params['named']['sort'])) { + $this->request->params['named']['sort'] = 'username'; } } @@ -141,17 +182,25 @@ public function view($slug = null) { * @return void */ public function edit() { - if (!empty($this->data)) { - if ($this->User->Detail->saveSection($this->Auth->user('id'), $this->data, 'User')) { - $this->Session->setFlash(__d('users', 'Profile saved.', true)); + if (!empty($this->request->data)) { + if ($this->User->Detail->saveSection($this->Auth->user('id'), $this->request->data, 'User')) { + $this->Session->setFlash(__d('users', 'Profile saved.')); } else { - $this->Session->setFlash(__d('users', 'Could not save your profile.', true)); + $this->Session->setFlash(__d('users', 'Could not save your profile.')); } } else { - $this->data = $this->User->read(null, $this->Auth->user('id')); + $this->request->data = $this->User->read(null, $this->Auth->user('id')); } $this->_setLanguages(); + + // Render the OpenID form if that data is present + $oid = $this->Session->read('openIdAuthData'); + if ($oid) { + $this->autoRender = false; + $this->set('openIdAuthData', $oid); + $this->render('openid_add'); + } } /** @@ -160,12 +209,15 @@ public function edit() { * @return void */ public function admin_index() { - $this->Prg->commonProcess(); +// $this->Prg->commonProcess(); $this->{$this->modelClass}->data[$this->modelClass] = $this->passedArgs; - $parsedConditions = $this->{$this->modelClass}->parseCriteria($this->passedArgs); - - $this->paginate[$this->modelClass]['conditions'] = $parsedConditions; - $this->paginate[$this->modelClass]['order'] = array($this->modelClass . '.created' => 'desc'); + if ($this->{$this->modelClass}->Behaviors->attached('Search.Searchable')) { + $parsedConditions = $this->{$this->modelClass}->parseCriteria($this->Users->passedArgs); + } else { + $parsedConditions = array(); + } + $this->Paginator->settings[$this->modelClass]['conditions'] = $parsedConditions; + $this->Paginator->settings[$this->modelClass]['order'] = array($this->modelClass . '.created' => 'desc'); $this->{$this->modelClass}->recursive = 0; $this->set('users', $this->paginate()); @@ -179,8 +231,8 @@ public function admin_index() { */ public function admin_view($id = null) { if (!$id) { - $this->Session->setFlash(__d('users', 'Invalid User.', true)); - $this->redirect(array('action'=>'index')); + $this->Session->setFlash(__d('users', 'Invalid User.')); + $this->redirect(array('action' => 'index')); } $this->set('user', $this->User->read(null, $id)); } @@ -191,8 +243,8 @@ public function admin_view($id = null) { * @return void */ public function admin_add() { - if ($this->User->add($this->data)) { - $this->Session->setFlash(__d('users', 'The User has been saved', true)); + if ($this->User->add($this->request->data)) { + $this->Session->setFlash(__d('users', 'The User has been saved')); $this->redirect(array('action' => 'index')); } } @@ -205,20 +257,20 @@ public function admin_add() { */ public function admin_edit($userId = null) { try { - $result = $this->User->edit($userId, $this->data); + $result = $this->User->edit($userId, $this->request->data); if ($result === true) { - $this->Session->setFlash(__d('users', 'User saved', true)); + $this->Session->setFlash(__d('users', 'User saved')); $this->redirect(array('action' => 'index')); } else { - $this->data = $result; + $this->request->data = $result; } } catch (OutOfBoundsException $e) { $this->Session->setFlash($e->getMessage()); $this->redirect(array('action' => 'index')); } - if (empty($this->data)) { - $this->data = $this->User->read(null, $userId); + if (empty($this->request->data)) { + $this->request->data = $this->User->read(null, $userId); } } @@ -230,9 +282,9 @@ public function admin_edit($userId = null) { */ public function admin_delete($userId = null) { if ($this->User->delete($userId)) { - $this->Session->setFlash(__d('users', 'User deleted', true)); + $this->Session->setFlash(__d('users', 'User deleted')); } else { - $this->Session->setFlash(__d('users', 'Invalid User', true)); + $this->Session->setFlash(__d('users', 'Invalid User')); } $this->redirect(array('action' => 'index')); @@ -252,23 +304,23 @@ public function admin_search() { * * @return void */ - public function register() { + public function add() { if ($this->Auth->user()) { - $this->Session->setFlash(__d('users', 'You are already registered and logged in!', true)); + $this->Session->setFlash(__d('users', 'You are already registered and logged in!')); $this->redirect('/'); } - if (!empty($this->data)) { - $user = $this->User->register($this->data); + if (!empty($this->request->data)) { + $user = $this->User->register($this->request->data); if ($user !== false) { $this->set('user', $user); $this->_sendVerificationEmail($user[$this->modelClass]['email']); - $this->Session->setFlash(__d('users', 'Your account has been created. You should receive an e-mail shortly to authenticate your account. Once validated you will be able to login.', true)); - $this->redirect(array('action'=> 'login')); + $this->Session->setFlash(__d('users', 'Your account has been created. You should receive an e-mail shortly to authenticate your account. Once validated you will be able to login.')); + $this->redirect(array('action' => 'login')); } else { - unset($this->data[$this->modelClass]['passwd']); - unset($this->data[$this->modelClass]['temppassword']); - $this->Session->setFlash(__d('users', 'Your account could not be created. Please, try again.', true), 'default', array('class' => 'message warning')); + unset($this->request->data[$this->modelClass]['password']); + unset($this->request->data[$this->modelClass]['temppassword']); + $this->Session->setFlash(__d('users', 'Your account could not be created. Please, try again.'), 'default', array('class' => 'message warning')); } } @@ -281,6 +333,7 @@ public function register() { * @return void */ public function login() { + $this->request->is('post') && $this->Auth->login(); if ($this->Auth->user()) { $this->User->id = $this->Auth->user('id'); $this->User->saveField('last_login', date('Y-m-d H:i:s')); @@ -289,9 +342,9 @@ public function login() { $this->Auth->loginRedirect = '/'; } - $this->Session->setFlash(sprintf(__d('users', '%s you have successfully logged in', true), $this->Auth->user('username'))); - if (!empty($this->data)) { - $data = $this->data[$this->modelClass]; + $this->Session->setFlash(sprintf(__d('users', '%s you have successfully logged in'), $this->Auth->user('username'))); + if (!empty($this->request->data)) { + $data = $this->request->data[$this->modelClass]; $this->_setCookie(); } @@ -299,10 +352,12 @@ public function login() { $data['return_to'] = null; } $this->redirect($this->Auth->redirect($data['return_to'])); + } else { + $this->Session->setFlash(__d('users', 'Invalid e-mail / password combination. Please try again', true), null, null, 'auth'); } - if (isset($this->params['named']['return_to'])) { - $this->set('return_to', urldecode($this->params['named']['return_to'])); + if (isset($this->request->params['named']['return_to'])) { + $this->set('return_to', urldecode($this->request->params['named']['return_to'])); } else { $this->set('return_to', false); } @@ -313,37 +368,37 @@ public function login() { * * @return void */ - public function search() { - $searchTerm = ''; - $this->Prg->commonProcess($this->modelClass, $this->modelClass, 'search', false); - - if (!empty($this->params['named']['search'])) { - $searchTerm = $this->params['named']['search']; - $by = 'any'; - } - if (!empty($this->params['named']['username'])) { - $searchTerm = $this->params['named']['username']; - $by = 'username'; - } - if (!empty($this->params['named']['email'])) { - $searchTerm = $this->params['named']['email']; - $by = 'email'; - } - $this->data[$this->modelClass]['search'] = $searchTerm; - - $this->paginate = array( - 'search', - 'limit' => 12, - 'by' => $by, - 'search' => $searchTerm, - 'conditions' => array( - 'AND' => array( - $this->modelClass . '.active' => 1, - $this->modelClass . '.email_authenticated' => 1))); - - $this->set('users', $this->paginate($this->modelClass)); - $this->set('searchTerm', $searchTerm); - } + // public function search() { + // $searchTerm = ''; + // $this->Prg->commonProcess($this->modelClass, $this->modelClass, 'search', false); + // + // if (!empty($this->request->params['named']['search'])) { + // $searchTerm = $this->request->params['named']['search']; + // $by = 'any'; + // } + // if (!empty($this->request->params['named']['username'])) { + // $searchTerm = $this->request->params['named']['username']; + // $by = 'username'; + // } + // if (!empty($this->request->params['named']['email'])) { + // $searchTerm = $this->request->params['named']['email']; + // $by = 'email'; + // } + // $this->request->data[$this->modelClass]['search'] = $searchTerm; + // + // $this->paginate = array( + // 'search', + // 'limit' => 12, + // 'by' => $by, + // 'search' => $searchTerm, + // 'conditions' => array( + // 'AND' => array( + // $this->modelClass . '.active' => 1, + // $this->modelClass . '.email_verified' => 1))); + // + // $this->set('users', $this->paginate($this->modelClass)); + // $this->set('searchTerm', $searchTerm); + // } /** * Common logout action @@ -351,78 +406,66 @@ public function search() { * @return void */ public function logout() { - $message = sprintf(__d('users', '%s you have successfully logged out', true), $this->Auth->user('username')); $this->Session->destroy(); $this->Cookie->destroy(); - $this->Session->setFlash($message); + $this->Session->setFlash(sprintf(__d('users', '%s you have successfully logged out'), $this->Auth->user('username'))); $this->redirect($this->Auth->logout()); } /** - * Confirm email action + * Confirm email action and password reset action * * @param string $type Type * @return void */ - public function verify($type = 'email') { - if (isset($this->passedArgs['1'])){ - $token = $this->passedArgs['1']; - } else { - $this->redirect(array('action' => 'login'), null, true); + public function verify($type = 'email', $token = null) { + $verifyTypes = array('email', 'reset'); + if (!$token || !in_array($type, $verifyTypes)) { + $this->Session->setFlash(__d('users', 'The url you accessed is not longer valid', true)); } - if ($type === 'email') { - $data = $this->User->validateToken($token); - } elseif($type === 'reset') { - $data = $this->User->validateToken($token, true); - } else { - $this->Session->setFlash(__d('users', 'There url you accessed is not longer valid', true)); - $this->redirect('/'); + $data = $this->User->validateToken($token, $type === 'reset'); + if (!$data) { + $this->Session->setFlash(__d('users', 'The url you accessed is not longer valid', true)); + return $this->redirect('/'); } - if ($data !== false) { - $email = $data[$this->modelClass]['email']; - unset($data[$this->modelClass]['email']); + $email = $data[$this->modelClass]['email']; + unset($data[$this->modelClass]['email']); - if ($type === 'reset') { - $newPassword = $data[$this->modelClass]['passwd']; - $data[$this->modelClass]['passwd'] = $this->Auth->password($newPassword); - } - - if ($type === 'email') { - $data[$this->modelClass]['active'] = 1; - } + if ($type === 'reset') { + $newPassword = $data[$this->modelClass]['password']; + $data[$this->modelClass]['password'] = $this->Auth->password($newPassword); + } + if ($type === 'email') { + $data[$this->modelClass]['active'] = 1; + } - if ($this->User->save($data, false)) { - if ($type === 'reset') { - $this->Email->to = $email; - $this->Email->from = Configure::read('App.defaultEmail'); - $this->Email->replyTo = Configure::read('App.defaultEmail'); - $this->Email->return = Configure::read('App.defaultEmail'); - $this->Email->subject = env('HTTP_HOST') . ' ' . __d('users', 'Password Reset', true); - $this->Email->template = null; - $content[] = __d('users', 'Your password has been reset', true); - $content[] = __d('users', 'Please login using this password and change your password', true); - $content[] = $newPassword; - $this->Email->send($content); - $this->Session->setFlash(__d('users', 'Your password was sent to your registered email account', true)); - $this->redirect(array('action' => 'login')); - } else { - unset($data); - $data[$this->modelClass]['active'] = 1; - $this->User->save($data); - $this->Session->setFlash(__d('users', 'Your e-mail has been validated!', true)); - $this->redirect(array('action' => 'login')); - } + if ($this->User->save($data, false)) { + if ($type === 'reset') { + $this->Email->to = $email; + $this->Email->from = Configure::read('App.defaultEmail'); + $this->Email->replyTo = Configure::read('App.defaultEmail'); + $this->Email->return = Configure::read('App.defaultEmail'); + $this->Email->subject = env('HTTP_HOST') . ' ' . __d('users', 'Password Reset', true); + $this->Email->template = null; + $content[] = __d('users', 'Your password has been reset', true); + $content[] = __d('users', 'Please login using this password and change your password', true); + $content[] = $newPassword; + $this->Email->send($content); + $this->Session->setFlash(__d('users', 'Your password was sent to your registered email account', true)); } else { - $this->Session->setFlash(__d('users', 'There was an error trying to validate your e-mail address. Please check your e-mail for the URL you should use to verify your e-mail address.', true)); - $this->redirect('/'); + unset($data); + $data[$this->modelClass]['active'] = 1; + $this->User->save($data); + $this->Session->setFlash(__d('users', 'Your e-mail has been validated!', true)); } - } else { - $this->Session->setFlash(__d('users', 'The url you accessed is not longer valid', true)); - $this->redirect('/'); + $this->redirect(array('action' => 'login')); } + + $this->Session->setFlash(__d('users', 'There was an error verifying your account. Please check the email you were sent, and retry the verification link.', true)); + $this->redirect('/'); } /** @@ -431,10 +474,10 @@ public function verify($type = 'email') { * @return void */ public function change_password() { - if (!empty($this->data)) { - $this->data[$this->modelClass]['id'] = $this->Auth->user('id'); - if ($this->User->changePassword($this->data)) { - $this->Session->setFlash(__d('users', 'Password changed.', true)); + if ($this->request->is('post')) { + $this->request->data[$this->modelClass]['id'] = $this->Auth->user('id'); + if ($this->User->changePassword($this->request->data)) { + $this->Session->setFlash(__d('users', 'Password changed.')); $this->redirect('/'); } } @@ -454,7 +497,7 @@ public function reset_password($token = null, $user = null) { if (empty($token)) { $admin = false; if ($user) { - $this->data = $user; + $this->request->data = $user; $admin = true; } $this->_sendPasswordReset($admin); @@ -470,7 +513,9 @@ public function reset_password($token = null, $user = null) { * @return void */ protected function _setLanguages($viewVar = 'languages') { - App::import('Lib', 'Utils.Languages'); + if (!App::import('Lib', 'Utils.Languages')) { + return false; + } $Languages = new Languages(); $this->set($viewVar, $Languages->lists('locale')); } @@ -489,8 +534,8 @@ protected function _setLanguages($viewVar = 'languages') { protected function _sendVerificationEmail($to = null, $options = array()) { $defaults = array( 'from' => 'noreply@' . env('HTTP_HOST'), - 'subject' => __d('users', 'Account verification', true), - 'template' => 'account_verification'); + 'subject' => __d('users', 'Account verification'), + 'template' => 'Users.account_verification'); $options = array_merge($defaults, $options); @@ -513,13 +558,13 @@ protected function _sendVerificationEmail($to = null, $options = array()) { protected function _sendPasswordReset($admin = null, $options = array()) { $defaults = array( 'from' => 'noreply@' . env('HTTP_HOST'), - 'subject' => __d('users', 'Password Reset', true), - 'template' => 'password_reset_request'); + 'subject' => __d('users', 'Password Reset'), + 'template' => 'Users.password_reset_request'); $options = array_merge($defaults, $options); - if (!empty($this->data)) { - $user = $this->User->passwordReset($this->data); + if (!empty($this->request->data)) { + $user = $this->User->passwordReset($this->request->data); if (!empty($user)) { $this->set('token', $user[$this->modelClass]['password_token']); @@ -531,15 +576,15 @@ protected function _sendPasswordReset($admin = null, $options = array()) { $this->Email->send(); if ($admin) { $this->Session->setFlash(sprintf( - __d('users', '%s has been sent an email with instruction to reset their password.', true), + __d('users', '%s has been sent an email with instruction to reset their password.'), $user[$this->modelClass]['email'])); $this->redirect(array('action' => 'index', 'admin' => true)); } else { - $this->Session->setFlash(__d('users', 'You should receive an email with further instructions shortly', true)); + $this->Session->setFlash(__d('users', 'You should receive an email with further instructions shortly')); $this->redirect(array('action' => 'login')); } } else { - $this->Session->setFlash(__d('users', 'No user was found with that email.', true)); + $this->Session->setFlash(__d('users', 'No user was found with that email.')); $this->redirect($this->referer('/')); } } @@ -550,12 +595,12 @@ protected function _sendPasswordReset($admin = null, $options = array()) { * Sets the cookie to remember the user * * @param array Cookie component properties as array, like array('domain' => 'yourdomain.com') - * @param string Cookie data keyname for the userdata, its default is "User". This is set to User and NOT using the model alias to make sure it works with different apps with different user models accross different (sub)domains. + * @param string Cookie data keyname for the userdata, its default is "User". This is set to User and NOT using the model alias to make sure it works with different apps with different user models across different (sub)domains. * @return void * @link http://api13.cakephp.org/class/cookie-component */ protected function _setCookie($options = array(), $cookieKey = 'User') { - if (empty($this->data[$this->modelClass]['remember_me'])) { + if (empty($this->request->data[$this->modelClass]['remember_me'])) { $this->Cookie->delete($cookieKey); } else { $validProperties = array('domain', 'key', 'name', 'path', 'secure', 'time'); @@ -570,11 +615,11 @@ protected function _setCookie($options = array(), $cookieKey = 'User') { } $cookieData = array(); - $cookieData[$this->Auth->fields['username']] = $this->data[$this->modelClass][$this->Auth->fields['username']]; - $cookieData[$this->Auth->fields['password']] = $this->data[$this->modelClass][$this->Auth->fields['password']]; + $cookieData['username'] = $this->request->data[$this->modelClass]['username']; + $cookieData['password'] = $this->request->data[$this->modelClass]['password']; $this->Cookie->write($cookieKey, $cookieData, true, '1 Month'); } - unset($this->data[$this->modelClass]['remember_me']); + unset($this->request->data[$this->modelClass]['remember_me']); } /** @@ -586,15 +631,13 @@ protected function _setCookie($options = array(), $cookieKey = 'User') { private function __resetPassword($token) { $user = $this->User->checkPasswordToken($token); if (empty($user)) { - $this->Session->setFlash(__d('users', 'Invalid password reset token, try again.', true)); + $this->Session->setFlash(__d('users', 'Invalid password reset token, try again.')); $this->redirect(array('action' => 'reset_password')); } - if (!empty($this->data)) { - if ($this->User->resetPassword(Set::merge($user, $this->data))) { - $this->Session->setFlash(__d('users', 'Password changed, you can now login with your new password.', true)); - $this->redirect($this->Auth->loginAction); - } + if (!empty($this->request->data) && $this->User->resetPassword(Set::merge($user, $this->request->data))) { + $this->Session->setFlash(__d('users', 'Password changed, you can now login with your new password.')); + $this->redirect($this->Auth->loginAction); } $this->set('token', $token); diff --git a/models/user.php b/Model/User.php similarity index 75% rename from models/user.php rename to Model/User.php index a5d612014..f01158841 100644 --- a/models/user.php +++ b/Model/User.php @@ -9,6 +9,9 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::uses('Security', 'Utility'); +App::import('Users.UsersAppModel'); + /** * Users Plugin User Model * @@ -24,23 +27,12 @@ class User extends UsersAppModel { */ public $name = 'User'; -/** - * Behaviors - * - * @var array - */ - public $actsAs = array( - 'Search.Searchable', - 'Utils.Sluggable' => array( - 'label' => 'username', - 'method' => 'multibyteSlug')); - /** * Additional Find methods * * @var array */ - public $_findMethods = array('search' => true); + public $findMethods = array('search' => true); /** * @todo comment me @@ -64,88 +56,119 @@ class User extends UsersAppModel { * @var array */ public $hasMany = array( - 'Detail' => array( - 'className' => 'Users.Detail', + 'UserDetail' => array( + 'className' => 'Users.UserDetail', 'foreign_key' => 'user_id')); /** - * Validation parameters - * - * @var array + * Validation domain for translations */ - public $validate = array(); + public $validationDomain = 'users'; /** - * Constructor + * Validation parameters * - * @param string $id ID - * @param string $table Table - * @param string $ds Datasource + * @var array */ - public function __construct($id = false, $table = null, $ds = null) { - parent::__construct($id, $table, $ds); - $this->validate = array( + public $validate = array( 'username' => array( 'required' => array( 'rule' => array('notEmpty'), 'required' => true, 'allowEmpty' => false, - 'message' => __d('users', 'Please enter a username', true)), + 'message' => 'Please enter a username'), 'alpha' => array( - 'rule'=>array('alphaNumeric'), - 'message' => __d('users', 'The username must be alphanumeric', true)), + 'rule' => array('alphaNumeric'), + 'message' => 'The username must be alphanumeric'), 'unique_username' => array( 'rule'=>array('isUnique','username'), - 'message' => __d('users', 'This username is already in use.', true)), + 'message' => 'This username is already in use.'), 'username_min' => array( 'rule' => array('minLength', '3'), - 'message' => __d('users', 'The username must have at least 3 characters.', true))), + 'message' => 'The username must have at least 3 characters.')), 'email' => array( 'isValid' => array( 'rule' => 'email', 'required' => true, - 'message' => __d('users', 'Please enter a valid email address.', true)), + 'message' => 'Please enter a valid email address.')), 'isUnique' => array( 'rule' => array('isUnique','email'), - 'message' => __d('users', 'This email is already in use.', true))), - 'passwd' => array( + 'message' => 'This email is already in use.'), + 'password' => array( 'to_short' => array( 'rule' => array('minLength', '6'), - 'message' => __d('users', 'The password must have at least 6 characters.', true)), + 'message' => 'The password must have at least 6 characters.'), 'required' => array( 'rule' => 'notEmpty', - 'message' => __d('users', 'Please enter a password.', true))), + 'message' => 'Please enter a password.')), 'temppassword' => array( 'rule' => 'confirmPassword', - 'message' => __d('users', 'The passwords are not equal, please try again.', true)), + 'message' => 'The passwords are not equal, please try again.'), 'tos' => array( 'rule' => array('custom','[1]'), - 'message' => __d('users', 'You must agree to the terms of use.', true))); + 'message' => 'You must agree to the terms of use.')); + +/** + * Constructor + * + * @param string $id ID + * @param string $table Table + * @param string $ds Datasource + */ + public function __construct($id = false, $table = null, $ds = null) { + $this->_setupBehaviors(); + $this->_setupValidation(); + parent::__construct($id, $table, $ds); + } + +/** + * Setup available plugins + * + * This checks for the existence of certain plugins, and if available, uses them. + * + * @return void + */ + protected function _setupBehaviors() { + if (App::import('Behavior', 'Search.Searchable')) { + $this->actsAs[] = 'Search.Searchable'; + } + if (App::import('Behavior', 'Utils.Sluggable')) { + $this->actsAs['Utils.Sluggable'] = array( + 'label' => 'username', + 'method' => 'multibyteSlug'); + } + } +/** + * Setup validation rules + * + * @return void + */ + protected function _setupValidation() { $this->validatePasswordChange = array( - 'new_password' => $this->validate['passwd'], + 'new_password' => $this->validate['password'], 'confirm_password' => array( - 'required' => array('rule' => array('compareFields', 'new_password', 'confirm_password'), 'required' => true, 'message' => __d('users', 'The passwords are not equal.', true))), + 'required' => array('rule' => array('compareFields', 'new_password', 'confirm_password'), 'required' => true, 'message' => __d('users', 'The passwords are not equal.'))), 'old_password' => array( - 'to_short' => array('rule' => 'validateOldPassword', 'required' => true, 'message' => __d('users', 'Invalid password.', true)))); + 'to_short' => array('rule' => 'validateOldPassword', 'required' => true, 'message' => __d('users', 'Invalid password.')))); } /** - * Sets some defaults for the detail model + * Sets some defaults for the UserDetail model * * @return void */ public function setupDetail() { - $this->Detail->sectionSchema[$this->alias] = array( + $this->UserDetail->sectionSchema[$this->alias] = array( 'birthday' => array( 'type' => 'date', 'null' => null, 'default' => null, 'length' => null)); - $this->Detail->sectionValidation[$this->alias] = array( + $this->UserDetail->sectionValidation[$this->alias] = array( 'birthday' => array( 'validDate' => array( - 'rule' => array('date'), 'allowEmpty' => true, 'message' => __d('users', 'Invalid date', true)))); + 'rule' => array('date'), 'allowEmpty' => true, 'message' => __d('users', 'Invalid date')))); } /** @@ -173,8 +196,8 @@ public function afterSave($created) { */ public function afterFind($results, $primary = false) { foreach ($results as &$row) { - if (isset($row['Detail']) && (is_array($row))) { - $row['Detail'] = $this->Detail->getSection($row[$this->alias]['id'], $this->alias); + if (isset($row['UserDetail']) && (is_array($row))) { + $row['UserDetail'] = $this->UserDetail->getSection($row[$this->alias]['id'], $this->alias); } } return $results; @@ -187,9 +210,9 @@ public function afterFind($results, $primary = false) { * @return boolean Success */ public function confirmPassword($password = null) { - if ((isset($this->data[$this->alias]['passwd']) && isset($password['temppassword'])) + if ((isset($this->data[$this->alias]['password']) && isset($password['temppassword'])) && !empty($password['temppassword']) - && ($this->data[$this->alias]['passwd'] === $password['temppassword'])) { + && ($this->data[$this->alias]['password'] === $password['temppassword'])) { return true; } return false; @@ -225,24 +248,26 @@ public function validateToken($token = null, $reset = false, $now = null) { $this->recursive = -1; $data = false; - $match = $this->find(array( - $this->alias . '.email_token' => $token), - 'id, email, email_token_expires'); + $match = $this->find('first', array( + 'conditions' => array($this->alias . '.email_token' => $token), + 'fields' => array('id', 'email', 'email_token_expiry', 'role') + )); - if (!empty($match)){ - $expires = strtotime($match[$this->alias]['email_token_expires']); + if (!empty($match)) { + $expires = strtotime($match[$this->alias]['email_token_expiry']); if ($expires > $now) { $data[$this->alias]['id'] = $match[$this->alias]['id']; $data[$this->alias]['email'] = $match[$this->alias]['email']; - $data[$this->alias]['email_authenticated'] = '1'; - + $data[$this->alias]['email_verified'] = '1'; + $data[$this->alias]['role'] = $match[$this->alias]['role']; + if ($reset === true) { - $data[$this->alias]['passwd'] = $this->generatePassword(); + $data[$this->alias]['password'] = $this->generatePassword(); $data[$this->alias]['password_token'] = null; } $data[$this->alias]['email_token'] = null; - $data[$this->alias]['email_token_expires'] = null; + $data[$this->alias]['email_token_expiry'] = null; } } return $data; @@ -259,7 +284,7 @@ public function updateLastActivity($userId = null) { $this->id = $userId; } if ($this->exists()) { - return $this->saveField('last_activity', date('Y-m-d H:i:s', time())); + return $this->saveField('last_action', date('Y-m-d H:i:s', time())); } return false; } @@ -271,22 +296,22 @@ public function updateLastActivity($userId = null) { * @return mixed False or user data as array on success */ public function passwordReset($postData = array()) { + $this->recursive = -1; $user = $this->find('first', array( 'conditions' => array( $this->alias . '.active' => 1, $this->alias . '.email' => $postData[$this->alias]['email']))); - - if (!empty($user) && $user[$this->alias]['email_authenticated'] == 1) { + if (!empty($user) && $user[$this->alias]['email_verified'] == 1) { $sixtyMins = time() + 43000; $token = $this->generateToken(); $user[$this->alias]['password_token'] = $token; - $user[$this->alias]['email_token_expires'] = date('Y-m-d H:i:s', $sixtyMins); + $user[$this->alias]['email_token_expiry'] = date('Y-m-d H:i:s', $sixtyMins); $user = $this->save($user, false); return $user; - } elseif (!empty($user) && $user[$this->alias]['email_authenticated'] == 0){ - $this->invalidate('email', __d('users', 'This Email Address exists but was never validated.', true)); + } elseif (!empty($user) && $user[$this->alias]['email_verified'] == 0){ + $this->invalidate('email', __d('users', 'This Email Address exists but was never validated.')); } else { - $this->invalidate('email', __d('users', 'This Email Address does not exist in the system.', true)); + $this->invalidate('email', __d('users', 'This Email Address does not exist in the system.')); } return false; } @@ -303,7 +328,7 @@ public function checkPasswordToken($token = null) { 'conditions' => array( $this->alias . '.active' => 1, $this->alias . '.password_token' => $token, - $this->alias . '.email_token_expires >=' => date('Y-m-d H:i:s')))); + $this->alias . '.email_token_expiry >=' => date('Y-m-d H:i:s')))); if (empty($user)) { return false; } @@ -320,16 +345,15 @@ public function resetPassword($postData = array()) { $result = false; $tmp = $this->validate; $this->validate = array( - 'new_password' => $this->validate['passwd'], + 'new_password' => $this->validate['password'], 'confirm_password' => array( 'required' => array( 'rule' => array('compareFields', 'new_password', 'confirm_password'), - 'message' => __d('users', 'The passwords are not equal.', true)))); + 'message' => __d('users', 'The passwords are not equal.')))); $this->set($postData); if ($this->validates()) { - App::import('Core', 'Security'); - $this->data[$this->alias]['passwd'] = Security::hash($this->data[$this->alias]['new_password'], null, true); + $this->data[$this->alias]['password'] = Security::hash($this->data[$this->alias]['new_password'], null, true); $this->data[$this->alias]['password_token'] = null; $result = $this->save($this->data, false); } @@ -349,8 +373,7 @@ public function changePassword($postData = array()) { $this->validate = $this->validatePasswordChange; if ($this->validates()) { - App::import('Core', 'Security'); - $this->data[$this->alias]['passwd'] = Security::hash($this->data[$this->alias]['new_password'], null, true); + $this->data[$this->alias]['password'] = Security::hash($this->data[$this->alias]['new_password'], null, true); $this->save($postData, array( 'validate' => false, 'callbacks' => false)); @@ -371,16 +394,12 @@ public function changePassword($postData = array()) { public function validateOldPassword($password) { if (!isset($this->data[$this->alias]['id']) || empty($this->data[$this->alias]['id'])) { if (Configure::read('debug') > 0) { - throw new OutOfBoundsException(__d('users', '$this->data[\'' . $this->alias . '\'][\'id\'] has to be set and not empty', true)); + throw new OutOfBoundsException(__d('users', '$this->data[\'' . $this->alias . '\'][\'id\'] has to be set and not empty')); } } - $passwd = $this->field('passwd', array($this->alias . '.id' => $this->data[$this->alias]['id'])); - App::import('Core', 'Security'); - if ($passwd === Security::hash($password['old_password'], null, true)) { - return true; - } - return false; + $current_password = $this->field('password', array($this->alias . '.id' => $this->data[$this->alias]['id'])); + return $current_password === Security::hash($password['old_password'], null, true); } /** @@ -410,18 +429,17 @@ public function compareFields($field1, $field2) { public function view($slug = null) { $user = $this->find('first', array( 'contain' => array( - //'Tag', - 'Detail'), + 'UserDetail'), 'conditions' => array( $this->alias . '.slug' => $slug, 'OR' => array( 'AND' => - array($this->alias . '.active' => 1, $this->alias . '.email_authenticated' => 1), + array($this->alias . '.active' => 1, $this->alias . '.email_verified' => 1), //array($this->alias . '.active' => 1, $this->alias . '.account_type' => 'remote') )))); if (empty($user)) { - throw new Exception(__d('users', 'The user does not exist.', true)); + throw new Exception(__d('users', 'The user does not exist.')); } return $user; @@ -441,8 +459,7 @@ public function register($postData = array(), $useEmailVerification = true) { $this->set($postData); if ($this->validates()) { - App::import('Core', 'Security'); - $postData[$this->alias]['passwd'] = Security::hash($postData[$this->alias]['passwd'], 'sha1', true); + $postData[$this->alias]['password'] = Security::hash($postData[$this->alias]['password'], 'sha1', true); $this->create(); return $this->save($postData, false); } @@ -458,7 +475,7 @@ public function register($postData = array(), $useEmailVerification = true) { */ public function resendVerification($postData = array()) { if (!isset($postData[$this->alias]['email']) || empty($postData[$this->alias]['email'])) { - $this->invalidate('email', __d('users', 'Please enter your email address.', true)); + $this->invalidate('email', __d('users', 'Please enter your email address.')); return false; } @@ -468,22 +485,22 @@ public function resendVerification($postData = array()) { $this->alias . '.email' => $postData[$this->alias]['email']))); if (empty($user)) { - $this->invalidate('email', __d('users', 'The email address does not exist in the system', true)); + $this->invalidate('email', __d('users', 'The email address does not exist in the system')); return false; } - if ($user[$this->alias]['email_authenticated'] == 1) { - $this->invalidate('email', __d('users', 'Your account is already authenticaed.', true)); + if ($user[$this->alias]['email_verified'] == 1) { + $this->invalidate('email', __d('users', 'Your account is already authenticaed.')); return false; } if ($user[$this->alias]['active'] == 0) { - $this->invalidate('email', __d('users', 'Your account is disabled.', true)); + $this->invalidate('email', __d('users', 'Your account is disabled.')); return false; } $user[$this->alias]['email_token'] = $this->generateToken(); - $user[$this->alias]['email_token_expires'] = date('Y-m-d H:i:s', time() + 86400); + $user[$this->alias]['email_token_expiry'] = date('Y-m-d H:i:s', time() + 86400); return $this->save($user, false); } @@ -537,9 +554,9 @@ public function generateToken($length = 10) { protected function _beforeRegistration($postData = array(), $useEmailVerification = true) { if ($useEmailVerification == true) { $postData[$this->alias]['email_token'] = $this->generateToken(); - $postData[$this->alias]['email_token_expires'] = date('Y-m-d H:i:s', time() + 86400); + $postData[$this->alias]['email_token_expiry'] = date('Y-m-d H:i:s', time() + 86400); } else { - $postData[$this->alias]['email_authenticated'] = 1; + $postData[$this->alias]['email_verified'] = 1; } $postData[$this->alias]['active'] = 1; return $postData; @@ -641,15 +658,19 @@ function paginateCount($conditions = array(), $recursive = 0, $extra = array()) * Adds a new user * * @param array post data, should be Controller->data - * @return array + * @return boolean True if the data was saved successfully. */ public function add($postData = null) { if (!empty($postData)) { $this->create(); - if ($this->save($postData)) { + $result = $this->save($postData); + if ($result) { + $result[$this->alias][$this->primaryKey] = $this->id; + $this->data = $result; return true; } } + return false; } /** @@ -661,14 +682,13 @@ public function add($postData = null) { */ public function edit($userId = null, $postData = null) { $user = $this->find('first', array( - 'contain' => array( - 'Detail'), - 'conditions' => array( - $this->alias . '.id' => $userId))); + 'contain' => array('UserDetail'), + 'conditions' => array($this->alias . '.id' => $userId) + )); $this->set($user); if (empty($user)) { - throw new OutOfBoundsException(__d('users', 'Invalid User', true)); + throw new OutOfBoundsException(__d('users', 'Invalid User')); } if (!empty($postData)) { @@ -692,7 +712,7 @@ public function edit($userId = null, $postData = null) { */ protected function _removeExpiredRegistrations() { $this->deleteAll(array( - $this->alias . '.email_authenticated' => 0, - $this->alias . '.email_token_expires <' => date('Y-m-d H:i:s'))); + $this->alias . '.email_verified' => 0, + $this->alias . '.email_token_expiry <' => date('Y-m-d H:i:s'))); } } diff --git a/models/detail.php b/Model/UserDetail.php similarity index 97% rename from models/detail.php rename to Model/UserDetail.php index d0a3273cf..ad18e34c5 100644 --- a/models/detail.php +++ b/Model/UserDetail.php @@ -15,14 +15,14 @@ * @package users * @subpackage users.models */ -class Detail extends UsersAppModel { +class UserDetail extends UsersAppModel { /** * Name * * @var string */ - public $name = 'Detail'; + public $name = 'UserDetail'; /** * Displayfield @@ -212,7 +212,7 @@ public function saveSection($userId = null, $data = null, $section = null) { $this->create(); $newDetail[$model]['user_id'] = $userId; } else { - $newDetail[$model]['id'] = $detail['Detail']['id']; + $newDetail[$model]['id'] = $detail[$this->alias]['id']; } $newDetail[$model]['field'] = $field; diff --git a/users_app_model.php b/Model/UsersAppModel.php similarity index 92% rename from users_app_model.php rename to Model/UsersAppModel.php index 7da1756a1..b77d21945 100644 --- a/users_app_model.php +++ b/Model/UsersAppModel.php @@ -9,6 +9,8 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::uses('Model', 'Model'); + /** * Users App Model * @@ -47,9 +49,7 @@ function paginateCount($conditions = array(), $recursive = 0, $extra = array()) if (isset($extra['type']) && isset($this->_findMethods[$extra['type']])) { $extra['operation'] = 'count'; return $this->find($extra['type'], array_merge($parameters, $extra)); - } else { - return $this->find('count', array_merge($parameters, $extra)); } + return $this->find('count', array_merge($parameters, $extra)); } - } diff --git a/tests/cases/controllers/details_controller.test.php b/Test/Case/Controller/UserDetailsControllerTest.php similarity index 73% rename from tests/cases/controllers/details_controller.test.php rename to Test/Case/Controller/UserDetailsControllerTest.php index 239f3fb08..6acb90c28 100644 --- a/tests/cases/controllers/details_controller.test.php +++ b/Test/Case/Controller/UserDetailsControllerTest.php @@ -9,7 +9,7 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::import('Controller', 'Users.Details'); +App::import('Controller', 'Users.UserDetails'); /** * TestDetails @@ -17,7 +17,7 @@ * @package users * @subpackage users.tests.controllers */ -class TestDetails extends DetailsController { +class TestUserDetails extends UserDetailsController { var $autoRender = false; } @@ -27,16 +27,16 @@ class TestDetails extends DetailsController { * @package users * @author users.tests.controllers */ -class DetailsControllerTest extends CakeTestCase { +class UserDetailsControllerTest extends CakeTestCase { var $Details = null; function setUp() { Configure::write('App.UserClass', null); - $this->Details = new TestDetails(); + $this->Details = new TestUserDetails(); } function testDetailsControllerInstance() { - $this->assertTrue(is_a($this->Details, 'DetailsController')); + $this->assertTrue(is_a($this->Details, 'UserDetailsController')); } function tearDown() { diff --git a/tests/cases/controllers/users_controller.test.php b/Test/Case/Controller/UsersControllerTest.php similarity index 74% rename from tests/cases/controllers/users_controller.test.php rename to Test/Case/Controller/UsersControllerTest.php index a6fe795f2..51482d593 100644 --- a/tests/cases/controllers/users_controller.test.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -9,9 +9,12 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::import('Controller', 'Users.Users'); -App::import('Model', 'Users.User'); -App::import('Component', array('Auth', 'Cookie', 'Session')); +App::uses('UsersController', 'Users.Controller'); +App::uses('User', 'Users.User'); +App::uses('AuthComponent', 'Controller/Component'); +App::uses('CookieComponent', 'Controller/Component'); +App::uses('SessionComponent', 'Controller/Component'); +App::uses('Security', 'Utility'); /** * TestUsersController @@ -40,13 +43,12 @@ class TestUsersController extends UsersController { */ public function beforeFilter() { parent::beforeFilter(); - $this->Auth->authorize = 'controller'; - $this->Auth->fields = array('username' => 'email', 'password' => 'passwd'); + $this->Auth->authorize = array('Controller'); + $this->Auth->fields = array('username' => 'email', 'password' => 'password'); $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'prefix' => 'admin', 'admin' => false, 'plugin' => 'users'); $this->Auth->loginRedirect = $this->Session->read('Auth.redirect'); $this->Auth->logoutRedirect = '/'; $this->Auth->authError = __d('users', 'Sorry, but you need to login to access this location.', true); - $this->Auth->loginError = __d('users', 'Invalid e-mail / password combination. Please try again', true); $this->Auth->autoRedirect = true; $this->Auth->userModel = 'User'; $this->Auth->userScope = array( @@ -107,8 +109,7 @@ class UsersControllerTestCase extends CakeTestCase { */ public $fixtures = array( 'plugin.users.user', - 'plugin.users.detail', - 'plugin.users.identity'); + 'plugin.users.user_detail'); /** * Sampletdata used for post data @@ -116,9 +117,20 @@ class UsersControllerTestCase extends CakeTestCase { * @var array */ public $usersData = array( - 'admin' => array('email' => 'larry.masters@cakedc.com', 'username' => 'phpnut', 'passwd' => 'test'), - 'validUser' => array('email' => 'florian.kraemer@cakedc.com', 'username' => 'floriank', 'passwd' => 'secretkey', 'redirect' => '/user/burzum'), - 'invalidUser' => array('email' => 'wronguser@wronguser.com', 'username' => 'invalidUser', 'passwd' => 'invalid-password!')); + 'admin' => array( + 'email' => 'adminuser@cakedc.com', + 'username' => 'adminuser', + 'password' => 'test'), + 'validUser' => array( + 'email' => 'testuser@cakedc.com', + 'username' => 'testuser', + 'password' => 'secretkey', + 'redirect' => '/user/slugname'), + 'invalidUser' => array( + 'email' => 'wronguser@wronguser.com', + 'username' => 'invalidUser', + 'password' => 'invalid-password!'), + ); /** * Start test @@ -127,18 +139,20 @@ class UsersControllerTestCase extends CakeTestCase { */ public function startTest() { Configure::write('App.UserClass', null); - $this->Users = new TestUsersController(); + + $request = new CakeRequest(); + $response = $this->getMock('CakeResponse'); + $this->Users = new TestUsersController($request, $response); + $this->Users->constructClasses(); - $this->Users->Component->init($this->Users); - $this->Users->Component->initialize($this->Users); - $this->Users->params = array( + $this->Users->request->params = array( 'pass' => array(), 'named' => array(), 'controller' => 'users', 'admin' => false, 'plugin' => 'users', 'url' => array()); - $this->Users->Email->delivery = 'debug'; + $this->Users->Email->delivery = 'Debug'; } /** @@ -147,7 +161,7 @@ public function startTest() { * @return void */ public function testUsersControllerInstance() { - $this->assertTrue(is_a($this->Users, 'UsersController')); + $this->assertInstanceOf('UsersController', $this->Users); } /** @@ -156,36 +170,34 @@ public function testUsersControllerInstance() { * @return void */ public function testUserLogin() { - $this->Users->params['action'] = 'login'; - $this->Users->Component->startup($this->Users); - - $this->Users->User->save(array( - 'User' => array( - 'id' => '1', - 'username' => 'testuser', - 'slug' => 'testuser', - 'passwd' => Security::hash('test', null, true), - )), false); + $this->Users->request->params['action'] = 'login'; + $this->Users->startupProcess(); $this->__setPost(array('User' => $this->usersData['admin'])); - $this->Users->beforeFilter(); - $this->Users->params = array( - 'controller' => 'users', - 'action' => 'login', - 'admin' => false, - 'plugin' => 'users', - 'url' => array( - 'url' => '/users/users/login')); + $this->Users->request->url = '/users/users/login'; + $this->Users->startupProcess(); - $this->Users->Component->startup($this->Users); $this->Users->login(); - $this->assertEqual($this->Users->Session->read('Message.flash.message'), __d('users', 'testuser you have successfully logged in', true)); + $result = $this->Users->Session->read('Message.flash.message'); + $expected = __d('users', 'adminuser you have successfully logged in', true); + $this->assertEqual($result, $expected); + $this->assertEqual(Router::normalize($this->Users->redirectUrl), Router::normalize(Router::url($this->Users->Auth->loginRedirect))); + } +/** + * testFailedUserLogin + * + * @return void + */ + public function testFailedUserLogin() { + $this->Users->request->params['action'] = 'login'; $this->__setPost(array('User' => $this->usersData['invalidUser'])); - $this->Users->beforeFilter(); + $this->Users->startupProcess(); $this->Users->login(); - $this->assertEqual($this->Users->Session->read('Message.auth.message'), __d('users', 'Invalid e-mail / password combination. Please try again', true)); + $result = $this->Users->Session->read('Message.auth.message'); + $expected = __d('users', 'Invalid e-mail / password combination. Please try again', true); + $this->assertEqual($result, $expected); } /** @@ -193,28 +205,27 @@ public function testUserLogin() { * */ public function testRegister() { - $this->Users->params['action'] = 'register'; - - $this->__setPost(array( + $_SERVER['HTTP_HOST'] = 'test.com'; + $this->Users->params['action'] = 'add'; + $this->__setPost(array( 'User' => array( 'username' => 'newUser', 'email' => 'newUser@newemail.com', - 'passwd' => 'password', + 'password' => 'password', 'temppassword' => 'password', 'tos' => 1))); $this->Users->beforeFilter(); - $this->Users->register(); + $this->Users->add(); $this->assertEqual($this->Users->Session->read('Message.flash.message'), __d('users', 'Your account has been created. You should receive an e-mail shortly to authenticate your account. Once validated you will be able to login.', true)); - - $this->__setPost(array( + $this->__setPost(array( 'User' => array( 'username' => 'newUser', 'email' => '', - 'passwd' => '', + 'password' => '', 'temppassword' => '', 'tos' => 0))); $this->Users->beforeFilter(); - $this->Users->register(); + $this->Users->add(); $this->assertEqual($this->Users->Session->read('Message.flash.message'), __d('users', 'Your account could not be created. Please, try again.', true)); } @@ -245,7 +256,7 @@ public function testLogout() { $this->Users->beforeFilter(); $this->Users->Session->write('Auth.User', $this->usersData['validUser']); $this->Users->logout(); - $this->assertEqual($this->Users->Session->read('Message.flash.message'), __d('users', 'floriank you have successfully logged out', true)); + $this->assertEqual($this->Users->Session->read('Message.flash.message'), __d('users', 'testuser you have successfully logged out', true)); $this->assertEqual($this->Users->redirectUrl, '/'); } @@ -255,8 +266,8 @@ public function testLogout() { * @return void */ public function testIndex() { - $this->Users->params = array( - 'url' => array()); + //$this->Users->params = array( + // 'url' => array()); $this->Users->passedArgs = array(); $this->Users->index(); $this->assertTrue(isset($this->Users->viewVars['users'])); @@ -268,7 +279,7 @@ public function testIndex() { * @return void */ public function testView() { - $this->Users->view('phpnut'); + $this->Users->view('adminuser'); $this->assertTrue(isset($this->Users->viewVars['user'])); $this->Users->view('INVALID-SLUG'); @@ -280,15 +291,15 @@ public function testView() { * * @return void */ - public function testSearch() { - $this->Users->params = array( - 'url' => array(), - 'named' => array( - 'search' => 'phpnut')); - $this->Users->passedArgs = array(); - $this->Users->search(); - $this->assertTrue(isset($this->Users->viewVars['users'])); - } + // public function testSearch() { + // $this->Users->params = array( + // 'url' => array(), + // 'named' => array( + // 'search' => 'phpnut')); + // $this->Users->passedArgs = array(); + // $this->Users->search(); + // $this->assertTrue(isset($this->Users->viewVars['users'])); + // } /** * change_password @@ -297,11 +308,11 @@ public function testSearch() { */ public function testChangePassword() { $this->Users->Session->write('Auth.User.id', '1'); - $this->Users->data = array( - 'User' => array( + $this->__setPost(array( + 'User' => array( 'new_password' => 'newpassword', 'confirm_password' => 'newpassword', - 'old_password' => 'test')); + 'old_password' => 'test'))); $this->Users->change_password(); $this->assertEqual($this->Users->redirectUrl, '/'); } @@ -323,11 +334,12 @@ public function testEdit() { * @return void */ public function testResetPassword() { + $_SERVER['HTTP_HOST'] = 'test.com'; $this->Users->User->id = '1'; $this->Users->User->saveField('email_token_expires', date('Y-m-d H:i:s', strtotime('+1 year'))); $this->Users->data = array( 'User' => array( - 'email' => 'larry.masters@cakedc.com')); + 'email' => 'adminuser@cakedc.com')); $this->Users->reset_password(); $this->assertEqual($this->Users->redirectUrl, array('action' => 'login')); @@ -349,7 +361,7 @@ public function testAdminIndex() { $this->Users->params = array( 'url' => array(), 'named' => array( - 'search' => 'phpnut')); + 'search' => 'adminuser')); $this->Users->passedArgs = array(); $this->Users->admin_index(); $this->assertTrue(isset($this->Users->viewVars['users'])); @@ -386,7 +398,7 @@ public function testAdminDelete() { * */ public function testSetCookie() { - $this->Users->data['User'] = array( + $this->Users->request->data['User'] = array( 'remember_me' => 1, 'username' => 'test', 'password' => 'testtest'); @@ -405,7 +417,7 @@ public function testSetCookie() { */ private function __setPost($data = array()) { $_SERVER['REQUEST_METHOD'] = 'POST'; - $this->Users->data = am($data, array('_method' => 'POST')); + $this->Users->request->data = array_merge($data, array('_method' => 'POST')); } /** diff --git a/tests/cases/models/detail.test.php b/Test/Case/Model/UserDetailTest.php similarity index 89% rename from tests/cases/models/detail.test.php rename to Test/Case/Model/UserDetailTest.php index f477d6c70..26041a835 100644 --- a/tests/cases/models/detail.test.php +++ b/Test/Case/Model/UserDetailTest.php @@ -15,7 +15,7 @@ * @package users * @subpackage users.tests.cases.models */ -class DetailTestCase extends CakeTestCase { +class UserDetailTestCase extends CakeTestCase { /** * Detail instance @@ -31,18 +31,16 @@ class DetailTestCase extends CakeTestCase { */ public $fixtures = array( 'plugin.users.user', - 'plugin.users.detail', - 'plugin.users.identity'); + 'plugin.users.user_detail'); /** * start * * @return void */ - public function start() { + public function startTest() { Configure::write('App.UserClass', null); - parent::start(); - $this->Detail =& ClassRegistry::init('Users.Detail'); + $this->Detail = ClassRegistry::init('Users.UserDetail'); } /** @@ -51,7 +49,7 @@ public function start() { * @return void */ public function testDetailInstance() { - $this->assertTrue(is_a($this->Detail, 'Detail')); + $this->assertTrue(is_a($this->Detail, 'UserDetail')); } /** @@ -109,7 +107,7 @@ public function testGetSection() { */ public function testSaveSection() { $data = array( - 'Detail' => array( + 'UserDetail' => array( 'biography' => 'Lipsum...', 'firstname' => 'Florian', 'lastname' => 'Krämer')); @@ -123,7 +121,7 @@ public function testSaveSection() { $data = array( - 'Detail' => array( + 'UserDetail' => array( 'biography' => 'Lipsum...', 'firstname' => 'Foo', 'lastname' => 'Bar')); @@ -137,9 +135,10 @@ public function testSaveSection() { $data = array( - 'User' => array( + 'UserDetail' => array( 'email' => 'foo@bar.com')); $this->Detail->saveSection('47ea303a-3cyc-k251-b313-4811c0a800bf', $data, 'User'); + $result = $this->Detail->getSection('47ea303a-3cyc-k251-b313-4811c0a800bf', 'User'); $this->Detail->User->id = '47ea303a-3cyc-k251-b313-4811c0a800bf'; $result = $this->Detail->User->field('User.email'); $this->assertEqual($result, 'foo@bar.com'); diff --git a/tests/cases/models/user.test.php b/Test/Case/Model/UserTest.php similarity index 75% rename from tests/cases/models/user.test.php rename to Test/Case/Model/UserTest.php index c19c01846..0ce8759ba 100644 --- a/tests/cases/models/user.test.php +++ b/Test/Case/Model/UserTest.php @@ -25,9 +25,11 @@ class UserTestCase extends CakeTestCase { public $User = null; /** - * + * Plugin name + * + * @var string */ - public $plugin = 'users'; + public $plugin = 'Users'; /** * Fixtures @@ -36,25 +38,25 @@ class UserTestCase extends CakeTestCase { */ public $fixtures = array( 'plugin.users.user', - 'plugin.users.detail', - 'plugin.users.identity'); + 'plugin.users.user_detail'); /** - * + * startTest * * @return void */ - public function startTest() { + public function setUp() { Configure::write('App.UserClass', null); $this->User = ClassRegistry::init('Users.User'); } /** - * + * endTest * * @return void */ - public function endTest() { + public function tearDown() { + parent::tearDown(); unset($this->User); ClassRegistry::flush(); } @@ -64,20 +66,20 @@ public function endTest() { * @return void */ public function testUserInstance() { - $this->assertTrue(is_a($this->User, 'User')); + $this->assertType('User', $this->User); } /** - * Test to compare the passwords when a user registers + * Test to compare the passwords when a user adds * * @return void */ public function testConfirmPassword() { - $this->User->data['User']['passwd'] = 'password'; + $this->User->data['User']['password'] = 'password'; $result = $this->User->confirmPassword(array('temppassword' => 'password')); $this->assertTrue($result); - $this->User->data['User']['passwd'] = 'different_password'; + $this->User->data['User']['password'] = 'different_password'; $result = $this->User->confirmPassword(array('temppassword' => 'password')); $this->assertFalse($result); } @@ -104,11 +106,11 @@ public function testConfirmEmail() { */ function testGenerateToken() { $result = $this->User->generateToken(); - $this->assertIsA($result, 'string'); + $this->assertInternalType('string', $result); } /** - * + * testValidateToken * * @return void */ @@ -118,7 +120,7 @@ function testValidateToken() { $now = strtotime('2008-03-25 02:48:46'); $result = $this->User->validateToken('testtoken2', false, $now); - $this->assertIsA($result, 'array'); + $this->assertInternalType('array', $result); $now = strtotime('2008-03-29 02:48:46'); $result = $this->User->validateToken('testtoken2', false, $now); @@ -126,22 +128,24 @@ function testValidateToken() { } /** - * + * testUpdateLastActivity * * @return void */ public function testUpdateLastActivity() { - $id = '1'; + $id = 1; $this->User->id = $id; - $lastDate = $this->User->field('last_activity'); - $this->User->updateLastActivity($id); - $newDate = $this->User->field('last_activity'); + $lastDate = $this->User->field('last_action'); + $result = $this->User->updateLastActivity($id); + $this->assertTrue(is_array($result)); + $this->User->id = $id; + $newDate = $result['User']['last_action']; $this->assertTrue($lastDate < $newDate); $this->assertFalse($this->User->updateLastActivity('invalid-id!')); } /** - * + * testResetPassword * * @return void */ @@ -153,7 +157,6 @@ public function testResetPassword() { 'confirm_password' => 'dsgdsgsdg')); $this->assertFalse($this->User->resetPassword($data)); - $data = array( 'User' => array( 'id' => 1, @@ -161,29 +164,28 @@ public function testResetPassword() { 'confirm_password' => '')); $this->assertFalse($this->User->resetPassword($data)); - $data = array( 'User' => array( 'id' => 1, 'new_password' => 'newpassword', 'confirm_password' => 'newpassword')); - $this->assertTrue($this->User->resetPassword($data)); + $this->assertInternalType('array', $this->User->resetPassword($data)); } /** - * + * testCheckPasswordToken * * @return void */ public function testCheckPasswordToken() { $this->User->id = '1'; - $this->User->saveField('email_token_expires', date('Y-m-d H:i:s', strtotime('+1 year'))); - $this->assertTrue($this->User->checkPasswordToken('testtoken')); + $this->User->saveField('email_token_expiry', date('Y-m-d H:i:s', strtotime('+1 year'))); + $this->assertInternalType('array', $this->User->checkPasswordToken('testtoken')); $this->assertFalse($this->User->checkPasswordToken('something-wrong-here')); } /** - * + * testPasswordReset * * @return void */ @@ -194,41 +196,43 @@ public function testPasswordReset() { 'email' => 'somethingwrong in here!')); $this->assertFalse($this->User->passwordReset($data)); - $this->User->id = '1'; - $this->User->saveField('email_token_expires', date('Y-m-d H:i:s', strtotime('+1 year'))); + $this->User->saveField('email_token_expiry', date('Y-m-d H:i:s', strtotime('+1 year'))); $data = array( 'User' => array( 'id' => 1, - 'email' => 'larry.masters@cakedc.com')); - $this->assertTrue($this->User->passwordReset($data)); + 'email' => 'adminuser@cakedc.com')); + $this->assertInternalType('array', $this->User->passwordReset($data)); } /** - * + * testValidateOldPassword * * @return void */ public function testValidateOldPassword() { - App::import('Core', 'Security'); $password = Security::hash('password', null, true); $this->User->id = '1'; - $this->User->saveField('passwd', $password); + $this->User->saveField('password', $password); $this->User->data = array( 'User' => array( 'id' => '1', - 'passwd')); - $this->assertTrue($this->User->validateOldPassword(array('old_password' => 'password'))); - $this->assertFalse($this->User->validateOldPassword(array('old_password' => 'FAIL!'))); + 'password')); + + $result = $this->User->validateOldPassword(array('old_password' => 'password')); + $this->assertTrue($result); + + $result = $this->User->validateOldPassword(array('old_password' => 'FAIL!')); + $this->assertFalse($result); } /** - * + * testView * * @return void */ public function testView() { - $result = $this->User->view('phpnut'); + $result = $this->User->view('adminuser'); $this->assertTrue(is_array($result) && !empty($result)); $this->expectException('Exception'); @@ -241,47 +245,44 @@ public function testView() { * @return void */ public function testRegister() { - App::import('Core', 'Security'); $postData = array(); - $result = $this->User->register($postData); + $result = $this->User->add($postData); $this->assertFalse($result); - $postData = array('User' => array( 'username' => '#236236326sdg!!!.s#invalid', 'email' => 'invalid', - 'passwd' => 'password', + 'password' => 'password', 'temppassword' => 'wrong', 'tos' => 0)); - $result = $this->User->register($postData); + $result = $this->User->add($postData); $this->assertFalse($result); $this->assertEqual(array_keys($this->User->invalidFields()), array( 'username', 'email', 'temppassword', 'tos')); - $postData = array('User' => array( 'username' => 'validusername', 'email' => 'test@test.com', - 'passwd' => '12345', + 'password' => '12345', 'temppassword' => '12345', 'tos' => 1)); - $result = $this->User->register($postData); + $result = $this->User->add($postData); $this->assertFalse($result); $this->assertEqual(array_keys($this->User->invalidFields()), array( - 'passwd')); - + 'password')); $postData = array('User' => array( 'username' => 'imanewuser', 'email' => 'foo@bar.com', - 'passwd' => 'password', + 'password' => 'password', 'temppassword' => 'password', 'tos' => 1)); - $result = $this->User->register($postData); - $this->assertTrue(is_array($result)); - $this->assertEqual($result['User']['active'], 1); - $this->assertEqual($result['User']['slug'], 'imanewuser'); - $this->assertEqual($result['User']['passwd'], Security::hash('password', 'sha1', true)); + $result = $this->User->add($postData); + $this->assertTrue($result); + $result = $this->User->data; + + $this->assertEqual($result['User']['active'], 0); + $this->assertEqual($result['User']['password'], Security::hash('password', 'sha1', true)); $this->assertTrue(is_string($result['User']['email_token'])); $result = $this->User->findById($this->User->id); @@ -298,7 +299,6 @@ public function testChangePassword() { $result = $this->User->changePassword($postData); $this->assertFalse($result); - $postData = array( 'User' => array( 'id' => 1, @@ -310,7 +310,6 @@ public function testChangePassword() { $this->assertFalse($result); $this->assertEqual(array('new_password', 'confirm_password'), array_keys($this->User->invalidFields())); - $postData = array( 'User' => array( 'id' => 1, @@ -323,7 +322,7 @@ public function testChangePassword() { 'recursive' => -1, 'conditions' => array( 'User.id' => 1))); - $this->assertEqual($ressult['User']['passwd'], Security::hash('testtest', null, true)); + $this->assertEqual($ressult['User']['password'], Security::hash('testtest', null, true)); } /** @@ -338,7 +337,6 @@ public function testCompareFields() { 'field2' => 'bar')); $this->assertFalse($this->User->compareFields('field1', 'field2')); - $this->User->data = array( 'User' => array( 'field1' => 'foo', @@ -356,19 +354,16 @@ public function testResendVerification() { 'User' => array()); $this->assertFalse($this->User->resendVerification($postData)); - $postData = array( 'User' => array( 'email' => 'doesnotexist!')); $this->assertFalse($this->User->resendVerification($postData)); - $postData = array( 'User' => array( - 'email' => 'larry.masters@cakedc.com')); + 'email' => 'adminuser@cakedc.com')); $this->assertFalse($this->User->resendVerification($postData)); - $postData = array( 'User' => array( 'email' => 'oidtest2@testuser.com')); @@ -383,12 +378,11 @@ public function testResendVerification() { */ public function testGeneratePassword() { $result = $this->User->generatePassword(); - $this->assertIsA($result, 'string'); + $this->assertInternalType('string', $result); $this->assertEqual(strlen($result), 10); - $result = $this->User->generatePassword(15); - $this->assertIsA($result, 'string'); + $this->assertInternalType('string', $result); $this->assertEqual(strlen($result), 15); } @@ -404,17 +398,6 @@ public function testDelete() { $this->assertFalse($this->User->exists()); } -/** - * testFindSearch - * - * @return void - */ - public function testFindSearch() { - $result = $this->User->find('search', array('by' => 'username', 'search' => 'php')); - $this->assertTrue(!empty($result)); - $this->assertEqual($result[0]['User']['username'], 'phpnut'); - } - /** * testAdd * @@ -425,7 +408,7 @@ public function testAdd() { 'User' => array( 'username' => 'newusername', 'email' => 'newusername@newusername.com', - 'passwd' => 'password', + 'password' => 'password', 'temppassword' => 'password', 'tos' => 1)); $result = $this->User->add($postData); @@ -448,12 +431,18 @@ public function testEdit() { $result = $this->User->read(null, 1); $this->assertEqual($result['User']['username'], $data['User']['username']); $this->assertEqual($result['User']['email'], $data['User']['email']); - - try { - $this->User->edit('bogus id', $userId, $data); - $this->fail('No exception'); - } catch (OutOfBoundsException $e) { - $this->pass('Correct exception thrown'); - } + } + +/** + * testEditException + * + * @return void + */ + public function testEditException() { + $this->setExpectedException('OutOfBoundsException'); + $userId = '1'; + $data = $this->User->read(null, $userId); + $data['User']['email'] = 'anotherNewEmail@anothernewemail.com'; + $this->User->edit('bogus id', $userId, $data); } } diff --git a/tests/fixtures/detail_fixture.php b/Test/Fixture/UserDetailFixture.php similarity index 95% rename from tests/fixtures/detail_fixture.php rename to Test/Fixture/UserDetailFixture.php index 3067c3039..66e9ee4c4 100644 --- a/tests/fixtures/detail_fixture.php +++ b/Test/Fixture/UserDetailFixture.php @@ -15,21 +15,21 @@ * @package users * @subpackage users.test.fixtures */ -class DetailFixture extends CakeTestFixture { +class UserDetailFixture extends CakeTestFixture { /** * Name * * @var string $name */ - public $name = 'Detail'; + public $name = 'UserDetail'; /** * Table * * @var array $table */ - public $table = 'details'; + public $table = 'user_details'; /** * Fields diff --git a/tests/fixtures/user_fixture.php b/Test/Fixture/UserFixture.php similarity index 72% rename from tests/fixtures/user_fixture.php rename to Test/Fixture/UserFixture.php index edbb70ddf..3e78f5373 100644 --- a/tests/fixtures/user_fixture.php +++ b/Test/Fixture/UserFixture.php @@ -9,6 +9,8 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::uses('Security', 'Utility'); + /** * UserFixture * @@ -40,15 +42,15 @@ class UserFixture extends CakeTestFixture { 'id' => array('type'=>'string', 'null' => false, 'length' => 36, 'key' => 'primary'), 'username' => array('type'=>'string', 'null' => false, 'default' => NULL), 'slug' => array('type'=>'string', 'null' => false, 'default' => NULL), - 'passwd' => array('type'=>'string', 'null' => true, 'default' => NULL, 'length' => 128), + 'password' => array('type'=>'string', 'null' => true, 'default' => NULL, 'length' => 128), 'password_token' => array('type'=>'string', 'null' => true, 'default' => NULL, 'length' => 128), 'email' => array('type'=>'string', 'null' => true, 'default' => NULL), - 'email_authenticated' => array('type'=>'boolean', 'null' => true, 'default' => '0'), + 'email_verified' => array('type'=>'boolean', 'null' => true, 'default' => '0'), 'email_token' => array('type'=>'string', 'null' => true, 'default' => NULL), - 'email_token_expires' => array('type'=>'datetime', 'null' => true, 'default' => NULL), + 'email_token_expiry' => array('type'=>'datetime', 'null' => true, 'default' => NULL), 'tos' => array('type'=>'boolean', 'null' => true, 'default' => '0'), 'active' => array('type'=>'boolean', 'null' => true, 'default' => '0'), - 'last_activity' => array('type'=>'datetime', 'null' => true, 'default' => NULL), + 'last_action' => array('type'=>'datetime', 'null' => true, 'default' => NULL), 'last_login' => array('type'=>'datetime', 'null' => true, 'default' => NULL), 'is_admin' => array('type'=>'boolean', 'null' => true, 'default' => '0'), 'role' => array('type'=>'string', 'null' => true, 'default' => NULL), @@ -66,17 +68,17 @@ class UserFixture extends CakeTestFixture { public $records = array( array( 'id' => '1', - 'username' => 'phpnut', - 'slug' => 'phpnut', - 'passwd' => 'test', // test + 'username' => 'adminuser', + 'slug' => 'adminuser', + 'password' => 'test', // test 'password_token' => 'testtoken', - 'email' => 'larry.masters@cakedc.com', - 'email_authenticated' => 1, + 'email' => 'adminuser@cakedc.com', + 'email_verified' => 1, 'email_token' => 'testtoken', - 'email_token_expires' => '2008-03-25 02:45:46', + 'email_token_expiry' => '2008-03-25 02:45:46', 'tos' => 1, 'active' => 1, - 'last_activity' => '2008-03-25 02:45:46', + 'last_action' => '2008-03-25 02:45:46', 'last_login' => '2008-03-25 02:45:46', 'is_admin' => 1, 'role' => 'admin', @@ -85,17 +87,17 @@ class UserFixture extends CakeTestFixture { ), array( 'id' => '47ea303a-3cyc-k251-b313-4811c0a800bf', - 'username' => 'floriank', - 'slug' => 'floriank', - 'passwd' => 'secretkey', // secretkey + 'username' => 'testuser', + 'slug' => 'testuser', + 'password' => 'secretkey', // secretkey 'password_token' => '', - 'email' => 'florian.kraemer@cakedc.com', - 'email_authenticated' => '1', + 'email' => 'testuser@cakedc.com', + 'email_verified' => '1', 'email_token' => '', - 'email_token_expires' => '2008-03-25 02:45:46', + 'email_token_expiry' => '2008-03-25 02:45:46', 'tos' => 1, 'active' => 1, - 'last_activity' => '2008-03-25 02:45:46', + 'last_action' => '2008-03-25 02:45:46', 'last_login' => '2008-03-25 02:45:46', 'is_admin' => 0, 'role' => 'user', @@ -106,15 +108,15 @@ class UserFixture extends CakeTestFixture { 'id' => '37ea303a-3bdc-4251-b315-1316c0b300fa', 'username' => 'user1', 'slug' => 'user1', - 'passwd' => 'newpass', // newpass + 'password' => 'newpass', // newpass 'password_token' => '', 'email' => 'testuser1@testuser.com', - 'email_authenticated' => 0, + 'email_verified' => 0, 'email_token' => 'testtoken2', - 'email_token_expires' => '2008-03-28 02:45:46', + 'email_token_expiry' => '2008-03-28 02:45:46', 'tos' => 0, 'active' => 0, - 'last_activity' => '2008-03-25 02:45:46', + 'last_action' => '2008-03-25 02:45:46', 'last_login' => '2008-03-25 02:45:46', 'is_admin' => 0, 'role' => 'user', @@ -125,15 +127,15 @@ class UserFixture extends CakeTestFixture { 'id' => '495e36a2-1f00-46b9-8247-58a367265f11', 'username' => 'oidtest', 'slug' => 'oistest', - 'passwd' => 'newpass', // newpass + 'password' => 'newpass', // newpass 'password_token' => '', 'email' => 'oidtest@testuser.com', - 'email_authenticated' => 0, + 'email_verified' => 0, 'email_token' => 'testtoken2', - 'email_token_expires' => '2008-03-28 02:45:46', + 'email_token_expiry' => '2008-03-28 02:45:46', 'tos' => 0, 'active' => 0, - 'last_activity' => '2008-03-25 02:45:46', + 'last_action' => '2008-03-25 02:45:46', 'last_login' => '2008-03-25 02:45:46', 'is_admin' => 0, 'role' => 'user', @@ -144,15 +146,15 @@ class UserFixture extends CakeTestFixture { 'id' => '315e36a2-1fxj-46b9-8247-58a367265f11', 'username' => 'oidtest2', 'slug' => 'oistest', - 'passwd' => 'newpass', // newpass + 'password' => 'newpass', // newpass 'password_token' => '', 'email' => 'oidtest2@testuser.com', - 'email_authenticated' => 0, + 'email_verified' => 0, 'email_token' => 'testtoken2', - 'email_token_expires' => '2008-03-28 02:45:46', + 'email_token_expiry' => '2008-03-28 02:45:46', 'tos' => 1, 'active' => 1, - 'last_activity' => '2008-03-25 02:45:46', + 'last_action' => '2008-03-25 02:45:46', 'last_login' => '2008-03-25 02:45:46', 'is_admin' => 0, 'role' => 'user', @@ -163,15 +165,15 @@ class UserFixture extends CakeTestFixture { 'id' => '515e36a2-5fjj-46b9-8247-584367265f11', 'username' => 'resetuser', 'slug' => 'resetuser', - 'passwd' => 'newpass', // newpass + 'password' => 'newpass', // newpass 'password_token' => 'testtoken', 'email' => 'resetuser@testuser.com', - 'email_authenticated' => 1, + 'email_verified' => 1, 'email_token' => 'testtoken', - 'email_token_expires' => '2008-03-28 02:45:46', + 'email_token_expiry' => '2008-03-28 02:45:46', 'tos' => 1, 'active' => 1, - 'last_activity' => '2008-03-25 02:45:46', + 'last_action' => '2008-03-25 02:45:46', 'last_login' => '2008-03-25 02:45:46', 'is_admin' => 0, 'role' => 'user', @@ -181,13 +183,13 @@ class UserFixture extends CakeTestFixture { ); /** - * + * Constructor + * */ public function __construct() { parent::__construct(); - App::import('Core', 'Security'); foreach ($this->records as &$record) { - $record['passwd'] = Security::hash($record['passwd'], null, true); + $record['password'] = Security::hash($record['password'], null, true); } } diff --git a/views/details/add.ctp b/View/Details/add.ctp similarity index 54% rename from views/details/add.ctp rename to View/Details/add.ctp index 766d384c7..0974b463f 100644 --- a/views/details/add.ctp +++ b/View/Details/add.ctp @@ -10,9 +10,9 @@ */ ?>
-Form->create('Detail');?> +Form->create('Detail'); ?>
- + Form->input('user_id'); echo $this->Form->input('position'); @@ -20,12 +20,12 @@ echo $this->Form->input('value'); ?>
-Form->end('Submit');?> +Form->end(__d('users', 'Submit')); ?>
diff --git a/View/Details/admin_add.ctp b/View/Details/admin_add.ctp new file mode 100644 index 000000000..1c3efc59a --- /dev/null +++ b/View/Details/admin_add.ctp @@ -0,0 +1,31 @@ + +
+Form->create('Detail'); ?> +
+ + Form->input('user_id'); + echo $this->Form->input('position'); + echo $this->Form->input('field'); + echo $this->Form->input('value'); + ?> +
+Form->end(__d('users', 'Submit')); ?> +
+
+ +
diff --git a/View/Details/admin_edit.ctp b/View/Details/admin_edit.ctp new file mode 100644 index 000000000..26f234b01 --- /dev/null +++ b/View/Details/admin_edit.ctp @@ -0,0 +1,33 @@ + +
+Form->create('Detail'); ?> +
+ + Form->input('id'); + echo $this->Form->input('user_id'); + echo $this->Form->input('position'); + echo $this->Form->input('field'); + echo $this->Form->input('value'); + ?> +
+Form->end('Submit'); ?> +
+
+ +
diff --git a/views/details/admin_index.ctp b/View/Details/admin_index.ctp similarity index 53% rename from views/details/admin_index.ctp rename to View/Details/admin_index.ctp index 28d85b202..35a53940e 100644 --- a/views/details/admin_index.ctp +++ b/View/Details/admin_index.ctp @@ -10,11 +10,10 @@ */ ?>
-

-

- +

Paginator->counter(array( -'format' => __d('users', 'Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true) + 'format' => __d('users', 'Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%') )); ?>

@@ -26,7 +25,7 @@ echo $this->Paginator->counter(array( - +
Paginator->sort('value');?> Paginator->sort('created');?> Paginator->sort('modified');?>
- Html->link($detail['User']['id'], array('controller'=> 'users', 'action'=>'view', $detail['User']['id'])); ?> + Html->link($detail['User']['id'], array('controller' => 'users', 'action' => 'view', $detail['User']['id'])); ?> @@ -59,23 +58,23 @@ foreach ($details as $detail): - Html->link(__d('users', 'View', true), array('action'=>'view', $detail['Detail']['id'])); ?> - Html->link(__d('users', 'Edit', true), array('action'=>'edit', $detail['Detail']['id'])); ?> - Html->link(__d('users', 'Delete', true), array('action'=>'delete', $detail['Detail']['id']), null, sprintf(__d('users', 'Are you sure you want to delete # %s?', true), $detail['Detail']['id'])); ?> + Html->link(__d('users', 'View'), array('action'=>'view', $detail['Detail']['id'])); ?> + Html->link(__d('users', 'Edit'), array('action'=>'edit', $detail['Detail']['id'])); ?> + Html->link(__d('users', 'Delete'), array('action'=>'delete', $detail['Detail']['id']), null, sprintf(__d('users', 'Are you sure you want to delete # %s?'), $detail['Detail']['id'])); ?>
- Paginator->prev('<< '.__d('users', 'previous', true), array(), null, array('class'=>'disabled'));?> - | Paginator->numbers();?> - Paginator->next(__d('users', 'next', true).' >>', array(), null, array('class'=>'disabled'));?> + Paginator->prev('<< ' . __d('users', 'previous'), array(), null, array('class'=>'disabled')); ?> + | Paginator->numbers(); ?> + Paginator->next(__d('users', 'next') . ' >>', array(), null, array('class'=>'disabled')); ?>
diff --git a/View/Details/admin_view.ctp b/View/Details/admin_view.ctp new file mode 100644 index 000000000..49aa9616f --- /dev/null +++ b/View/Details/admin_view.ctp @@ -0,0 +1,61 @@ + +
+

+
+ > + > + +   + + > + > + Html->link($detail['User']['id'], array('controller'=> 'users', 'action' => 'view', $detail['User']['id'])); ?> +   + + > + > + +   + + > + > + +   + + > + > + +   + + > + > + +   + + > + > + +   + +
+
+
+ +
\ No newline at end of file diff --git a/views/details/edit.ctp b/View/Details/edit.ctp similarity index 52% rename from views/details/edit.ctp rename to View/Details/edit.ctp index 9dae678bf..2ef88b84a 100644 --- a/views/details/edit.ctp +++ b/View/Details/edit.ctp @@ -10,17 +10,16 @@ */ ?>
-Form->create('Detail', array( - 'action' => 'edit'));?> +Form->create('Detail', array('action' => 'edit')); ?>
- + Form->input('firstname'); - echo $this->Form->input('middlename'); - echo $this->Form->input('lastname'); - echo $this->Form->input('biography'); - echo $this->Form->input('birthday'); + echo $this->Form->input('firstname'); + echo $this->Form->input('middlename'); + echo $this->Form->input('lastname'); + echo $this->Form->input('biography'); + echo $this->Form->input('birthday'); ?>
-Form->end('Submit');?> +Form->end('Submit'); ?>
\ No newline at end of file diff --git a/views/details/index.ctp b/View/Details/index.ctp similarity index 94% rename from views/details/index.ctp rename to View/Details/index.ctp index bb23d05c9..9d8df044f 100644 --- a/views/details/index.ctp +++ b/View/Details/index.ctp @@ -24,5 +24,5 @@ if (!empty($details)) { } echo $this->Form->input($detail['Detail']['field'], ($options)); } - echo $this->Form->end(__d('users', 'Submit', true)); + echo $this->Form->end(__d('users', 'Submit')); } diff --git a/View/Details/view.ctp b/View/Details/view.ctp new file mode 100644 index 000000000..820b4c6b8 --- /dev/null +++ b/View/Details/view.ctp @@ -0,0 +1,62 @@ + +
+

+
+ > + > + +   + + > + > + Html->link($detail['User']['id'], array('controller' => 'users', 'action' => 'view', $detail['User']['id'])); ?> +   + + > + > + +   + + > + > + +   + + > + > + +   + + > + > + +   + + > + > + +   + +
+
+ +
+ +
diff --git a/views/elements/login.ctp b/View/Elements/login.ctp similarity index 69% rename from views/elements/login.ctp rename to View/Elements/login.ctp index 7ee85a282..9addebbf0 100644 --- a/views/elements/login.ctp +++ b/View/Elements/login.ctp @@ -17,10 +17,7 @@ if (!$this->Session->check('Auth.Users')) { 'controller' => 'users', 'action' => 'login'), 'id' => 'LoginForm')); - echo $this->Form->input('email', array( - 'label' => __d('users', 'Email', true))); - echo $this->Form->input('passwd', array( - 'label' => __d('users', 'Password', true), - 'type' => 'password')); - echo $this->Form->end(__d('users', 'Login', true)); + echo $this->Form->input('email', array('label' => __d('users', 'Email'))); + echo $this->Form->input('password', array('label' => __d('users', 'Password'))); + echo $this->Form->end(__d('users', 'Login')); } diff --git a/views/elements/email/text/account_verification.ctp b/View/Emails/text/account_verification.ctp similarity index 76% rename from views/elements/email/text/account_verification.ctp rename to View/Emails/text/account_verification.ctp index 0c372b030..d7ab3910b 100644 --- a/views/elements/email/text/account_verification.ctp +++ b/View/Emails/text/account_verification.ctp @@ -9,8 +9,8 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -echo sprintf(__d('users', 'Hello %s,', true), $user['User']['username']); +echo sprintf(__d('users', 'Hello %s,'), $user['User']['username']); echo "\n"; -__d('users', 'to validate your account, you must visit the URL below within 24 hours'); +echo __d('users', 'to validate your account, you must visit the URL below within 24 hours'); echo "\n"; echo Router::url(array('admin' => false, 'plugin' => 'users', 'controller' => 'users', 'action' => 'verify', 'email', $user['User']['email_token']), true); diff --git a/views/elements/email/text/password_reset_request.ctp b/View/Emails/text/password_reset_request.ctp similarity index 100% rename from views/elements/email/text/password_reset_request.ctp rename to View/Emails/text/password_reset_request.ctp diff --git a/View/Users/add.ctp b/View/Users/add.ctp new file mode 100644 index 000000000..5844fb16c --- /dev/null +++ b/View/Users/add.ctp @@ -0,0 +1,50 @@ + +
+
+ + Form->create($model); + echo $this->Form->input('username', array( + 'error' => array( + 'unique_username' => __d('users', 'Please select a username that is not already in use', true), + 'username_min' => __d('users', 'Must be at least 3 characters', true), + 'alpha' => __d('users', 'Username must contain numbers and letters only', true), + 'required' => __d('users', 'Please choose username', true)))); + echo $this->Form->input('email', array( + 'label' => __d('users', 'E-mail (used as login)',true), + 'error' => array('isValid' => __d('users', 'Must be a valid email address', true), + 'isUnique' => __d('users', 'An account with that email already exists', true)))); + echo $this->Form->input('password', array( + 'label' => __d('users', 'Password',true), + 'type' => 'password', + 'error' => __d('users', 'Must be at least 5 characters long', true))); + echo $this->Form->input('temppassword', array( + 'label' => __d('users', 'Password (confirm)', true), + 'type' => 'password', + 'error' => __d('users', 'Passwords must match', true) + ) + ); + echo $this->Form->input('tos', array( + 'label' => __d('users', 'I have read and agreed to ', true) . $this->Html->link(__d('users', 'Terms of Service', true), array('controller' => 'pages', 'action' => 'tos')), + 'error' => __d('users', 'You must verify you have read the Terms of Service', true) + ) + ); + echo $this->Form->end(__d('users', 'Submit',true)); + ?> +
+
+
+ +
diff --git a/views/users/admin_add.ctp b/View/Users/admin_add.ctp similarity index 60% rename from views/users/admin_add.ctp rename to View/Users/admin_add.ctp index bd583f141..383b802a8 100644 --- a/views/users/admin_add.ctp +++ b/View/Users/admin_add.ctp @@ -10,17 +10,15 @@ */ ?>
-Form->create($model);?> +Form->create($model); ?>
- - Form->input('username'); - ?> + + Form->input('username'); ?>
-Form->end('Submit');?> +Form->end('Submit'); ?>
diff --git a/View/Users/admin_edit.ctp b/View/Users/admin_edit.ctp new file mode 100644 index 000000000..32c0fb760 --- /dev/null +++ b/View/Users/admin_edit.ctp @@ -0,0 +1,28 @@ + +
+Form->create($model); ?> +
+ + Form->input('id'); + echo $this->Form->input('username'); + ?> +
+Form->end('Submit'); ?> +
+
+ +
diff --git a/views/users/admin_index.ctp b/View/Users/admin_index.ctp similarity index 50% rename from views/users/admin_index.ctp rename to View/Users/admin_index.ctp index ec0e27349..d29508db0 100644 --- a/views/users/admin_index.ctp +++ b/View/Users/admin_index.ctp @@ -10,27 +10,25 @@ */ ?>
-

+

-

+

Form->create($model, array('action' => 'index')); - echo $this->Form->input('username', array( - 'label' => __d('users', 'Username', true))); - echo $this->Form->input('email', array( - 'label' => __d('users', 'Email', true))); - echo $this->Form->end(__d('users', 'Search', true)); + echo $this->Form->create($model, array('action' => 'index')); + echo $this->Form->input('username', array('label' => __d('users', 'Username'))); + echo $this->Form->input('email', array('label' => __d('users', 'Email'))); + echo $this->Form->end(__d('users', 'Search')); ?> element('paging'); ?> - - - - - - + + + + + + diff --git a/View/Users/admin_view.ctp b/View/Users/admin_view.ctp new file mode 100644 index 000000000..898267180 --- /dev/null +++ b/View/Users/admin_view.ctp @@ -0,0 +1,39 @@ + +
+

+
+ > + > + +   + + > + > + +   + + > + > + +   + +
+
+
+ +
diff --git a/views/users/change_password.ctp b/View/Users/change_password.ctp similarity index 56% rename from views/users/change_password.ctp rename to View/Users/change_password.ctp index 155e08e90..5b70a2b24 100644 --- a/views/users/change_password.ctp +++ b/View/Users/change_password.ctp @@ -9,20 +9,17 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ ?> -

-

- -

+

+

Form->create($model, array('action' => 'change_password')); +echo $this->Form->create($model, array('action' => 'change_password')); echo $this->Form->input('old_password', array( - 'label' => __d('users', 'Old Password', true), + 'label' => __d('users', 'Old Password'), 'type' => 'password')); echo $this->Form->input('new_password', array( - 'label' => __d('users', 'New Password', true), + 'label' => __d('users', 'New Password'), 'type' => 'password')); echo $this->Form->input('confirm_password', array( - 'label' => __d('users', 'Confirm', true), + 'label' => __d('users', 'Confirm'), 'type' => 'password')); - echo $this->Form->end(__d('users', 'Submit', true)); -?> \ No newline at end of file +echo $this->Form->end(__d('users', 'Submit')); diff --git a/views/users/dashboard.ctp b/View/Users/dashboard.ctp similarity index 72% rename from views/users/dashboard.ctp rename to View/Users/dashboard.ctp index 838833a75..501453f17 100644 --- a/views/users/dashboard.ctp +++ b/View/Users/dashboard.ctp @@ -10,6 +10,6 @@ */ ?>
-

-

+

+

\ No newline at end of file diff --git a/views/users/edit.ctp b/View/Users/edit.ctp similarity index 57% rename from views/users/edit.ctp rename to View/Users/edit.ctp index 679da5ed8..d33256a7f 100644 --- a/views/users/edit.ctp +++ b/View/Users/edit.ctp @@ -9,14 +9,14 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ ?> -Form->create($model);?> +Form->create($model); ?>
- + Form->input('id'); - echo $this->Form->input('account_type'); - echo $this->Form->input('url'); - echo $this->Form->input('username'); + echo $this->Form->input('id'); + echo $this->Form->input('account_type'); + echo $this->Form->input('url'); + echo $this->Form->input('username'); ?>
-Form->end('Submit');?> \ No newline at end of file +Form->end('Submit'); ?> \ No newline at end of file diff --git a/View/Users/index.ctp b/View/Users/index.ctp new file mode 100644 index 000000000..1b2ef76e6 --- /dev/null +++ b/View/Users/index.ctp @@ -0,0 +1,61 @@ + +
+

+ +

Paginator->counter(array( + 'format' => __d('users', 'Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%') + )); + ?>

+ +
Paginator->sort('username');?>Paginator->sort('email');?>Paginator->sort('email_authenticated');?>Paginator->sort('active');?>Paginator->sort('created');?>Paginator->sort('username'); ?>Paginator->sort('email'); ?>Paginator->sort('email_authenticated'); ?>Paginator->sort('active'); ?>Paginator->sort('created'); ?>
- Html->link(__d('users', 'View', true), array('action'=>'view', $user[$model]['id'])); ?> - Html->link(__d('users', 'Edit', true), array('action'=>'edit', $user[$model]['id'])); ?> - Html->link(__d('users', 'Delete', true), array('action'=>'delete', $user[$model]['id']), null, sprintf(__d('users', 'Are you sure you want to delete # %s?', true), $user[$model]['id'])); ?> + Html->link(__d('users', 'View'), array('action'=>'view', $user[$model]['id'])); ?> + Html->link(__d('users', 'Edit'), array('action'=>'edit', $user[$model]['id'])); ?> + Html->link(__d('users', 'Delete'), array('action'=>'delete', $user[$model]['id']), null, sprintf(__d('users', 'Are you sure you want to delete # %s?'), $user[$model]['id'])); ?>
+ + + + + + + > + + + + + +
Paginator->sort('username'); ?>Paginator->sort('created'); ?>
+ Html->link(__d('users', 'View'), array('action' => 'view', $user[$model]['id'])); ?> + Html->link(__d('users', 'Edit'), array('action' => 'edit', $user[$model]['id'])); ?> + Html->link( + __d('users', 'Delete'), + array('action' => 'delete', $user[$model]['id']), + null, + sprintf(__d('users', 'Are you sure you want to delete # %s?'), $user[$model]['id']) + ); ?> +
+
+ Paginator->prev('<< ' . __d('users', 'previous'), array(), null, array('class' => 'disabled')); ?> + | Paginator->numbers(); ?> + Paginator->next(__d('users', 'next') . ' >>', array(), null, array('class' => 'disabled')); ?> +
+
+
+ +
diff --git a/views/users/login.ctp b/View/Users/login.ctp similarity index 57% rename from views/users/login.ctp rename to View/Users/login.ctp index bbabce902..6a4a25596 100644 --- a/views/users/login.ctp +++ b/View/Users/login.ctp @@ -9,18 +9,15 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ ?> -

+

- + Form->create($model, array( - 'action' => 'login')); - echo $this->Form->input('email', array( - 'label' => __d('users', 'Email', true))); - echo $this->Form->input('passwd', array( - 'label' => __d('users', 'Password', true))); + echo $this->Form->create($model, array('action' => 'login')); + echo $this->Form->input('email', array('label' => __d('users', 'Email'))); + echo $this->Form->input('password', array('label' => __d('users', 'Password'))); echo __d('users', 'Remember Me') . $this->Form->checkbox('remember_me'); echo $this->Form->hidden('User.return_to', array('value' => $return_to)); - echo $this->Form->end(__d('users', 'Submit', true)); + echo $this->Form->end(__d('users', 'Submit')); ?>
\ No newline at end of file diff --git a/View/Users/openid_add.ctp b/View/Users/openid_add.ctp new file mode 100644 index 000000000..7ef723c3f --- /dev/null +++ b/View/Users/openid_add.ctp @@ -0,0 +1,70 @@ + +
+
+ + Form->create('Openid.OpenidUser', array('url' => array('plugin' => 'openid', 'controller' => 'openid_users', 'action' => 'attach_identity'))); + $oid = isset($openIdAuthData['openid_claimed_id']) ? $openIdAuthData['openid_claimed_id'] : $openIdAuthData['openid_identity']; + echo $this->Form->input('openid_identifier', array( + 'name' => 'data[OpenidUser][openid_url]', + 'class' => 'openid', + 'value' => $oid, + 'type' => 'hidden', + 'label' => __d('users', 'Openid Identifier', true) + ) + ); + + $username = isset($openIdAuthData['openid_sreg_nickname']) ? $openIdAuthData['openid_sreg_nickname'] : ''; + echo $this->Form->input('username', array( + 'value' => $username, + 'label' => __d('users', 'Username', true), + )); + + if (isset($this->params['named']['username_taken'])) { + echo $this->Form->input('username', array( + 'value' => $openIdAuthData['openid_sreg_nickname'], + 'label' => __d('users', 'Username', true), + ) + ); + } + + if (isset($openIdAuthData['openid_sreg_email'])) { + echo $this->Form->input('email', array( + 'value' => $openIdAuthData['openid_sreg_email'], + 'label' => __d('users', 'Email', true), + 'type' => 'hidden', + ) + ); + } elseif (isset($openIdAuthData['openid_ext1_value_email'])) { + echo $this->Form->input('email', array( + 'value' => $openIdAuthData['openid_ext1_value_email'], + 'label' => __d('users', 'Email', true), + 'type' => 'hidden', + ) + ); + } + echo $this->Form->input('tos', array( + 'type' => 'checkbox', + 'label' => __d('users', 'I have read and agreed to ', true) . $this->Html->link(__d('users', 'Terms of Service', true), array('controller' => 'pages', 'action' => 'tos')), + 'error' => __d('users', 'You must verify you have read the Terms of Service', true) + ) + ); + echo $this->Form->end(__d('users', 'Submit',true)); + ?> +
+
+
+ +
\ No newline at end of file diff --git a/View/Users/request_password_change.ctp b/View/Users/request_password_change.ctp new file mode 100644 index 000000000..4e695d9a9 --- /dev/null +++ b/View/Users/request_password_change.ctp @@ -0,0 +1,22 @@ + +

+

+Form->create($model, array( + 'url' => array( + 'admin' => false, + 'action' => 'reset_password'))); + echo $this->Form->input('email', array( + 'label' => __d('users', 'Your Email'))); + echo $this->Form->submit(__d('users', 'Submit')); +echo $this->Form->end(); diff --git a/View/Users/reset_password.ctp b/View/Users/reset_password.ctp new file mode 100644 index 000000000..823308c80 --- /dev/null +++ b/View/Users/reset_password.ctp @@ -0,0 +1,14 @@ +

+Form->create($model, array( + 'url' => array( + 'action' => 'reset_password', + $token))); + echo $this->Form->input('new_password', array( + 'label' => __d('users', 'New Password'), + 'type' => 'password')); + echo $this->Form->input('confirm_password', array( + 'label' => __d('users', 'Confirm'), + 'type' => 'password')); + echo $this->Form->submit(__d('users', 'Submit')); +echo $this->Form->end(); diff --git a/View/Users/search.ctp b/View/Users/search.ctp new file mode 100644 index 000000000..c1a9612f3 --- /dev/null +++ b/View/Users/search.ctp @@ -0,0 +1,18 @@ + +

+Form->create($model, array('action' => 'search')); + echo $this->Form->input('username', array('label' => __d('users', 'Username'))); + echo $this->Form->input('email', array('label' => __d('users', 'Email'))); + echo $this->Form->input('Profile.name', array('label' => __d('users', 'Name'))); +echo $this->Form->end(__d('users', 'Search')); diff --git a/views/users/view.ctp b/View/Users/view.ctp similarity index 54% rename from views/users/view.ctp rename to View/Users/view.ctp index dd5cf3494..38894f3c0 100644 --- a/views/users/view.ctp +++ b/View/Users/view.ctp @@ -10,25 +10,25 @@ */ ?>
-

+

- > - > + > + >   - > - > + > + >   ' . $detail['field'] . ''; - echo '
' . $detail['value'] . '
'; - } + if (!empty($user['Detail'])) { + foreach ($user['Detail'] as $detail) { + echo '
' . $detail['field'] . '
'; + echo '
' . $detail['value'] . '
'; } + } ?>
diff --git a/readme.md b/readme.md index 124c41260..289ddc008 100644 --- a/readme.md +++ b/readme.md @@ -36,7 +36,7 @@ The plugin itself is already capable of: Declare the controller class - App::import('Controller', 'Users.Users'); + App::uses('Controller', 'Users.Users'); AppUsersController extends UsersController In the case you want to extend also the user model it's required to set the right user class in the beforeFilter() because the controller will use the inherited model which would be Users.User. @@ -62,7 +62,7 @@ You can overwrite the render() method to fall back to the plugin views in the ca Declare the model - App::import('Model', 'Users.User'); + App::uses('Model', 'Users.User'); AppUser extends User { public $useTable = 'users'; public $name = 'AppUser'; @@ -75,7 +75,7 @@ You can override/extend all methods or properties like validation rules to suit ## Requirements ## * PHP version: PHP 5.2+ -* CakePHP version: Cakephp 1.3 Stable +* CakePHP version: Cakephp 2.0 * [CakeDC Utils plugin](http://github.com/CakeDC/utils) * [CakeDC Search plugin](http://github.com/CakeDC/search) diff --git a/views/details/admin_add.ctp b/views/details/admin_add.ctp deleted file mode 100644 index 766d384c7..000000000 --- a/views/details/admin_add.ctp +++ /dev/null @@ -1,31 +0,0 @@ - -
-Form->create('Detail');?> -
- - Form->input('user_id'); - echo $this->Form->input('position'); - echo $this->Form->input('field'); - echo $this->Form->input('value'); - ?> -
-Form->end('Submit');?> -
-
- -
diff --git a/views/details/admin_edit.ctp b/views/details/admin_edit.ctp deleted file mode 100644 index 4ee6be0a2..000000000 --- a/views/details/admin_edit.ctp +++ /dev/null @@ -1,33 +0,0 @@ - -
-Form->create('Detail');?> -
- - Form->input('id'); - echo $this->Form->input('user_id'); - echo $this->Form->input('position'); - echo $this->Form->input('field'); - echo $this->Form->input('value'); - ?> -
-Form->end('Submit');?> -
-
- -
diff --git a/views/details/admin_view.ctp b/views/details/admin_view.ctp deleted file mode 100644 index ec425b0c3..000000000 --- a/views/details/admin_view.ctp +++ /dev/null @@ -1,61 +0,0 @@ - -
-

-
- > - > - -   - - > - > - Html->link($detail['User']['id'], array('controller'=> 'users', 'action'=>'view', $detail['User']['id'])); ?> -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - -
-
-
- -
\ No newline at end of file diff --git a/views/details/view.ctp b/views/details/view.ctp deleted file mode 100644 index dce0fa870..000000000 --- a/views/details/view.ctp +++ /dev/null @@ -1,62 +0,0 @@ - -
-

-
- > - > - -   - - > - > - Html->link($detail['User']['id'], array('controller'=> 'users', 'action'=>'view', $detail['User']['id'])); ?> -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - - > - > - -   - -
-
- -
- -
\ No newline at end of file diff --git a/views/users/admin_edit.ctp b/views/users/admin_edit.ctp deleted file mode 100644 index fbdebb627..000000000 --- a/views/users/admin_edit.ctp +++ /dev/null @@ -1,28 +0,0 @@ - -
-Form->create($model);?> -
- - Form->input('id'); - echo $this->Form->input('username'); - ?> -
-Form->end('Submit');?> -
-
- -
diff --git a/views/users/admin_view.ctp b/views/users/admin_view.ctp deleted file mode 100644 index e0ea3502e..000000000 --- a/views/users/admin_view.ctp +++ /dev/null @@ -1,39 +0,0 @@ - -
-

-
- > - > - -   - - > - > - -   - - > - > - -   - -
-
-
- -
diff --git a/views/users/index.ctp b/views/users/index.ctp deleted file mode 100644 index ea27ff4e6..000000000 --- a/views/users/index.ctp +++ /dev/null @@ -1,59 +0,0 @@ - -
-

-

-Paginator->counter(array( -'format' => __d('users', 'Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true) -)); -?>

- - - - - - - - > - - - - - -
Paginator->sort('username');?>Paginator->sort('created');?>
- - - - - Html->link(__d('users', 'View', true), array('action'=>'view', $user[$model]['id'])); ?> - Html->link(__d('users', 'Edit', true), array('action'=>'edit', $user[$model]['id'])); ?> - Html->link(__d('users', 'Delete', true), array('action'=>'delete', $user[$model]['id']), null, sprintf(__d('users', 'Are you sure you want to delete # %s?', true), $user[$model]['id'])); ?> -
-
-
- Paginator->prev('<< '.__d('users', 'previous', true), array(), null, array('class'=>'disabled'));?> - | Paginator->numbers();?> - Paginator->next(__d('users', 'next', true).' >>', array(), null, array('class'=>'disabled'));?> -
-
- -
diff --git a/views/users/register.ctp b/views/users/register.ctp deleted file mode 100644 index 308b6c1a6..000000000 --- a/views/users/register.ctp +++ /dev/null @@ -1,103 +0,0 @@ - -Session->read('openIdAuthData');?> -

-
- - Form->create($model, array('url' => array('action'=>'register'))); - echo $this->Form->input('username', array( - 'error' => array( - 'unique_username' => __d('users', 'Please select a username that is not already in use', true), - 'username_min' => __d('users', 'Must be at least 3 characters', true), - 'alpha' => __d('users', 'Username must contain numbers and letters only', true), - 'required' => __d('users', 'Please choose username', true)))); - echo $this->Form->input('email', array( - 'label' => __d('users', 'E-mail (used as login)',true), - 'error' => array('isValid' => __d('users', 'Must be a valid email address', true), - 'isUnique' => __d('users', 'An account with that email already exists', true)))); - echo $this->Form->input('passwd', array( - 'label' => __d('users', 'Password',true), - 'type' => 'password', - 'error' => __d('users', 'Must be at least 5 characters long', true))); - echo $this->Form->input('temppassword', array( - 'label' => __d('users', 'Password (confirm)', true), - 'type' => 'password', - 'error' => __d('users', 'Passwords must match', true) - ) - ); - echo $this->Form->input('tos', array( - 'label' => __d('users', 'I have read and agreed to ', true) . $this->Html->link(__d('users', 'Terms of Service', true), array('controller' => 'pages', 'action' => 'tos')), - 'error' => __d('users', 'You must verify you have read the Terms of Service', true) - ) - ); - echo $this->Form->end(__d('users', 'Submit',true)); - } else { - if(isset($openIdAuthData['openid_claimed_id'])) { - $oid = $openIdAuthData['openid_claimed_id']; - } else { - $oid = $openIdAuthData['openid_identity']; - } - echo $this->Form->create('Openid.OpenidUser', array('url' => array('plugin' => 'openid', 'controller' => 'openid_users', 'action' => 'attach_identity'))); - echo $this->Form->input('openid_identifier', array( - 'name' => 'data[OpenidUser][openid_url]', - 'class' => 'openid', - 'value' => $oid, - 'type' => 'hidden', - 'label' => __d('users', 'Openid Identifier', true) - ) - ); - - if (isset($openIdAuthData['openid_sreg_nickname'])) { - $username = $openIdAuthData['openid_sreg_nickname']; - } else { - $username = ''; - } - echo $this->Form->input('username', array( - 'value' => $username, - 'label' => __d('users', 'Username', true), - )); - - if (isset($this->params['named']['username_taken'])) { - echo $this->Form->input('username', array( - 'value' => $openIdAuthData['openid_sreg_nickname'], - 'label' => __d('users', 'Username', true), - ) - ); - } - - if (isset($openIdAuthData['openid_sreg_email'])) { - echo $this->Form->input('email', array( - 'value' => $openIdAuthData['openid_sreg_email'], - 'label' => __d('users', 'Email', true), - 'type' => 'hidden', - ) - ); - } elseif (isset($openIdAuthData['openid_ext1_value_email'])) { - echo $this->Form->input('email', array( - 'value' => $openIdAuthData['openid_ext1_value_email'], - 'label' => __d('users', 'Email', true), - 'type' => 'hidden', - ) - ); - } - echo $this->Form->input('tos', array( - 'type' => 'checkbox', - 'label' => __d('users', 'I have read and agreed to ', true) . $this->Html->link(__d('users', 'Terms of Service', true), array('controller' => 'pages', 'action' => 'tos')), - 'error' => __d('users', 'You must verify you have read the Terms of Service', true) - ) - ); - echo $this->Form->end(__d('users', 'Submit',true)); - } -?> -
\ No newline at end of file diff --git a/views/users/request_password_change.ctp b/views/users/request_password_change.ctp deleted file mode 100644 index 5c866640a..000000000 --- a/views/users/request_password_change.ctp +++ /dev/null @@ -1,25 +0,0 @@ - -

-

- -

-Form->create($model, array( - 'url' => array( - 'admin' => false, - 'action' => 'reset_password'))); - echo $this->Form->input('email', array( - 'label' => __d('users', 'Your Email', true))); - echo $this->Form->submit(__d('users', 'Submit', true)); - echo $this->Form->end(); -?> \ No newline at end of file diff --git a/views/users/reset_password.ctp b/views/users/reset_password.ctp deleted file mode 100644 index 3e831e48e..000000000 --- a/views/users/reset_password.ctp +++ /dev/null @@ -1,16 +0,0 @@ -

- -Form->create($model, array( - 'url' => array( - 'action' => 'reset_password', - $token))); - echo $this->Form->input('new_password', array( - 'label' => __d('users', 'New Password', true), - 'type' => 'password')); - echo $this->Form->input('confirm_password', array( - 'label' => __d('users', 'Confirm', true), - 'type' => 'password')); - echo $this->Form->submit(__d('users', 'Submit', true)); - echo $this->Form->end(); -?> \ No newline at end of file diff --git a/views/users/search.ctp b/views/users/search.ctp deleted file mode 100644 index 4c8dfa7a8..000000000 --- a/views/users/search.ctp +++ /dev/null @@ -1,22 +0,0 @@ - -

-Form->create($model, array('action' => 'search')); - echo $this->Form->input('username', array( - 'label' => __d('users', 'Username', true))); - echo $this->Form->input('email', array( - 'label' => __d('users', 'Email', true))); - echo $this->Form->input('Profile.name', array( - 'label' => __d('users', 'Name', true))); - echo $this->Form->end(__d('users', 'Search', true)); -?> \ No newline at end of file