From 03ec20b54267c2629567410b7c910cb3d5a5c7ba Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 22 May 2011 12:23:19 +1000 Subject: [PATCH 01/80] Moved direcotiress and renamed files for 2.0 readiness --- .../details_controller.php => Controller/DetailsController.php | 0 .../users_controller.php => Controller/UsersController.php | 0 models/detail.php => Model/Detail.php | 0 models/user.php => Model/User.php | 0 .../Case/Controller/DetailsControllerTest.php | 0 .../Case/Controller/UsersControllerTest.php | 0 .../models/detail.test.php => Test/Case/Model/DetailTest.php | 0 tests/cases/models/user.test.php => Test/Case/Model/UserTest.php | 0 .../fixtures/detail_fixture.php => Test/Fixture/DetailFixture.php | 0 tests/fixtures/user_fixture.php => Test/Fixture/UserFixture.php | 0 {views/details => View/Details}/add.ctp | 0 {views/details => View/Details}/admin_add.ctp | 0 {views/details => View/Details}/admin_edit.ctp | 0 {views/details => View/Details}/admin_index.ctp | 0 {views/details => View/Details}/admin_view.ctp | 0 {views/details => View/Details}/edit.ctp | 0 {views/details => View/Details}/index.ctp | 0 {views/details => View/Details}/view.ctp | 0 .../Elements}/email/text/account_verification.ctp | 0 .../Elements}/email/text/password_reset_request.ctp | 0 {views/elements => View/Elements}/login.ctp | 0 {views/users => View/Users}/admin_add.ctp | 0 {views/users => View/Users}/admin_edit.ctp | 0 {views/users => View/Users}/admin_index.ctp | 0 {views/users => View/Users}/admin_view.ctp | 0 {views/users => View/Users}/change_password.ctp | 0 {views/users => View/Users}/dashboard.ctp | 0 {views/users => View/Users}/edit.ctp | 0 {views/users => View/Users}/index.ctp | 0 {views/users => View/Users}/login.ctp | 0 {views/users => View/Users}/register.ctp | 0 {views/users => View/Users}/request_password_change.ctp | 0 {views/users => View/Users}/reset_password.ctp | 0 {views/users => View/Users}/search.ctp | 0 {views/users => View/Users}/view.ctp | 0 35 files changed, 0 insertions(+), 0 deletions(-) rename controllers/details_controller.php => Controller/DetailsController.php (100%) rename controllers/users_controller.php => Controller/UsersController.php (100%) rename models/detail.php => Model/Detail.php (100%) rename models/user.php => Model/User.php (100%) rename tests/cases/controllers/details_controller.test.php => Test/Case/Controller/DetailsControllerTest.php (100%) rename tests/cases/controllers/users_controller.test.php => Test/Case/Controller/UsersControllerTest.php (100%) rename tests/cases/models/detail.test.php => Test/Case/Model/DetailTest.php (100%) rename tests/cases/models/user.test.php => Test/Case/Model/UserTest.php (100%) rename tests/fixtures/detail_fixture.php => Test/Fixture/DetailFixture.php (100%) rename tests/fixtures/user_fixture.php => Test/Fixture/UserFixture.php (100%) rename {views/details => View/Details}/add.ctp (100%) rename {views/details => View/Details}/admin_add.ctp (100%) rename {views/details => View/Details}/admin_edit.ctp (100%) rename {views/details => View/Details}/admin_index.ctp (100%) rename {views/details => View/Details}/admin_view.ctp (100%) rename {views/details => View/Details}/edit.ctp (100%) rename {views/details => View/Details}/index.ctp (100%) rename {views/details => View/Details}/view.ctp (100%) rename {views/elements => View/Elements}/email/text/account_verification.ctp (100%) rename {views/elements => View/Elements}/email/text/password_reset_request.ctp (100%) rename {views/elements => View/Elements}/login.ctp (100%) rename {views/users => View/Users}/admin_add.ctp (100%) rename {views/users => View/Users}/admin_edit.ctp (100%) rename {views/users => View/Users}/admin_index.ctp (100%) rename {views/users => View/Users}/admin_view.ctp (100%) rename {views/users => View/Users}/change_password.ctp (100%) rename {views/users => View/Users}/dashboard.ctp (100%) rename {views/users => View/Users}/edit.ctp (100%) rename {views/users => View/Users}/index.ctp (100%) rename {views/users => View/Users}/login.ctp (100%) rename {views/users => View/Users}/register.ctp (100%) rename {views/users => View/Users}/request_password_change.ctp (100%) rename {views/users => View/Users}/reset_password.ctp (100%) rename {views/users => View/Users}/search.ctp (100%) rename {views/users => View/Users}/view.ctp (100%) diff --git a/controllers/details_controller.php b/Controller/DetailsController.php similarity index 100% rename from controllers/details_controller.php rename to Controller/DetailsController.php diff --git a/controllers/users_controller.php b/Controller/UsersController.php similarity index 100% rename from controllers/users_controller.php rename to Controller/UsersController.php diff --git a/models/detail.php b/Model/Detail.php similarity index 100% rename from models/detail.php rename to Model/Detail.php diff --git a/models/user.php b/Model/User.php similarity index 100% rename from models/user.php rename to Model/User.php diff --git a/tests/cases/controllers/details_controller.test.php b/Test/Case/Controller/DetailsControllerTest.php similarity index 100% rename from tests/cases/controllers/details_controller.test.php rename to Test/Case/Controller/DetailsControllerTest.php diff --git a/tests/cases/controllers/users_controller.test.php b/Test/Case/Controller/UsersControllerTest.php similarity index 100% rename from tests/cases/controllers/users_controller.test.php rename to Test/Case/Controller/UsersControllerTest.php diff --git a/tests/cases/models/detail.test.php b/Test/Case/Model/DetailTest.php similarity index 100% rename from tests/cases/models/detail.test.php rename to Test/Case/Model/DetailTest.php diff --git a/tests/cases/models/user.test.php b/Test/Case/Model/UserTest.php similarity index 100% rename from tests/cases/models/user.test.php rename to Test/Case/Model/UserTest.php diff --git a/tests/fixtures/detail_fixture.php b/Test/Fixture/DetailFixture.php similarity index 100% rename from tests/fixtures/detail_fixture.php rename to Test/Fixture/DetailFixture.php diff --git a/tests/fixtures/user_fixture.php b/Test/Fixture/UserFixture.php similarity index 100% rename from tests/fixtures/user_fixture.php rename to Test/Fixture/UserFixture.php diff --git a/views/details/add.ctp b/View/Details/add.ctp similarity index 100% rename from views/details/add.ctp rename to View/Details/add.ctp diff --git a/views/details/admin_add.ctp b/View/Details/admin_add.ctp similarity index 100% rename from views/details/admin_add.ctp rename to View/Details/admin_add.ctp diff --git a/views/details/admin_edit.ctp b/View/Details/admin_edit.ctp similarity index 100% rename from views/details/admin_edit.ctp rename to View/Details/admin_edit.ctp diff --git a/views/details/admin_index.ctp b/View/Details/admin_index.ctp similarity index 100% rename from views/details/admin_index.ctp rename to View/Details/admin_index.ctp diff --git a/views/details/admin_view.ctp b/View/Details/admin_view.ctp similarity index 100% rename from views/details/admin_view.ctp rename to View/Details/admin_view.ctp diff --git a/views/details/edit.ctp b/View/Details/edit.ctp similarity index 100% rename from views/details/edit.ctp rename to View/Details/edit.ctp diff --git a/views/details/index.ctp b/View/Details/index.ctp similarity index 100% rename from views/details/index.ctp rename to View/Details/index.ctp diff --git a/views/details/view.ctp b/View/Details/view.ctp similarity index 100% rename from views/details/view.ctp rename to View/Details/view.ctp diff --git a/views/elements/email/text/account_verification.ctp b/View/Elements/email/text/account_verification.ctp similarity index 100% rename from views/elements/email/text/account_verification.ctp rename to View/Elements/email/text/account_verification.ctp diff --git a/views/elements/email/text/password_reset_request.ctp b/View/Elements/email/text/password_reset_request.ctp similarity index 100% rename from views/elements/email/text/password_reset_request.ctp rename to View/Elements/email/text/password_reset_request.ctp diff --git a/views/elements/login.ctp b/View/Elements/login.ctp similarity index 100% rename from views/elements/login.ctp rename to View/Elements/login.ctp diff --git a/views/users/admin_add.ctp b/View/Users/admin_add.ctp similarity index 100% rename from views/users/admin_add.ctp rename to View/Users/admin_add.ctp diff --git a/views/users/admin_edit.ctp b/View/Users/admin_edit.ctp similarity index 100% rename from views/users/admin_edit.ctp rename to View/Users/admin_edit.ctp diff --git a/views/users/admin_index.ctp b/View/Users/admin_index.ctp similarity index 100% rename from views/users/admin_index.ctp rename to View/Users/admin_index.ctp diff --git a/views/users/admin_view.ctp b/View/Users/admin_view.ctp similarity index 100% rename from views/users/admin_view.ctp rename to View/Users/admin_view.ctp diff --git a/views/users/change_password.ctp b/View/Users/change_password.ctp similarity index 100% rename from views/users/change_password.ctp rename to View/Users/change_password.ctp diff --git a/views/users/dashboard.ctp b/View/Users/dashboard.ctp similarity index 100% rename from views/users/dashboard.ctp rename to View/Users/dashboard.ctp diff --git a/views/users/edit.ctp b/View/Users/edit.ctp similarity index 100% rename from views/users/edit.ctp rename to View/Users/edit.ctp diff --git a/views/users/index.ctp b/View/Users/index.ctp similarity index 100% rename from views/users/index.ctp rename to View/Users/index.ctp diff --git a/views/users/login.ctp b/View/Users/login.ctp similarity index 100% rename from views/users/login.ctp rename to View/Users/login.ctp diff --git a/views/users/register.ctp b/View/Users/register.ctp similarity index 100% rename from views/users/register.ctp rename to View/Users/register.ctp diff --git a/views/users/request_password_change.ctp b/View/Users/request_password_change.ctp similarity index 100% rename from views/users/request_password_change.ctp rename to View/Users/request_password_change.ctp diff --git a/views/users/reset_password.ctp b/View/Users/reset_password.ctp similarity index 100% rename from views/users/reset_password.ctp rename to View/Users/reset_password.ctp diff --git a/views/users/search.ctp b/View/Users/search.ctp similarity index 100% rename from views/users/search.ctp rename to View/Users/search.ctp diff --git a/views/users/view.ctp b/View/Users/view.ctp similarity index 100% rename from views/users/view.ctp rename to View/Users/view.ctp From 88aa69cb1c64cc2dd61f617b556f0c23643dbb08 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 22 May 2011 12:23:55 +1000 Subject: [PATCH 02/80] Moved Email elements to view directory --- View/{Elements/email => Emails}/text/account_verification.ctp | 0 View/{Elements/email => Emails}/text/password_reset_request.ctp | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename View/{Elements/email => Emails}/text/account_verification.ctp (100%) rename View/{Elements/email => Emails}/text/password_reset_request.ctp (100%) diff --git a/View/Elements/email/text/account_verification.ctp b/View/Emails/text/account_verification.ctp similarity index 100% rename from View/Elements/email/text/account_verification.ctp rename to View/Emails/text/account_verification.ctp diff --git a/View/Elements/email/text/password_reset_request.ctp b/View/Emails/text/password_reset_request.ctp similarity index 100% rename from View/Elements/email/text/password_reset_request.ctp rename to View/Emails/text/password_reset_request.ctp From a184f52c3457a16d42fcd6100aa779afb7711a29 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 22 May 2011 22:17:13 +1000 Subject: [PATCH 03/80] Moved UsersAppController and UsersAppModel. --- users_app_controller.php => Controller/UsersAppController.php | 0 users_app_model.php => Model/UsersAppModel.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename users_app_controller.php => Controller/UsersAppController.php (100%) rename users_app_model.php => Model/UsersAppModel.php (100%) diff --git a/users_app_controller.php b/Controller/UsersAppController.php similarity index 100% rename from users_app_controller.php rename to Controller/UsersAppController.php diff --git a/users_app_model.php b/Model/UsersAppModel.php similarity index 100% rename from users_app_model.php rename to Model/UsersAppModel.php From ab6bb7715a9950022be40309185855f47690f415 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 22 May 2011 23:13:20 +1000 Subject: [PATCH 04/80] Added App:uses for Security and Model for User model and tests, --- Model/UsersAppModel.php | 2 ++ Test/Fixture/UserFixture.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Model/UsersAppModel.php b/Model/UsersAppModel.php index 7da1756a1..57442d42c 100644 --- a/Model/UsersAppModel.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 * diff --git a/Test/Fixture/UserFixture.php b/Test/Fixture/UserFixture.php index edbb70ddf..39e778a5f 100644 --- a/Test/Fixture/UserFixture.php +++ b/Test/Fixture/UserFixture.php @@ -185,7 +185,7 @@ class UserFixture extends CakeTestFixture { */ public function __construct() { parent::__construct(); - App::import('Core', 'Security'); + App::uses('Lib', 'Security'); foreach ($this->records as &$record) { $record['passwd'] = Security::hash($record['passwd'], null, true); } From e984cb08ea4705980118117a696f8b332a33338b Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 22 May 2011 23:15:11 +1000 Subject: [PATCH 05/80] Updated readme to indicate CakePHP 2.0 required. --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 124c41260..5252bd67b 100644 --- a/readme.md +++ b/readme.md @@ -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) From 6b5875331536f717bd6188176db6a59174c26a11 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 22 May 2011 23:16:10 +1000 Subject: [PATCH 06/80] Change import() to uses() --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 5252bd67b..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'; From 9b21233d402203664e37f12fcfdceb87d0382a1d Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 22 May 2011 23:20:48 +1000 Subject: [PATCH 07/80] Changed 'passwd' to 'password'! --- Controller/UsersController.php | 6 +++--- Model/User.php | 22 ++++++++++---------- Test/Case/Controller/UsersControllerTest.php | 14 ++++++------- Test/Case/Model/UserTest.php | 22 ++++++++++---------- Test/Fixture/UserFixture.php | 16 +++++++------- View/Elements/login.ctp | 5 ++--- View/Users/login.ctp | 2 +- View/Users/register.ctp | 3 +-- config/schema/users.php | 2 +- 9 files changed, 45 insertions(+), 47 deletions(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 7d431718e..98b42dee3 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -266,7 +266,7 @@ public function register() { $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')); } else { - unset($this->data[$this->modelClass]['passwd']); + unset($this->data[$this->modelClass]['password']); 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')); } @@ -386,8 +386,8 @@ public function verify($type = 'email') { unset($data[$this->modelClass]['email']); if ($type === 'reset') { - $newPassword = $data[$this->modelClass]['passwd']; - $data[$this->modelClass]['passwd'] = $this->Auth->password($newPassword); + $newPassword = $data[$this->modelClass]['password']; + $data[$this->modelClass]['password'] = $this->Auth->password($newPassword); } if ($type === 'email') { diff --git a/Model/User.php b/Model/User.php index a5d612014..0d7b5fa22 100644 --- a/Model/User.php +++ b/Model/User.php @@ -107,7 +107,7 @@ public function __construct($id = false, $table = null, $ds = null) { 'isUnique' => array( 'rule' => array('isUnique','email'), 'message' => __d('users', 'This email is already in use.', true))), - 'passwd' => array( + 'password' => array( 'to_short' => array( 'rule' => array('minLength', '6'), 'message' => __d('users', 'The password must have at least 6 characters.', true)), @@ -122,7 +122,7 @@ public function __construct($id = false, $table = null, $ds = null) { 'message' => __d('users', 'You must agree to the terms of use.', true))); $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))), 'old_password' => array( @@ -187,9 +187,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; @@ -237,7 +237,7 @@ public function validateToken($token = null, $reset = false, $now = null) { $data[$this->alias]['email_authenticated'] = '1'; if ($reset === true) { - $data[$this->alias]['passwd'] = $this->generatePassword(); + $data[$this->alias]['password'] = $this->generatePassword(); $data[$this->alias]['password_token'] = null; } @@ -320,7 +320,7 @@ 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'), @@ -329,7 +329,7 @@ public function resetPassword($postData = array()) { $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); } @@ -350,7 +350,7 @@ public function changePassword($postData = array()) { 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)); @@ -375,9 +375,9 @@ public function validateOldPassword($password) { } } - $passwd = $this->field('passwd', array($this->alias . '.id' => $this->data[$this->alias]['id'])); + $password = $this->field('password', array($this->alias . '.id' => $this->data[$this->alias]['id'])); App::import('Core', 'Security'); - if ($passwd === Security::hash($password['old_password'], null, true)) { + if ($password === Security::hash($password['old_password'], null, true)) { return true; } return false; @@ -442,7 +442,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); } diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index a6fe795f2..d9ea8ce25 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -41,7 +41,7 @@ class TestUsersController extends UsersController { public function beforeFilter() { parent::beforeFilter(); $this->Auth->authorize = 'controller'; - $this->Auth->fields = array('username' => 'email', 'password' => 'passwd'); + $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 = '/'; @@ -116,9 +116,9 @@ 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' => 'larry.masters@cakedc.com', 'username' => 'phpnut', 'password' => 'test'), + 'validUser' => array('email' => 'florian.kraemer@cakedc.com', 'username' => 'floriank', 'password' => 'secretkey', 'redirect' => '/user/burzum'), + 'invalidUser' => array('email' => 'wronguser@wronguser.com', 'username' => 'invalidUser', 'password' => 'invalid-password!')); /** * Start test @@ -164,7 +164,7 @@ public function testUserLogin() { 'id' => '1', 'username' => 'testuser', 'slug' => 'testuser', - 'passwd' => Security::hash('test', null, true), + 'password' => Security::hash('test', null, true), )), false); $this->__setPost(array('User' => $this->usersData['admin'])); @@ -199,7 +199,7 @@ public function testRegister() { 'User' => array( 'username' => 'newUser', 'email' => 'newUser@newemail.com', - 'passwd' => 'password', + 'password' => 'password', 'temppassword' => 'password', 'tos' => 1))); $this->Users->beforeFilter(); @@ -210,7 +210,7 @@ public function testRegister() { 'User' => array( 'username' => 'newUser', 'email' => '', - 'passwd' => '', + 'password' => '', 'temppassword' => '', 'tos' => 0))); $this->Users->beforeFilter(); diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index c19c01846..67a6870cc 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -73,11 +73,11 @@ public function testUserInstance() { * @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); } @@ -213,11 +213,11 @@ 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')); + 'password')); $this->assertTrue($this->User->validateOldPassword(array('old_password' => 'password'))); $this->assertFalse($this->User->validateOldPassword(array('old_password' => 'FAIL!'))); } @@ -250,7 +250,7 @@ public function testRegister() { $postData = array('User' => array( 'username' => '#236236326sdg!!!.s#invalid', 'email' => 'invalid', - 'passwd' => 'password', + 'password' => 'password', 'temppassword' => 'wrong', 'tos' => 0)); $result = $this->User->register($postData); @@ -262,26 +262,26 @@ public function testRegister() { $postData = array('User' => array( 'username' => 'validusername', 'email' => 'test@test.com', - 'passwd' => '12345', + 'password' => '12345', 'temppassword' => '12345', 'tos' => 1)); $result = $this->User->register($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)); + $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); @@ -323,7 +323,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)); } /** @@ -425,7 +425,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); diff --git a/Test/Fixture/UserFixture.php b/Test/Fixture/UserFixture.php index 39e778a5f..4cecfe137 100644 --- a/Test/Fixture/UserFixture.php +++ b/Test/Fixture/UserFixture.php @@ -40,7 +40,7 @@ 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'), @@ -68,7 +68,7 @@ class UserFixture extends CakeTestFixture { 'id' => '1', 'username' => 'phpnut', 'slug' => 'phpnut', - 'passwd' => 'test', // test + 'password' => 'test', // test 'password_token' => 'testtoken', 'email' => 'larry.masters@cakedc.com', 'email_authenticated' => 1, @@ -87,7 +87,7 @@ class UserFixture extends CakeTestFixture { 'id' => '47ea303a-3cyc-k251-b313-4811c0a800bf', 'username' => 'floriank', 'slug' => 'floriank', - 'passwd' => 'secretkey', // secretkey + 'password' => 'secretkey', // secretkey 'password_token' => '', 'email' => 'florian.kraemer@cakedc.com', 'email_authenticated' => '1', @@ -106,7 +106,7 @@ 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, @@ -125,7 +125,7 @@ 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, @@ -144,7 +144,7 @@ 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, @@ -163,7 +163,7 @@ 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, @@ -187,7 +187,7 @@ public function __construct() { parent::__construct(); App::uses('Lib', '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/View/Elements/login.ctp b/View/Elements/login.ctp index 7ee85a282..1831e2796 100644 --- a/View/Elements/login.ctp +++ b/View/Elements/login.ctp @@ -19,8 +19,7 @@ if (!$this->Session->check('Auth.Users')) { '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->input('password', array( + 'label' => __d('users', 'Password', true))); echo $this->Form->end(__d('users', 'Login', true)); } diff --git a/View/Users/login.ctp b/View/Users/login.ctp index bbabce902..1615ec8dd 100644 --- a/View/Users/login.ctp +++ b/View/Users/login.ctp @@ -17,7 +17,7 @@ 'action' => 'login')); echo $this->Form->input('email', array( 'label' => __d('users', 'Email', true))); - echo $this->Form->input('passwd', array( + echo $this->Form->input('password', array( 'label' => __d('users', 'Password', true))); echo __d('users', 'Remember Me') . $this->Form->checkbox('remember_me'); echo $this->Form->hidden('User.return_to', array('value' => $return_to)); diff --git a/View/Users/register.ctp b/View/Users/register.ctp index 308b6c1a6..5d1a0295e 100644 --- a/View/Users/register.ctp +++ b/View/Users/register.ctp @@ -26,9 +26,8 @@ '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( + 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), diff --git a/config/schema/users.php b/config/schema/users.php index 343ba9346..1587545aa 100644 --- a/config/schema/users.php +++ b/config/schema/users.php @@ -41,7 +41,7 @@ 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'), From 906f429b6c572bacf53a384c88fddaf55e22988c Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 22 May 2011 23:26:31 +1000 Subject: [PATCH 08/80] Changing translation usage, and minor reformatting of code, --- View/Users/register.ctp | 162 ++++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 82 deletions(-) diff --git a/View/Users/register.ctp b/View/Users/register.ctp index 5d1a0295e..fe0f8426c 100644 --- a/View/Users/register.ctp +++ b/View/Users/register.ctp @@ -9,94 +9,92 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ ?> -Session->read('openIdAuthData');?> -

+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('password', array( - 'label' => __d('users', 'Password',true), - '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)); + if (!isset($openIdAuthData)) { + echo $this->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'), + 'username_min' => __d('users', 'Must be at least 3 characters'), + 'alpha' => __d('users', 'Username must contain numbers and letters only'), + 'required' => __d('users', 'Please choose username')) + )); + echo $this->Form->input('email', array( + 'label' => __d('users', 'E-mail (used as login)'), + 'error' => array('isValid' => __d('users', 'Must be a valid email address'), + 'isUnique' => __d('users', 'An account with that email already exists')) + )); + echo $this->Form->input('password', array( + 'label' => __d('users', 'Password'), + 'error' => __d('users', 'Must be at least 5 characters long') + )); + echo $this->Form->input('temppassword', array( + 'label' => __d('users', 'Password (confirm)'), + 'type' => 'password', + 'error' => __d('users', 'Passwords must match') + )); + echo $this->Form->input('tos', array( + 'label' => __d('users', 'I have read and agreed to ') . $this->Html->link(__d('users', 'Terms of Service'), array('controller' => 'pages', 'action' => 'tos')), + 'error' => __d('users', 'You must verify you have read the Terms of Service') + )); + echo $this->Form->end(__d('users', 'Submit')); + } else { + if (isset($openIdAuthData['openid_claimed_id'])) { + $oid = $openIdAuthData['openid_claimed_id']; } 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) - ) - ); + $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') + )); - if (isset($openIdAuthData['openid_sreg_nickname'])) { - $username = $openIdAuthData['openid_sreg_nickname']; - } else { - $username = ''; - } + 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'), + )); + + if (isset($this->params['named']['username_taken'])) { echo $this->Form->input('username', array( - 'value' => $username, - 'label' => __d('users', 'Username', true), + 'value' => $openIdAuthData['openid_sreg_nickname'], + 'label' => __d('users', 'Username'), )); - - 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)); + if (isset($openIdAuthData['openid_sreg_email'])) { + echo $this->Form->input('email', array( + 'value' => $openIdAuthData['openid_sreg_email'], + 'label' => __d('users', 'Email'), + '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'), + 'type' => 'hidden', + )); } -?> + echo $this->Form->input('tos', array( + 'type' => 'checkbox', + 'label' => __d('users', 'I have read and agreed to ') . $this->Html->link(__d('users', 'Terms of Service'), array('controller' => 'pages', 'action' => 'tos')), + 'error' => __d('users', 'You must verify you have read the Terms of Service') + )); + echo $this->Form->end(__d('users', 'Submit')); + } + ?>
\ No newline at end of file From 82a18ed91902849461386772586df4ac1aad5e98 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 22 May 2011 23:42:31 +1000 Subject: [PATCH 09/80] Updated use of translation strings for all Users views. --- View/Users/admin_add.ctp | 12 ++++----- View/Users/admin_edit.ctp | 14 +++++----- View/Users/admin_index.ctp | 32 +++++++++++------------ View/Users/admin_view.ctp | 24 ++++++++--------- View/Users/change_password.ctp | 17 +++++------- View/Users/dashboard.ctp | 4 +-- View/Users/edit.ctp | 14 +++++----- View/Users/index.ctp | 36 +++++++++++++++----------- View/Users/login.ctp | 15 +++++------ View/Users/register.ctp | 2 +- View/Users/request_password_change.ctp | 21 +++++++-------- View/Users/reset_password.ctp | 20 +++++++------- View/Users/search.ctp | 16 +++++------- View/Users/view.ctp | 20 +++++++------- 14 files changed, 117 insertions(+), 130 deletions(-) diff --git a/View/Users/admin_add.ctp b/View/Users/admin_add.ctp index bd583f141..383b802a8 100644 --- a/View/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'); ?>
    -
  • Html->link(__d('users', 'List Users', true), array('action'=>'index'));?>
  • +
  • Html->link(__d('users', 'List Users'), array('action' => 'index')); ?>
diff --git a/View/Users/admin_edit.ctp b/View/Users/admin_edit.ctp index fbdebb627..32c0fb760 100644 --- a/View/Users/admin_edit.ctp +++ b/View/Users/admin_edit.ctp @@ -10,19 +10,19 @@ */ ?>
-Form->create($model);?> +Form->create($model); ?>
- + Form->input('id'); - echo $this->Form->input('username'); + echo $this->Form->input('id'); + echo $this->Form->input('username'); ?>
-Form->end('Submit');?> +Form->end('Submit'); ?>
    -
  • Html->link(__d('users', 'Delete', true), array('action'=>'delete', $this->Form->value('User.id')), null, sprintf(__d('users', 'Are you sure you want to delete # %s?', true), $this->Form->value('User.id'))); ?>
  • -
  • Html->link(__d('users', 'List Users', true), array('action'=>'index'));?>
  • +
  • Html->link(__d('users', 'Delete'), array('action' => 'delete', $this->Form->value('User.id')), null, sprintf(__d('users', 'Are you sure you want to delete # %s?'), $this->Form->value('User.id'))); ?>
  • +
  • Html->link(__d('users', 'List Users'), array('action' => 'index')); ?>
diff --git a/View/Users/admin_index.ctp b/View/Users/admin_index.ctp index ec0e27349..d29508db0 100644 --- a/View/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 index e0ea3502e..898267180 100644 --- a/View/Users/admin_view.ctp +++ b/View/Users/admin_view.ctp @@ -10,20 +10,20 @@ */ ?>
-

-
- > - > +

+
+ > + >   - > - > + > + >   - > - > + > + >   @@ -31,9 +31,9 @@
    -
  • Html->link(__d('users', 'Edit User', true), array('action'=>'edit', $user[$model]['id'])); ?>
  • -
  • Html->link(__d('users', 'Delete User', 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', 'List Users', true), array('action'=>'index')); ?>
  • -
  • Html->link(__d('users', 'New User', true), array('action'=>'add')); ?>
  • +
  • Html->link(__d('users', 'Edit User'), array('action'=>'edit', $user[$model]['id'])); ?>
  • +
  • Html->link(__d('users', 'Delete User'), array('action'=>'delete', $user[$model]['id']), null, sprintf(__d('users', 'Are you sure you want to delete # %s?'), $user[$model]['id'])); ?>
  • +
  • Html->link(__d('users', 'List Users'), array('action'=>'index')); ?>
  • +
  • Html->link(__d('users', 'New User'), array('action'=>'add')); ?>
diff --git a/View/Users/change_password.ctp b/View/Users/change_password.ctp index 155e08e90..5b70a2b24 100644 --- a/View/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/View/Users/dashboard.ctp b/View/Users/dashboard.ctp index 838833a75..501453f17 100644 --- a/View/Users/dashboard.ctp +++ b/View/Users/dashboard.ctp @@ -10,6 +10,6 @@ */ ?>
-

-

+

+

\ No newline at end of file diff --git a/View/Users/edit.ctp b/View/Users/edit.ctp index 679da5ed8..d33256a7f 100644 --- a/View/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 index ea27ff4e6..c85a56b32 100644 --- a/View/Users/index.ctp +++ b/View/Users/index.ctp @@ -10,18 +10,19 @@ */ ?>
-

-

- + +

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%') )); ?>

+
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'])); ?>
- - - + + + - > + > @@ -39,21 +40,26 @@ foreach ($users as $user):
Paginator->sort('username');?>Paginator->sort('created');?>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'])); ?> + 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', 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')); ?>
    -
  • Html->link(__d('users', 'Register an account', true), array('action' => 'register')); ?>
  • +
  • Html->link(__d('users', 'Register an account'), array('action' => 'register')); ?>
diff --git a/View/Users/login.ctp b/View/Users/login.ctp index 1615ec8dd..6a4a25596 100644 --- a/View/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('password', 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/register.ctp b/View/Users/register.ctp index fe0f8426c..f979f55c0 100644 --- a/View/Users/register.ctp +++ b/View/Users/register.ctp @@ -12,7 +12,7 @@ Session->read('openIdAuthData'); ?>

- + Form->create($model, array('url' => array('action'=>'register'))); diff --git a/View/Users/request_password_change.ctp b/View/Users/request_password_change.ctp index 5c866640a..4e695d9a9 100644 --- a/View/Users/request_password_change.ctp +++ b/View/Users/request_password_change.ctp @@ -9,17 +9,14 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ ?> -

-

- -

+

+

Form->create($model, array( - 'url' => array( - 'admin' => false, - 'action' => 'reset_password'))); +echo $this->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 + '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 index 3e831e48e..823308c80 100644 --- a/View/Users/reset_password.ctp +++ b/View/Users/reset_password.ctp @@ -1,16 +1,14 @@ -

- +

Form->create($model, array( - 'url' => array( - 'action' => 'reset_password', - $token))); +echo $this->Form->create($model, array( + 'url' => array( + 'action' => 'reset_password', + $token))); 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->submit(__d('users', 'Submit', true)); - echo $this->Form->end(); -?> \ No newline at end of file + echo $this->Form->submit(__d('users', 'Submit')); +echo $this->Form->end(); diff --git a/View/Users/search.ctp b/View/Users/search.ctp index 4c8dfa7a8..c1a9612f3 100644 --- a/View/Users/search.ctp +++ b/View/Users/search.ctp @@ -9,14 +9,10 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ ?> -

+

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 +echo $this->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/View/Users/view.ctp b/View/Users/view.ctp index dd5cf3494..38894f3c0 100644 --- a/View/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'] . '
'; } + } ?>
From 557089c157c994dde33826bccbb42ce2e2a8a327 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 22 May 2011 23:43:32 +1000 Subject: [PATCH 10/80] Updated use of translation shortcuts in email views. --- View/Emails/text/account_verification.ctp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/View/Emails/text/account_verification.ctp b/View/Emails/text/account_verification.ctp index 0c372b030..d7ab3910b 100644 --- a/View/Emails/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); From f9eddb9aaedc5dffe0b3724cc7323c5e9a6c3805 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 22 May 2011 23:57:09 +1000 Subject: [PATCH 11/80] Change dtranslation shortcut usage for Details views for CakePHP 2.0 --- View/Details/add.ctp | 12 ++++----- View/Details/admin_add.ctp | 20 +++++++-------- View/Details/admin_edit.ctp | 24 +++++++++--------- View/Details/admin_index.ctp | 29 +++++++++++----------- View/Details/admin_view.ctp | 46 +++++++++++++++++----------------- View/Details/edit.ctp | 17 ++++++------- View/Details/index.ctp | 2 +- View/Details/view.ctp | 48 ++++++++++++++++++------------------ View/Elements/login.ctp | 8 +++--- 9 files changed, 101 insertions(+), 105 deletions(-) diff --git a/View/Details/add.ctp b/View/Details/add.ctp index 766d384c7..0974b463f 100644 --- a/View/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')); ?>
    -
  • Html->link(__d('users', 'List Details', true), array('action'=>'index'));?>
  • -
  • Html->link(__d('users', 'List Users', true), array('controller'=> 'users', 'action'=>'index')); ?>
  • -
  • Html->link(__d('users', 'New User', true), array('controller'=> 'users', 'action'=>'add')); ?>
  • +
  • Html->link(__d('users', 'List Details'), array('action' => 'index')); ?>
  • +
  • Html->link(__d('users', 'List Users'), array('controller' => 'users', 'action' => 'index')); ?>
  • +
  • Html->link(__d('users', 'New User'), array('controller' => 'users', 'action' => 'add')); ?>
diff --git a/View/Details/admin_add.ctp b/View/Details/admin_add.ctp index 766d384c7..1c3efc59a 100644 --- a/View/Details/admin_add.ctp +++ b/View/Details/admin_add.ctp @@ -10,22 +10,22 @@ */ ?>
-Form->create('Detail');?> +Form->create('Detail'); ?>
- + Form->input('user_id'); - echo $this->Form->input('position'); - echo $this->Form->input('field'); - echo $this->Form->input('value'); + echo $this->Form->input('user_id'); + echo $this->Form->input('position'); + echo $this->Form->input('field'); + echo $this->Form->input('value'); ?>
-Form->end('Submit');?> +Form->end(__d('users', 'Submit')); ?>
    -
  • Html->link(__d('users', 'List Details', true), array('action'=>'index'));?>
  • -
  • Html->link(__d('users', 'List Users', true), array('controller'=> 'users', 'action'=>'index')); ?>
  • -
  • Html->link(__d('users', 'New User', true), array('controller'=> 'users', 'action'=>'add')); ?>
  • +
  • Html->link(__d('users', 'List Details'), array('action' => 'index')); ?>
  • +
  • Html->link(__d('users', 'List Users'), array('controller' => 'users', 'action' => 'index')); ?>
  • +
  • Html->link(__d('users', 'New User'), array('controller' => 'users', 'action' => 'add')); ?>
diff --git a/View/Details/admin_edit.ctp b/View/Details/admin_edit.ctp index 4ee6be0a2..26f234b01 100644 --- a/View/Details/admin_edit.ctp +++ b/View/Details/admin_edit.ctp @@ -10,24 +10,24 @@ */ ?>
-Form->create('Detail');?> +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'); + echo $this->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');?> +Form->end('Submit'); ?>
    -
  • Html->link(__d('users', 'Delete', true), array('action'=>'delete', $this->Form->value('Detail.id')), null, sprintf(__d('users', 'Are you sure you want to delete # %s?', true), $this->Form->value('Detail.id'))); ?>
  • -
  • Html->link(__d('users', 'List Details', true), array('action'=>'index'));?>
  • -
  • Html->link(__d('users', 'List Users', true), array('controller'=> 'users', 'action'=>'index')); ?>
  • -
  • Html->link(__d('users', 'New User', true), array('controller'=> 'users', 'action'=>'add')); ?>
  • +
  • Html->link(__d('users', 'Delete'), array('action' => 'delete', $this->Form->value('Detail.id')), null, sprintf(__d('users', 'Are you sure you want to delete # %s?'), $this->Form->value('Detail.id'))); ?>
  • +
  • Html->link(__d('users', 'List Details'), array('action' => 'index'));?>
  • +
  • Html->link(__d('users', 'List Users'), array('controller' => 'users', 'action' => 'index')); ?>
  • +
  • Html->link(__d('users', 'New User'), array('controller' => 'users', 'action' => 'add')); ?>
diff --git a/View/Details/admin_index.ctp b/View/Details/admin_index.ctp index 28d85b202..35a53940e 100644 --- a/View/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')); ?>
    -
  • Html->link(__d('users', 'New Detail', true), array('action'=>'add')); ?>
  • -
  • Html->link(__d('users', 'List Users', true), array('controller'=> 'users', 'action'=>'index')); ?>
  • -
  • Html->link(__d('users', 'New User', true), array('controller'=> 'users', 'action'=>'add')); ?>
  • +
  • Html->link(__d('users', 'New Detail'), array('action' => 'add')); ?>
  • +
  • Html->link(__d('users', 'List Users'), array('controller' => 'users', 'action' => 'index')); ?>
  • +
  • Html->link(__d('users', 'New User'), array('controller' => 'users', 'action' => 'add')); ?>
diff --git a/View/Details/admin_view.ctp b/View/Details/admin_view.ctp index ec425b0c3..49aa9616f 100644 --- a/View/Details/admin_view.ctp +++ b/View/Details/admin_view.ctp @@ -10,40 +10,40 @@ */ ?>
-

-
- > - > +

+
+ > + >   - > - > - 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'])); ?>   - > - > + > + >   - > - > + > + >   - > - > + > + >   - > - > + > + >   - > - > + > + >   @@ -51,11 +51,11 @@
    -
  • Html->link(__d('users', 'Edit Detail', true), array('action'=>'edit', $detail['Detail']['id'])); ?>
  • -
  • Html->link(__d('users', 'Delete Detail', 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', 'List Details', true), array('action'=>'index')); ?>
  • -
  • Html->link(__d('users', 'New Detail', true), array('action'=>'add')); ?>
  • -
  • Html->link(__d('users', 'List Users', true), array('controller'=> 'users', 'action'=>'index')); ?>
  • -
  • Html->link(__d('users', 'New User', true), array('controller'=> 'users', 'action'=>'add')); ?>
  • +
  • Html->link(__d('users', 'Edit Detail'), array('action' => 'edit', $detail['Detail']['id'])); ?>
  • +
  • Html->link(__d('users', 'Delete Detail'), array('action' => 'delete', $detail['Detail']['id']), null, sprintf(__d('users', 'Are you sure you want to delete # %s?'), $detail['Detail']['id'])); ?>
  • +
  • Html->link(__d('users', 'List Details'), array('action' => 'index')); ?>
  • +
  • Html->link(__d('users', 'New Detail'), array('action' => 'add')); ?>
  • +
  • Html->link(__d('users', 'List Users'), array('controller' => 'users', 'action' => 'index')); ?>
  • +
  • Html->link(__d('users', 'New User'), array('controller' => 'users', 'action' => 'add')); ?>
\ No newline at end of file diff --git a/View/Details/edit.ctp b/View/Details/edit.ctp index 9dae678bf..2ef88b84a 100644 --- a/View/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/View/Details/index.ctp b/View/Details/index.ctp index bb23d05c9..9d8df044f 100644 --- a/View/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 index dce0fa870..820b4c6b8 100644 --- a/View/Details/view.ctp +++ b/View/Details/view.ctp @@ -10,40 +10,40 @@ */ ?>
-

-
- > - > +

+
+ > + >   - > - > - 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'])); ?>   - > - > + > + >   - > - > + > + >   - > - > + > + >   - > - > + > + >   - > - > + > + >   @@ -52,11 +52,11 @@
    -
  • Html->link(__d('users', 'Edit Detail', true), array('action'=>'edit', $detail['Detail']['id'])); ?>
  • -
  • Html->link(__d('users', 'Delete Detail', 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', 'List Details', true), array('action'=>'index')); ?>
  • -
  • Html->link(__d('users', 'New Detail', true), array('action'=>'add')); ?>
  • -
  • Html->link(__d('users', 'List Users', true), array('controller'=> 'users', 'action'=>'index')); ?>
  • -
  • Html->link(__d('users', 'New User', true), array('controller'=> 'users', 'action'=>'add')); ?>
  • +
  • Html->link(__d('users', 'Edit Detail'), array('action' => 'edit', $detail['Detail']['id'])); ?>
  • +
  • Html->link(__d('users', 'Delete Detail'), array('action' => 'delete', $detail['Detail']['id']), null, sprintf(__d('users', 'Are you sure you want to delete # %s?'), $detail['Detail']['id'])); ?>
  • +
  • Html->link(__d('users', 'List Details'), array('action' => 'index')); ?>
  • +
  • Html->link(__d('users', 'New Detail'), array('action' => 'add')); ?>
  • +
  • Html->link(__d('users', 'List Users'), array('controller' => 'users', 'action' => 'index')); ?>
  • +
  • Html->link(__d('users', 'New User'), array('controller' => 'users', 'action' => 'add')); ?>
-
\ No newline at end of file +
diff --git a/View/Elements/login.ctp b/View/Elements/login.ctp index 1831e2796..9addebbf0 100644 --- a/View/Elements/login.ctp +++ b/View/Elements/login.ctp @@ -17,9 +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('password', array( - 'label' => __d('users', 'Password', true))); - 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')); } From 75f9761b4bb19d6527e28dbbe356a2b31f46a1bf Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Mon, 23 May 2011 00:01:09 +1000 Subject: [PATCH 12/80] Changed translation shortcut usage in Controllers. --- Controller/DetailsController.php | 44 +++++++++++------------ Controller/UsersController.php | 60 ++++++++++++++++---------------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Controller/DetailsController.php b/Controller/DetailsController.php index 164426b02..d48b0fc21 100644 --- a/Controller/DetailsController.php +++ b/Controller/DetailsController.php @@ -54,8 +54,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 +76,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 +97,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 +115,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 +142,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 +157,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 +176,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 +203,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/Controller/UsersController.php b/Controller/UsersController.php index 98b42dee3..350ee49bd 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -143,9 +143,9 @@ public function view($slug = null) { 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)); + $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')); @@ -179,8 +179,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)); } @@ -192,7 +192,7 @@ public function admin_view($id = null) { */ public function admin_add() { if ($this->User->add($this->data)) { - $this->Session->setFlash(__d('users', 'The User has been saved', true)); + $this->Session->setFlash(__d('users', 'The User has been saved')); $this->redirect(array('action' => 'index')); } } @@ -207,7 +207,7 @@ public function admin_edit($userId = null) { try { $result = $this->User->edit($userId, $this->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; @@ -230,9 +230,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')); @@ -254,7 +254,7 @@ public function admin_search() { */ public function register() { 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('/'); } @@ -263,12 +263,12 @@ public function register() { 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]['password']); 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')); + $this->Session->setFlash(__d('users', 'Your account could not be created. Please, try again.'), 'default', array('class' => 'message warning')); } } @@ -289,7 +289,7 @@ public function login() { $this->Auth->loginRedirect = '/'; } - $this->Session->setFlash(sprintf(__d('users', '%s you have successfully logged in', true), $this->Auth->user('username'))); + $this->Session->setFlash(sprintf(__d('users', '%s you have successfully logged in'), $this->Auth->user('username'))); if (!empty($this->data)) { $data = $this->data[$this->modelClass]; $this->_setCookie(); @@ -351,7 +351,7 @@ public function search() { * @return void */ public function logout() { - $message = sprintf(__d('users', '%s you have successfully logged out', true), $this->Auth->user('username')); + $message = sprintf(__d('users', '%s you have successfully logged out'), $this->Auth->user('username')); $this->Session->destroy(); $this->Cookie->destroy(); @@ -377,7 +377,7 @@ public function verify($type = 'email') { } 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->Session->setFlash(__d('users', 'There url you accessed is not longer valid')); $this->redirect('/'); } @@ -400,27 +400,27 @@ public function verify($type = '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->subject = env('HTTP_HOST') . ' ' . __d('users', 'Password Reset'); $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[] = __d('users', 'Your password has been reset'); + $content[] = __d('users', 'Please login using this password and change your password'); $content[] = $newPassword; $this->Email->send($content); - $this->Session->setFlash(__d('users', 'Your password was sent to your registered email account', true)); + $this->Session->setFlash(__d('users', 'Your password was sent to your registered email account')); $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->Session->setFlash(__d('users', 'Your e-mail has been validated!')); $this->redirect(array('action' => 'login')); } } 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->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.')); $this->redirect('/'); } } else { - $this->Session->setFlash(__d('users', 'The url you accessed is not longer valid', true)); + $this->Session->setFlash(__d('users', 'The url you accessed is not longer valid')); $this->redirect('/'); } } @@ -434,7 +434,7 @@ 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)); + $this->Session->setFlash(__d('users', 'Password changed.')); $this->redirect('/'); } } @@ -489,7 +489,7 @@ 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), + 'subject' => __d('users', 'Account verification'), 'template' => 'account_verification'); $options = array_merge($defaults, $options); @@ -513,7 +513,7 @@ 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), + 'subject' => __d('users', 'Password Reset'), 'template' => 'password_reset_request'); $options = array_merge($defaults, $options); @@ -531,15 +531,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('/')); } } @@ -586,13 +586,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->Session->setFlash(__d('users', 'Password changed, you can now login with your new password.')); $this->redirect($this->Auth->loginAction); } } From 7eb0b2d8df1640fd4f23b2a4acb7f9ed28ddf303 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Mon, 23 May 2011 00:03:24 +1000 Subject: [PATCH 13/80] Fix translation shortcuts in Models, and minor code adjustments. --- Model/User.php | 46 ++++++++++++++++++++--------------------- Model/UsersAppModel.php | 4 +--- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/Model/User.php b/Model/User.php index 0d7b5fa22..fe0b21458 100644 --- a/Model/User.php +++ b/Model/User.php @@ -89,44 +89,44 @@ public function __construct($id = false, $table = null, $ds = null) { 'required' => array( 'rule' => array('notEmpty'), 'required' => true, 'allowEmpty' => false, - 'message' => __d('users', 'Please enter a username', true)), + 'message' => __d('users', 'Please enter a username')), 'alpha' => array( 'rule'=>array('alphaNumeric'), - 'message' => __d('users', 'The username must be alphanumeric', true)), + 'message' => __d('users', 'The username must be alphanumeric')), 'unique_username' => array( 'rule'=>array('isUnique','username'), - 'message' => __d('users', 'This username is already in use.', true)), + 'message' => __d('users', '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' => __d('users', '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' => __d('users', 'Please enter a valid email address.')), 'isUnique' => array( 'rule' => array('isUnique','email'), - 'message' => __d('users', 'This email is already in use.', true))), + 'message' => __d('users', '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' => __d('users', 'The password must have at least 6 characters.')), 'required' => array( 'rule' => 'notEmpty', - 'message' => __d('users', 'Please enter a password.', true))), + 'message' => __d('users', 'Please enter a password.'))), 'temppassword' => array( 'rule' => 'confirmPassword', - 'message' => __d('users', 'The passwords are not equal, please try again.', true)), + 'message' => __d('users', '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' => __d('users', 'You must agree to the terms of use.'))); $this->validatePasswordChange = array( '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.')))); } /** @@ -145,7 +145,7 @@ public function setupDetail() { $this->Detail->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')))); } /** @@ -284,9 +284,9 @@ public function passwordReset($postData = array()) { $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)); + $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; } @@ -324,7 +324,7 @@ public function resetPassword($postData = array()) { '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()) { @@ -371,7 +371,7 @@ 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')); } } @@ -421,7 +421,7 @@ public function view($slug = null) { )))); 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; @@ -458,7 +458,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,17 +468,17 @@ 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)); + $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; } @@ -668,7 +668,7 @@ public function edit($userId = null, $postData = null) { $this->set($user); if (empty($user)) { - throw new OutOfBoundsException(__d('users', 'Invalid User', true)); + throw new OutOfBoundsException(__d('users', 'Invalid User')); } if (!empty($postData)) { diff --git a/Model/UsersAppModel.php b/Model/UsersAppModel.php index 57442d42c..b77d21945 100644 --- a/Model/UsersAppModel.php +++ b/Model/UsersAppModel.php @@ -49,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)); } - } From 825b76ddec078b371508f7ee6a57a62f179c6fcd Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sat, 11 Jun 2011 23:56:13 +0800 Subject: [PATCH 14/80] Fix App:uses for Security class --- Test/Fixture/UserFixture.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Fixture/UserFixture.php b/Test/Fixture/UserFixture.php index 4cecfe137..7d92cca9f 100644 --- a/Test/Fixture/UserFixture.php +++ b/Test/Fixture/UserFixture.php @@ -185,7 +185,7 @@ class UserFixture extends CakeTestFixture { */ public function __construct() { parent::__construct(); - App::uses('Lib', 'Security'); + App::uses('Security', 'Utility'); foreach ($this->records as &$record) { $record['password'] = Security::hash($record['password'], null, true); } From 697800bca596eed63fd20741ea620ac1d59784da Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sat, 11 Jun 2011 23:56:54 +0800 Subject: [PATCH 15/80] Added docblock --- Test/Fixture/UserFixture.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Test/Fixture/UserFixture.php b/Test/Fixture/UserFixture.php index 7d92cca9f..4b4d858e6 100644 --- a/Test/Fixture/UserFixture.php +++ b/Test/Fixture/UserFixture.php @@ -181,7 +181,8 @@ class UserFixture extends CakeTestFixture { ); /** - * + * Constructor + * */ public function __construct() { parent::__construct(); From 9caf54070070f2e4448479be16a9c06ab24f983a Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sat, 11 Jun 2011 23:58:35 +0800 Subject: [PATCH 16/80] Fixed uses for Security class --- Test/Case/Model/UserTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index 67a6870cc..cc22fc12b 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -210,7 +210,7 @@ public function testPasswordReset() { * @return void */ public function testValidateOldPassword() { - App::import('Core', 'Security'); + App::uses('Security', 'Utility'); $password = Security::hash('password', null, true); $this->User->id = '1'; $this->User->saveField('password', $password); @@ -241,7 +241,7 @@ public function testView() { * @return void */ public function testRegister() { - App::import('Core', 'Security'); + App::uses('Security', 'Utility'); $postData = array(); $result = $this->User->register($postData); $this->assertFalse($result); From 2c63af31945a516331e304f13cbe80c6e11c11ef Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 00:00:51 +0800 Subject: [PATCH 17/80] Added doc blocks and fixed plugin name in UserTest --- Test/Case/Model/UserTest.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index cc22fc12b..0f1e2eb0e 100644 --- a/Test/Case/Model/UserTest.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 @@ -40,7 +42,7 @@ class UserTestCase extends CakeTestCase { 'plugin.users.identity'); /** - * + * startTest * * @return void */ @@ -50,7 +52,7 @@ public function startTest() { } /** - * + * endTest * * @return void */ @@ -108,7 +110,7 @@ function testGenerateToken() { } /** - * + * testValidateToken * * @return void */ @@ -126,7 +128,7 @@ function testValidateToken() { } /** - * + * testUpdateLastActivity * * @return void */ @@ -141,7 +143,7 @@ public function testUpdateLastActivity() { } /** - * + * testResetPassword * * @return void */ @@ -171,7 +173,7 @@ public function testResetPassword() { } /** - * + * testCheckPasswordToken * * @return void */ @@ -183,7 +185,7 @@ public function testCheckPasswordToken() { } /** - * + * testPasswordReset * * @return void */ @@ -205,7 +207,7 @@ public function testPasswordReset() { } /** - * + * testValidateOldPassword * * @return void */ @@ -223,7 +225,7 @@ public function testValidateOldPassword() { } /** - * + * testView * * @return void */ From a991c1ceceb0289fc856af25cb89b00c695db778 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 00:48:44 +0800 Subject: [PATCH 18/80] Behaviors now load only if their respective plugins are available. Moved App::uses() to top of class. --- Model/User.php | 39 ++++++++++++++++++++++++++---------- Test/Case/Model/UserTest.php | 2 -- Test/Fixture/UserFixture.php | 3 ++- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Model/User.php b/Model/User.php index fe0b21458..7768ce776 100644 --- a/Model/User.php +++ b/Model/User.php @@ -24,17 +24,6 @@ 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 * @@ -83,7 +72,35 @@ class User extends UsersAppModel { * @param string $ds Datasource */ public function __construct($id = false, $table = null, $ds = null) { + $this->_attachBehaviors(); + $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 _attachBehaviors() { + 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->validate = array( 'username' => array( 'required' => array( diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index 0f1e2eb0e..e9c8f7aee 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -212,7 +212,6 @@ public function testPasswordReset() { * @return void */ public function testValidateOldPassword() { - App::uses('Security', 'Utility'); $password = Security::hash('password', null, true); $this->User->id = '1'; $this->User->saveField('password', $password); @@ -243,7 +242,6 @@ public function testView() { * @return void */ public function testRegister() { - App::uses('Security', 'Utility'); $postData = array(); $result = $this->User->register($postData); $this->assertFalse($result); diff --git a/Test/Fixture/UserFixture.php b/Test/Fixture/UserFixture.php index 4b4d858e6..dfc19f030 100644 --- a/Test/Fixture/UserFixture.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 * @@ -186,7 +188,6 @@ class UserFixture extends CakeTestFixture { */ public function __construct() { parent::__construct(); - App::uses('Security', 'Utility'); foreach ($this->records as &$record) { $record['password'] = Security::hash($record['password'], null, true); } From 151a4f11923bf65f605b944edf3486ca6fd1a6a8 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 00:52:30 +0800 Subject: [PATCH 19/80] Fixed internal type checking on testGenerateToken --- Test/Case/Model/UserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index e9c8f7aee..ba1d84606 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -106,7 +106,7 @@ public function testConfirmEmail() { */ function testGenerateToken() { $result = $this->User->generateToken(); - $this->assertIsA($result, 'string'); + $this->assertInternalType('string', $result); } /** From 42ee8b3776f165e21a94fb6106e4ddd36cd82379 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 01:15:12 +0800 Subject: [PATCH 20/80] Fix internal type checking --- Test/Case/Model/UserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index ba1d84606..27fc8e05f 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -120,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); From 062827377b81468a12da2245bb6d26589305ebd2 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 01:20:00 +0800 Subject: [PATCH 21/80] Fixed testValidateToken test find --- Model/User.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Model/User.php b/Model/User.php index 7768ce776..556847d13 100644 --- a/Model/User.php +++ b/Model/User.php @@ -242,9 +242,9 @@ 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_expires'))); if (!empty($match)){ $expires = strtotime($match[$this->alias]['email_token_expires']); From eebe8fa26030d546475300534910cf1c140b8a81 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 01:21:07 +0800 Subject: [PATCH 22/80] Removing blank lines --- Test/Case/Model/UserTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index 27fc8e05f..ce384513e 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -155,7 +155,6 @@ public function testResetPassword() { 'confirm_password' => 'dsgdsgsdg')); $this->assertFalse($this->User->resetPassword($data)); - $data = array( 'User' => array( 'id' => 1, @@ -163,7 +162,6 @@ public function testResetPassword() { 'confirm_password' => '')); $this->assertFalse($this->User->resetPassword($data)); - $data = array( 'User' => array( 'id' => 1, From cf18c46d39265d13369f53c05800e97af4a88c41 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 01:23:35 +0800 Subject: [PATCH 23/80] Changed App::import of Security to App::uses --- Model/User.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Model/User.php b/Model/User.php index 556847d13..021817480 100644 --- a/Model/User.php +++ b/Model/User.php @@ -9,6 +9,8 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::uses('Security', 'Utility'); + /** * Users Plugin User Model * @@ -345,7 +347,6 @@ public function resetPassword($postData = array()) { $this->set($postData); if ($this->validates()) { - App::import('Core', 'Security'); $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); @@ -366,7 +367,6 @@ public function changePassword($postData = array()) { $this->validate = $this->validatePasswordChange; if ($this->validates()) { - App::import('Core', 'Security'); $this->data[$this->alias]['password'] = Security::hash($this->data[$this->alias]['new_password'], null, true); $this->save($postData, array( 'validate' => false, @@ -393,7 +393,6 @@ public function validateOldPassword($password) { } $password = $this->field('password', array($this->alias . '.id' => $this->data[$this->alias]['id'])); - App::import('Core', 'Security'); if ($password === Security::hash($password['old_password'], null, true)) { return true; } @@ -458,7 +457,6 @@ public function register($postData = array(), $useEmailVerification = true) { $this->set($postData); if ($this->validates()) { - App::import('Core', 'Security'); $postData[$this->alias]['password'] = Security::hash($postData[$this->alias]['password'], 'sha1', true); $this->create(); return $this->save($postData, false); From adf9fb89792810329ec25ac34eaee185c9f78538 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 01:25:20 +0800 Subject: [PATCH 24/80] Changed resetPassword to return a boolean --- Model/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/User.php b/Model/User.php index 021817480..95e752db3 100644 --- a/Model/User.php +++ b/Model/User.php @@ -349,7 +349,7 @@ public function resetPassword($postData = array()) { if ($this->validates()) { $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); + $result = is_array($this->save($this->data, false)); } $this->validate = $tmp; return $result; From 713bb4ab9521ccf1f83ad7bd5ea13b7ad2c842b9 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 01:35:12 +0800 Subject: [PATCH 25/80] Changed resetPassword usage to retain 2.0 returned data instead of boolean true for success. --- Controller/UsersController.php | 8 +++----- Model/User.php | 2 +- Test/Case/Model/UserTest.php | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 350ee49bd..5b0b86a8f 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -590,11 +590,9 @@ private function __resetPassword($token) { $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.')); - $this->redirect($this->Auth->loginAction); - } + if (!empty($this->data) && $this->User->resetPassword(Set::merge($user, $this->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/Model/User.php b/Model/User.php index 95e752db3..021817480 100644 --- a/Model/User.php +++ b/Model/User.php @@ -349,7 +349,7 @@ public function resetPassword($postData = array()) { if ($this->validates()) { $this->data[$this->alias]['password'] = Security::hash($this->data[$this->alias]['new_password'], null, true); $this->data[$this->alias]['password_token'] = null; - $result = is_array($this->save($this->data, false)); + $result = $this->save($this->data, false); } $this->validate = $tmp; return $result; diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index ce384513e..bd71f7087 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -167,7 +167,7 @@ public function testResetPassword() { 'id' => 1, 'new_password' => 'newpassword', 'confirm_password' => 'newpassword')); - $this->assertTrue($this->User->resetPassword($data)); + $this->assertInternalType('array', $this->User->resetPassword($data)); } /** From f96bde249b44599b90175183d3e5036ad8e4ff84 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 01:36:08 +0800 Subject: [PATCH 26/80] Fix docblock typo --- Controller/UsersController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 5b0b86a8f..46b56f08e 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -550,7 +550,7 @@ 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 */ From 6c04c5cebaf36197b26394a538d8a3d64b8724d9 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 01:38:02 +0800 Subject: [PATCH 27/80] Fix internal type check for checkPassword --- Test/Case/Model/UserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index bd71f7087..ce26ebba4 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -178,7 +178,7 @@ public function testResetPassword() { 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->assertInternalType('array', $this->User->checkPasswordToken('testtoken')); $this->assertFalse($this->User->checkPasswordToken('something-wrong-here')); } From bf52305fa344e038788e51a7364e0c2410eb4572 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 01:38:42 +0800 Subject: [PATCH 28/80] Fix internal type check for resetPassword --- Test/Case/Model/UserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index ce26ebba4..7de987ec2 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -201,7 +201,7 @@ public function testPasswordReset() { 'User' => array( 'id' => 1, 'email' => 'larry.masters@cakedc.com')); - $this->assertTrue($this->User->passwordReset($data)); + $this->assertInternalType('array', $this->User->passwordReset($data)); } /** From c2b526fcf5899a8f134760cf53db5e2a6f49acf3 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 01:40:14 +0800 Subject: [PATCH 29/80] Restructure tests for easier debugging --- Test/Case/Model/UserTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index 7de987ec2..8dc40263f 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -217,8 +217,12 @@ public function testValidateOldPassword() { 'User' => array( 'id' => '1', 'password')); - $this->assertTrue($this->User->validateOldPassword(array('old_password' => 'password'))); - $this->assertFalse($this->User->validateOldPassword(array('old_password' => 'FAIL!'))); + + $result = $this->User->validateOldPassword(array('old_password' => 'password')); + $this->assertTrue($result); + + $result = $this->User->validateOldPassword(array('old_password' => 'FAIL!')); + $this->assertFalse($result); } /** From b813258a3b1329e9e567bf5b624561fae041755a Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 02:20:24 +0800 Subject: [PATCH 30/80] Fix implementation of validateOldPassword, error introduced when passwd was changed to password --- Model/User.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Model/User.php b/Model/User.php index 021817480..229da4e02 100644 --- a/Model/User.php +++ b/Model/User.php @@ -392,8 +392,8 @@ public function validateOldPassword($password) { } } - $password = $this->field('password', array($this->alias . '.id' => $this->data[$this->alias]['id'])); - if ($password === Security::hash($password['old_password'], null, true)) { + $current_password = $this->field('password', array($this->alias . '.id' => $this->data[$this->alias]['id'])); + if ($current_password === Security::hash($password['old_password'], null, true)) { return true; } return false; From 667aa6f1dac17af40e2c3050b4c3324f67e2d673 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 02:21:36 +0800 Subject: [PATCH 31/80] Simplified validateOldPassword return --- Model/User.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Model/User.php b/Model/User.php index 229da4e02..7116bc9ec 100644 --- a/Model/User.php +++ b/Model/User.php @@ -393,10 +393,7 @@ public function validateOldPassword($password) { } $current_password = $this->field('password', array($this->alias . '.id' => $this->data[$this->alias]['id'])); - if ($current_password === Security::hash($password['old_password'], null, true)) { - return true; - } - return false; + return $current_password === Security::hash($password['old_password'], null, true); } /** From 9e6a91c0426e4807dcafa7265bd0e951fb597eb5 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 02:22:53 +0800 Subject: [PATCH 32/80] Remove empty lines --- Test/Case/Model/UserTest.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index 8dc40263f..b3ff6cb45 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -194,7 +194,6 @@ 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'))); $data = array( @@ -248,7 +247,6 @@ public function testRegister() { $result = $this->User->register($postData); $this->assertFalse($result); - $postData = array('User' => array( 'username' => '#236236326sdg!!!.s#invalid', 'email' => 'invalid', @@ -260,7 +258,6 @@ public function testRegister() { $this->assertEqual(array_keys($this->User->invalidFields()), array( 'username', 'email', 'temppassword', 'tos')); - $postData = array('User' => array( 'username' => 'validusername', 'email' => 'test@test.com', @@ -272,7 +269,6 @@ public function testRegister() { $this->assertEqual(array_keys($this->User->invalidFields()), array( 'password')); - $postData = array('User' => array( 'username' => 'imanewuser', 'email' => 'foo@bar.com', @@ -300,7 +296,6 @@ public function testChangePassword() { $result = $this->User->changePassword($postData); $this->assertFalse($result); - $postData = array( 'User' => array( 'id' => 1, @@ -312,7 +307,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, @@ -340,7 +334,6 @@ public function testCompareFields() { 'field2' => 'bar')); $this->assertFalse($this->User->compareFields('field1', 'field2')); - $this->User->data = array( 'User' => array( 'field1' => 'foo', @@ -358,19 +351,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')); $this->assertFalse($this->User->resendVerification($postData)); - $postData = array( 'User' => array( 'email' => 'oidtest2@testuser.com')); @@ -388,7 +378,6 @@ public function testGeneratePassword() { $this->assertIsA($result, 'string'); $this->assertEqual(strlen($result), 10); - $result = $this->User->generatePassword(15); $this->assertIsA($result, 'string'); $this->assertEqual(strlen($result), 15); From 59248f7674bcfe53213269a9d0107157d3476013 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 12 Jun 2011 02:39:18 +0800 Subject: [PATCH 33/80] Removed search testing, should be tested in the search plugin. Fixed internal type checking. Removed try/catch, replaced with setExpectedException. --- Test/Case/Model/UserTest.php | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index b3ff6cb45..b2100abbe 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -278,7 +278,6 @@ public function testRegister() { $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']['password'], Security::hash('password', 'sha1', true)); $this->assertTrue(is_string($result['User']['email_token'])); @@ -375,11 +374,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); } @@ -395,17 +394,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 * @@ -439,12 +427,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); } } From fd385c7ef9c7f127f8a8f35b1821f55b0a8a359a Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 15 Jun 2011 21:13:14 +1000 Subject: [PATCH 34/80] Fixed DetailTest so it passes --- Test/Case/Model/DetailTest.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Test/Case/Model/DetailTest.php b/Test/Case/Model/DetailTest.php index f477d6c70..182400cdf 100644 --- a/Test/Case/Model/DetailTest.php +++ b/Test/Case/Model/DetailTest.php @@ -39,10 +39,9 @@ class DetailTestCase extends CakeTestCase { * * @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.Detail'); } /** @@ -51,7 +50,7 @@ public function start() { * @return void */ public function testDetailInstance() { - $this->assertTrue(is_a($this->Detail, 'Detail')); + $this->assertInstanceOf('Detail', $this->Detail); } /** @@ -144,5 +143,4 @@ public function testSaveSection() { $result = $this->Detail->User->field('User.email'); $this->assertEqual($result, 'foo@bar.com'); } - } From 65102fa8ff1588959a3f167ffd9fd6aae4612150 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 15 Jun 2011 22:03:07 +1000 Subject: [PATCH 35/80] Adding App::uses() instead of App::import for reuqired classes --- Controller/DetailsController.php | 2 ++ Controller/UsersController.php | 2 ++ Test/Case/Controller/UsersControllerTest.php | 8 +++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Controller/DetailsController.php b/Controller/DetailsController.php index d48b0fc21..e88b3bab3 100644 --- a/Controller/DetailsController.php +++ b/Controller/DetailsController.php @@ -9,6 +9,8 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::uses('UsersAppController', 'Users.Controller'); + /** * Users Details Controller * diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 46b56f08e..227131940 100644 --- a/Controller/UsersController.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 * diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index d9ea8ce25..a4f1f58a6 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -9,9 +9,11 @@ * @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'); /** * TestUsersController From 6dbcf8fc25b0db6c6aadbeaf4adedbe51ae490e3 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 15 Jun 2011 22:27:31 +1000 Subject: [PATCH 36/80] Added dynamic loading of components and helpers based on availability. Fixed ->params reference to call request object --- Controller/UsersController.php | 64 +++++++++++++++----- Model/User.php | 4 +- Test/Case/Controller/UsersControllerTest.php | 18 +++--- 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 227131940..547be92a7 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -31,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'); /** * $presetVars @@ -50,6 +50,40 @@ class UsersController extends UsersAppController { array('field' => 'username', 'type' => 'value'), array('field' => 'email', 'type' => 'value')); +/** + * Constructor. + * + * @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 __construct($request = null) { + parent::__construct($request); + $this->_setupComponents(); + $this->_setupHelpers(); + } + +/** + * Setup components based on plugin availability + * + * @return void + */ + protected function _setupComponents() { + if (App::import('Component', 'Search.Prg')) { + $this->components[] = 'Search.Prg'; + } + } + +/** + * Setup helpers based on plugin availability + * + * @return void + */ + protected function _setupHelpers() { + if (App::import('Helper', 'Goodies.Gravatar')) { + $this->helpers[] = 'Goodies.Gravatar'; + } + } + /** * beforeFilter callback * @@ -84,9 +118,9 @@ public function index() { $searchTerm = ''; $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; } @@ -106,8 +140,8 @@ public function index() { $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'; } } @@ -303,8 +337,8 @@ public function login() { $this->redirect($this->Auth->redirect($data['return_to'])); } - 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); } @@ -319,16 +353,16 @@ public function search() { $searchTerm = ''; $this->Prg->commonProcess($this->modelClass, $this->modelClass, 'search', false); - if (!empty($this->params['named']['search'])) { - $searchTerm = $this->params['named']['search']; + if (!empty($this->request->params['named']['search'])) { + $searchTerm = $this->request->params['named']['search']; $by = 'any'; } - if (!empty($this->params['named']['username'])) { - $searchTerm = $this->params['named']['username']; + if (!empty($this->request->params['named']['username'])) { + $searchTerm = $this->request->params['named']['username']; $by = 'username'; } - if (!empty($this->params['named']['email'])) { - $searchTerm = $this->params['named']['email']; + if (!empty($this->request->params['named']['email'])) { + $searchTerm = $this->request->params['named']['email']; $by = 'email'; } $this->data[$this->modelClass]['search'] = $searchTerm; diff --git a/Model/User.php b/Model/User.php index 7116bc9ec..5ab93531e 100644 --- a/Model/User.php +++ b/Model/User.php @@ -74,7 +74,7 @@ class User extends UsersAppModel { * @param string $ds Datasource */ public function __construct($id = false, $table = null, $ds = null) { - $this->_attachBehaviors(); + $this->_setupBehaviors(); $this->_setupValidation(); parent::__construct($id, $table, $ds); } @@ -86,7 +86,7 @@ public function __construct($id = false, $table = null, $ds = null) { * * @return void */ - protected function _attachBehaviors() { + protected function _setupBehaviors() { if (App::import('Behavior', 'Search.Searchable')) { $this->actsAs[] = 'Search.Searchable'; } diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index a4f1f58a6..06b311671 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -131,8 +131,8 @@ public function startTest() { Configure::write('App.UserClass', null); $this->Users = new TestUsersController(); $this->Users->constructClasses(); - $this->Users->Component->init($this->Users); - $this->Users->Component->initialize($this->Users); + // $this->Users->Components->init($this->Users); + // $this->Users->Components->initialize($this->Users); $this->Users->params = array( 'pass' => array(), 'named' => array(), @@ -158,8 +158,8 @@ public function testUsersControllerInstance() { * @return void */ public function testUserLogin() { - $this->Users->params['action'] = 'login'; - $this->Users->Component->startup($this->Users); + $this->Users->request->params['action'] = 'login'; + // $this->Users->Components->initialize($this->Users); $this->Users->User->save(array( 'User' => array( @@ -171,7 +171,7 @@ public function testUserLogin() { $this->__setPost(array('User' => $this->usersData['admin'])); $this->Users->beforeFilter(); - $this->Users->params = array( + $this->Users->request->params = array( 'controller' => 'users', 'action' => 'login', 'admin' => false, @@ -179,9 +179,13 @@ public function testUserLogin() { 'url' => array( 'url' => '/users/users/login')); - $this->Users->Component->startup($this->Users); +// $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'); + var_dump($result); + $expected = __d('users', 'testuser 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))); $this->__setPost(array('User' => $this->usersData['invalidUser'])); From 89a49b5fb97a6eff2ca06fd0889727680bcd22a7 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 15 Jun 2011 23:22:42 +1000 Subject: [PATCH 37/80] Separated Auth setup functionality. Fixed post data in UsersController Test --- Controller/UsersController.php | 23 ++++++++++++++------ Test/Case/Controller/UsersControllerTest.php | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 547be92a7..4886af8d6 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -91,21 +91,30 @@ protected function _setupHelpers() { */ public function beforeFilter() { parent::beforeFilter(); + $this->_setupAuth(); + + $this->set('model', $this->modelClass); + + if (!Configure::read('App.defaultEmail')) { + Configure::write('App.defaultEmail', 'noreply@' . env('HTTP_HOST')); + } + } + +/** + * Setup Authentication Component + * + * @return void + */ + public function _setupAuth() { $this->Auth->allow('register', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password'); if ($this->action == 'register') { - $this->Auth->enabled = false; + $this->Components->disable('Auth'); } if ($this->action == 'login') { $this->Auth->autoRedirect = false; } - - $this->set('model', $this->modelClass); - - if (!Configure::read('App.defaultEmail')) { - Configure::write('App.defaultEmail', 'noreply@' . env('HTTP_HOST')); - } } /** diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index 06b311671..393eff944 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -411,7 +411,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')); } /** From a5496a3521ae20415145ca7b0136c20d2fbd8545 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 15 Jun 2011 23:50:31 +1000 Subject: [PATCH 38/80] Fixed CakeRequest not being passed to UsersController in tests --- Test/Case/Controller/UsersControllerTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index 393eff944..c820dc301 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -129,11 +129,11 @@ class UsersControllerTestCase extends CakeTestCase { */ public function startTest() { Configure::write('App.UserClass', null); - $this->Users = new TestUsersController(); + $this->Users = new TestUsersController(new CakeRequest()); $this->Users->constructClasses(); // $this->Users->Components->init($this->Users); // $this->Users->Components->initialize($this->Users); - $this->Users->params = array( + $this->Users->request->params = array( 'pass' => array(), 'named' => array(), 'controller' => 'users', @@ -149,7 +149,7 @@ public function startTest() { * @return void */ public function testUsersControllerInstance() { - $this->assertTrue(is_a($this->Users, 'UsersController')); + $this->assertInstanceOf('UsersController', $this->Users); } /** @@ -182,7 +182,6 @@ public function testUserLogin() { // $this->Users->Component->startup($this->Users); $this->Users->login(); $result = $this->Users->Session->read('Message.flash.message'); - var_dump($result); $expected = __d('users', 'testuser you have successfully logged in', true); $this->assertEqual($result, $expected); From 15c3cd3327613d80b6e1d985bfa63813180e4331 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Thu, 16 Jun 2011 00:14:22 +1000 Subject: [PATCH 39/80] Fixed request URL for 2.0, and changed to use startupProcess to initialize components --- Test/Case/Controller/UsersControllerTest.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index c820dc301..6b3c8f5d2 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -131,8 +131,6 @@ public function startTest() { Configure::write('App.UserClass', null); $this->Users = new TestUsersController(new CakeRequest()); $this->Users->constructClasses(); - // $this->Users->Components->init($this->Users); - // $this->Users->Components->initialize($this->Users); $this->Users->request->params = array( 'pass' => array(), 'named' => array(), @@ -159,7 +157,7 @@ public function testUsersControllerInstance() { */ public function testUserLogin() { $this->Users->request->params['action'] = 'login'; - // $this->Users->Components->initialize($this->Users); + $this->Users->startupProcess(); $this->Users->User->save(array( 'User' => array( @@ -170,16 +168,9 @@ public function testUserLogin() { )), false); $this->__setPost(array('User' => $this->usersData['admin'])); - $this->Users->beforeFilter(); - $this->Users->request->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(); $result = $this->Users->Session->read('Message.flash.message'); $expected = __d('users', 'testuser you have successfully logged in', true); From d49fca5ac8996fc10539c9bb803ede9f9e552bba Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Thu, 16 Jun 2011 00:41:32 +1000 Subject: [PATCH 40/80] Changed fixtures to generic data. Made login tests pass. Commented search for now, until dependency checking is finalised, --- Controller/UsersAppController.php | 11 +++ Controller/UsersController.php | 73 ++++++++++---------- Test/Case/Controller/UsersControllerTest.php | 48 +++++++------ Test/Fixture/UserFixture.php | 12 ++-- 4 files changed, 81 insertions(+), 63 deletions(-) diff --git a/Controller/UsersAppController.php b/Controller/UsersAppController.php index 92b5400ae..ff2cdd581 100644 --- a/Controller/UsersAppController.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/Controller/UsersController.php b/Controller/UsersController.php index 4886af8d6..ce4378060 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -125,7 +125,7 @@ public function _setupAuth() { 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->request->params['named']['search'])) { if (!empty($this->request->params['named']['search'])) { @@ -205,7 +205,7 @@ 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); @@ -326,6 +326,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')); @@ -358,37 +359,37 @@ public function login() { * * @return void */ - 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->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->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); + // } /** * Common logout action @@ -515,7 +516,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')); } @@ -619,7 +622,7 @@ protected function _setCookie($options = array(), $cookieKey = 'User') { $cookieData[$this->Auth->fields['password']] = $this->data[$this->modelClass][$this->Auth->fields['password']]; $this->Cookie->write($cookieKey, $cookieData, true, '1 Month'); } - unset($this->data[$this->modelClass]['remember_me']); + unset($this->request->data[$this->modelClass]['remember_me']); } /** diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index 6b3c8f5d2..f6bb5dd19 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -14,6 +14,7 @@ App::uses('AuthComponent', 'Controller/Component'); App::uses('CookieComponent', 'Controller/Component'); App::uses('SessionComponent', 'Controller/Component'); +App::uses('Security', 'Utility'); /** * TestUsersController @@ -42,7 +43,7 @@ class TestUsersController extends UsersController { */ public function beforeFilter() { parent::beforeFilter(); - $this->Auth->authorize = 'controller'; + $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'); @@ -118,9 +119,20 @@ class UsersControllerTestCase extends CakeTestCase { * @var array */ public $usersData = array( - 'admin' => array('email' => 'larry.masters@cakedc.com', 'username' => 'phpnut', 'password' => 'test'), - 'validUser' => array('email' => 'florian.kraemer@cakedc.com', 'username' => 'floriank', 'password' => 'secretkey', 'redirect' => '/user/burzum'), - 'invalidUser' => array('email' => 'wronguser@wronguser.com', 'username' => 'invalidUser', 'password' => '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 @@ -159,21 +171,13 @@ public function testUserLogin() { $this->Users->request->params['action'] = 'login'; $this->Users->startupProcess(); - $this->Users->User->save(array( - 'User' => array( - 'id' => '1', - 'username' => 'testuser', - 'slug' => 'testuser', - 'password' => Security::hash('test', null, true), - )), false); - $this->__setPost(array('User' => $this->usersData['admin'])); $this->Users->request->url = '/users/users/login'; $this->Users->startupProcess(); $this->Users->login(); $result = $this->Users->Session->read('Message.flash.message'); - $expected = __d('users', 'testuser you have successfully logged in', true); + $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))); @@ -276,15 +280,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 diff --git a/Test/Fixture/UserFixture.php b/Test/Fixture/UserFixture.php index dfc19f030..52fcc90b1 100644 --- a/Test/Fixture/UserFixture.php +++ b/Test/Fixture/UserFixture.php @@ -68,11 +68,11 @@ class UserFixture extends CakeTestFixture { public $records = array( array( 'id' => '1', - 'username' => 'phpnut', - 'slug' => 'phpnut', + 'username' => 'adminuser', + 'slug' => 'adminuser', 'password' => 'test', // test 'password_token' => 'testtoken', - 'email' => 'larry.masters@cakedc.com', + 'email' => 'adminuser@cakedc.com', 'email_authenticated' => 1, 'email_token' => 'testtoken', 'email_token_expires' => '2008-03-25 02:45:46', @@ -87,11 +87,11 @@ class UserFixture extends CakeTestFixture { ), array( 'id' => '47ea303a-3cyc-k251-b313-4811c0a800bf', - 'username' => 'floriank', - 'slug' => 'floriank', + 'username' => 'testuser', + 'slug' => 'testuser', 'password' => 'secretkey', // secretkey 'password_token' => '', - 'email' => 'florian.kraemer@cakedc.com', + 'email' => 'testuser@cakedc.com', 'email_authenticated' => '1', 'email_token' => '', 'email_token_expires' => '2008-03-25 02:45:46', From 0e39e64fac81f889a05bec27cdb73dbf9f38b7be Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Thu, 16 Jun 2011 00:42:53 +1000 Subject: [PATCH 41/80] Fixed failing tests due to Fixture changes --- Test/Case/Controller/UsersControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index f6bb5dd19..14bd990c4 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -245,7 +245,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, '/'); } @@ -327,7 +327,7 @@ public function testResetPassword() { $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')); From 86bd933cdf117df2091bff7f7eb0c650c6544303 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Thu, 16 Jun 2011 00:56:23 +1000 Subject: [PATCH 42/80] Removed loginError, its no longer used. Moved failed login test to a new test method --- Test/Case/Controller/UsersControllerTest.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index 14bd990c4..af8e22cb8 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -49,7 +49,6 @@ public function beforeFilter() { $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( @@ -181,11 +180,16 @@ public function testUserLogin() { $this->assertEqual($result, $expected); $this->assertEqual(Router::normalize($this->Users->redirectUrl), Router::normalize(Router::url($this->Users->Auth->loginRedirect))); - + } + + 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); } /** From 69e5b8c82f35bc31cb468fd44abd924e001020f6 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Thu, 16 Jun 2011 01:00:00 +1000 Subject: [PATCH 43/80] Fixed test for failed login --- Controller/UsersController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index ce4378060..587437c40 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -345,6 +345,8 @@ 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->request->params['named']['return_to'])) { From b0ac4e1bea6324586612cfdffe026a8c371881be Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Thu, 16 Jun 2011 07:44:52 +1000 Subject: [PATCH 44/80] Added doc block for new test --- Test/Case/Controller/UsersControllerTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index af8e22cb8..c302e9c13 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -181,7 +181,12 @@ public function testUserLogin() { $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'])); From 833a0b60dfb7a4460ed57ad2e58266f59c82df70 Mon Sep 17 00:00:00 2001 From: Alejandro Ibarra Date: Fri, 17 Jun 2011 19:28:33 -0430 Subject: [PATCH 45/80] Fixed Unit Tests for UsersController and UserTest (Wrong fixture data). --- .../users.php => Config/Schema/schema.php | 0 .../001_initialize_users_schema.php | 0 {config => Config}/migrations/map.php | 0 Controller/UsersController.php | 73 ++++++++++--------- Model/User.php | 5 +- Test/Case/Controller/UsersControllerTest.php | 26 +++---- Test/Case/Model/UserTest.php | 6 +- View/Users/register.ctp | 1 + 8 files changed, 57 insertions(+), 54 deletions(-) rename config/schema/users.php => Config/Schema/schema.php (100%) rename {config => Config}/migrations/001_initialize_users_schema.php (100%) rename {config => Config}/migrations/map.php (100%) diff --git a/config/schema/users.php b/Config/Schema/schema.php similarity index 100% rename from config/schema/users.php rename to Config/Schema/schema.php diff --git a/config/migrations/001_initialize_users_schema.php b/Config/migrations/001_initialize_users_schema.php similarity index 100% rename from config/migrations/001_initialize_users_schema.php rename to Config/migrations/001_initialize_users_schema.php diff --git a/config/migrations/map.php b/Config/migrations/map.php similarity index 100% rename from config/migrations/map.php rename to Config/migrations/map.php diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 587437c40..c23d95412 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -38,7 +38,7 @@ class UsersController extends UsersAppController { * * @var array */ - public $components = array('Auth', 'Session', 'Email', 'Cookie'); + public $components = array('Auth', 'Session', 'Email', 'Cookie','Paginator'); /** * $presetVars @@ -131,7 +131,7 @@ public function index() { 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( @@ -144,8 +144,6 @@ public function index() { 'AND' => array( $this->modelClass . '.active' => 1, $this->modelClass . '.email_authenticated' => 1)))); - - $this->set('users', $this->paginate($this->modelClass)); $this->set('searchTerm', $searchTerm); @@ -186,14 +184,14 @@ 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')) { + 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.')); } } else { - $this->data = $this->User->read(null, $this->Auth->user('id')); + $this->request->data = $this->User->read(null, $this->Auth->user('id')); } $this->_setLanguages(); @@ -207,10 +205,13 @@ public function edit() { public function admin_index() { // $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()); @@ -236,7 +237,7 @@ public function admin_view($id = null) { * @return void */ public function admin_add() { - if ($this->User->add($this->data)) { + if ($this->User->add($this->request->data)) { $this->Session->setFlash(__d('users', 'The User has been saved')); $this->redirect(array('action' => 'index')); } @@ -250,20 +251,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')); $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); } } @@ -303,16 +304,16 @@ public function register() { $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.')); $this->redirect(array('action' => 'login')); } else { - unset($this->data[$this->modelClass]['password']); - unset($this->data[$this->modelClass]['temppassword']); + 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')); } } @@ -336,8 +337,8 @@ public function login() { } $this->Session->setFlash(sprintf(__d('users', '%s you have successfully logged in'), $this->Auth->user('username'))); - if (!empty($this->data)) { - $data = $this->data[$this->modelClass]; + if (!empty($this->request->data)) { + $data = $this->request->data[$this->modelClass]; $this->_setCookie(); } @@ -377,7 +378,7 @@ public function login() { // $searchTerm = $this->request->params['named']['email']; // $by = 'email'; // } - // $this->data[$this->modelClass]['search'] = $searchTerm; + // $this->request->data[$this->modelClass]['search'] = $searchTerm; // // $this->paginate = array( // 'search', @@ -479,10 +480,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.')); + 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('/'); } } @@ -502,7 +503,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); @@ -540,7 +541,7 @@ protected function _sendVerificationEmail($to = null, $options = array()) { $defaults = array( 'from' => 'noreply@' . env('HTTP_HOST'), 'subject' => __d('users', 'Account verification'), - 'template' => 'account_verification'); + 'template' => 'Users.account_verification'); $options = array_merge($defaults, $options); @@ -564,12 +565,12 @@ protected function _sendPasswordReset($admin = null, $options = array()) { $defaults = array( 'from' => 'noreply@' . env('HTTP_HOST'), 'subject' => __d('users', 'Password Reset'), - 'template' => 'password_reset_request'); + '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']); @@ -605,7 +606,7 @@ protected function _sendPasswordReset($admin = null, $options = array()) { * @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'); @@ -620,8 +621,8 @@ 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->request->data[$this->modelClass]['remember_me']); @@ -640,7 +641,7 @@ private function __resetPassword($token) { $this->redirect(array('action' => 'reset_password')); } - if (!empty($this->data) && $this->User->resetPassword(Set::merge($user, $this->data))) { + 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); } diff --git a/Model/User.php b/Model/User.php index 5ab93531e..3eef7b311 100644 --- a/Model/User.php +++ b/Model/User.php @@ -10,6 +10,7 @@ */ App::uses('Security', 'Utility'); +App::import('Users.UsersAppModel'); /** * Users Plugin User Model @@ -31,7 +32,7 @@ class User extends UsersAppModel { * * @var array */ - public $_findMethods = array('search' => true); + public $findMethods = array('search' => true); /** * @todo comment me @@ -294,7 +295,7 @@ public function passwordReset($postData = array()) { 'conditions' => array( $this->alias . '.active' => 1, $this->alias . '.email' => $postData[$this->alias]['email']))); - + //debug($user); if (!empty($user) && $user[$this->alias]['email_authenticated'] == 1) { $sixtyMins = time() + 43000; $token = $this->generateToken(); diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index c302e9c13..db84871f9 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -149,7 +149,7 @@ public function startTest() { 'admin' => false, 'plugin' => 'users', 'url' => array()); - $this->Users->Email->delivery = 'debug'; + $this->Users->Email->delivery = 'Debug'; } /** @@ -202,9 +202,9 @@ public function testFailedUserLogin() { * */ public function testRegister() { + $_SERVER['HTTP_HOST'] = 'test.com'; $this->Users->params['action'] = 'register'; - - $this->__setPost(array( + $this->__setPost(array( 'User' => array( 'username' => 'newUser', 'email' => 'newUser@newemail.com', @@ -214,8 +214,7 @@ public function testRegister() { $this->Users->beforeFilter(); $this->Users->register(); $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' => '', @@ -264,8 +263,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'])); @@ -277,7 +276,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'); @@ -306,11 +305,11 @@ public function testView() { */ 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, '/'); } @@ -332,6 +331,7 @@ 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( @@ -358,7 +358,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'])); @@ -395,7 +395,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'); diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index b2100abbe..7073baf62 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -199,7 +199,7 @@ public function testPasswordReset() { $data = array( 'User' => array( 'id' => 1, - 'email' => 'larry.masters@cakedc.com')); + 'email' => 'adminuser@cakedc.com')); $this->assertInternalType('array', $this->User->passwordReset($data)); } @@ -230,7 +230,7 @@ public function testValidateOldPassword() { * @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'); @@ -357,7 +357,7 @@ public function testResendVerification() { $postData = array( 'User' => array( - 'email' => 'larry.masters@cakedc.com')); + 'email' => 'adminuser@cakedc.com')); $this->assertFalse($this->User->resendVerification($postData)); $postData = array( diff --git a/View/Users/register.ctp b/View/Users/register.ctp index f979f55c0..9b089ace6 100644 --- a/View/Users/register.ctp +++ b/View/Users/register.ctp @@ -38,6 +38,7 @@ 'error' => __d('users', 'Passwords must match') )); echo $this->Form->input('tos', array( + 'type' => 'checkbox', 'label' => __d('users', 'I have read and agreed to ') . $this->Html->link(__d('users', 'Terms of Service'), array('controller' => 'pages', 'action' => 'tos')), 'error' => __d('users', 'You must verify you have read the Terms of Service') )); From da56b7cd3ea31fbbb771b633711afe5f8c2322a9 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 26 Jun 2011 12:30:47 -0700 Subject: [PATCH 46/80] Moved Details to UserDetails. Changed lots of fields like email_authenticated => email_verified --- Config/Schema/schema.php | 2 +- .../001_initialize_users_schema.php | 8 ++++---- ...ntroller.php => UserDetailsController.php} | 4 ++-- Controller/UsersController.php | 4 ++-- Model/User.php | 20 +++++++++---------- Model/{Detail.php => UserDetail.php} | 4 ++-- Test/Fixture/UserFixture.php | 14 ++++++------- 7 files changed, 28 insertions(+), 28 deletions(-) rename Controller/{DetailsController.php => UserDetailsController.php} (98%) rename Model/{Detail.php => UserDetail.php} (98%) diff --git a/Config/Schema/schema.php b/Config/Schema/schema.php index 1587545aa..fd3691150 100644 --- a/Config/Schema/schema.php +++ b/Config/Schema/schema.php @@ -50,7 +50,7 @@ function after($event = array()) { '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/Config/migrations/001_initialize_users_schema.php b/Config/migrations/001_initialize_users_schema.php index a7e5356e3..c57ce7bdc 100644 --- a/Config/migrations/001_initialize_users_schema.php +++ b/Config/migrations/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_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/Controller/DetailsController.php b/Controller/UserDetailsController.php similarity index 98% rename from Controller/DetailsController.php rename to Controller/UserDetailsController.php index e88b3bab3..7f7225eba 100644 --- a/Controller/DetailsController.php +++ b/Controller/UserDetailsController.php @@ -17,14 +17,14 @@ * @package users * @subpackage users.controllers */ -class DetailsController extends UsersAppController { +class UserDetailsController extends UsersAppController { /** * Name * * @var string */ - public $name = 'Details'; + public $name = 'UserDetails'; /** * Helpers diff --git a/Controller/UsersController.php b/Controller/UsersController.php index c23d95412..32731e440 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -143,7 +143,7 @@ public function index() { 'OR' => array( 'AND' => array( $this->modelClass . '.active' => 1, - $this->modelClass . '.email_authenticated' => 1)))); + $this->modelClass . '.email_verified' => 1)))); $this->set('users', $this->paginate($this->modelClass)); $this->set('searchTerm', $searchTerm); @@ -388,7 +388,7 @@ public function login() { // 'conditions' => array( // 'AND' => array( // $this->modelClass . '.active' => 1, - // $this->modelClass . '.email_authenticated' => 1))); + // $this->modelClass . '.email_verified' => 1))); // // $this->set('users', $this->paginate($this->modelClass)); // $this->set('searchTerm', $searchTerm); diff --git a/Model/User.php b/Model/User.php index 3eef7b311..8b2b1979e 100644 --- a/Model/User.php +++ b/Model/User.php @@ -56,8 +56,8 @@ class User extends UsersAppModel { * @var array */ public $hasMany = array( - 'Detail' => array( - 'className' => 'Users.Detail', + 'UserDetail' => array( + 'className' => 'Users.UserDetail', 'foreign_key' => 'user_id')); /** @@ -254,7 +254,7 @@ public function validateToken($token = null, $reset = false, $now = null) { 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'; if ($reset === true) { $data[$this->alias]['password'] = $this->generatePassword(); @@ -279,7 +279,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; } @@ -296,14 +296,14 @@ public function passwordReset($postData = array()) { $this->alias . '.active' => 1, $this->alias . '.email' => $postData[$this->alias]['email']))); //debug($user); - 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->save($user, false); return $user; - } elseif (!empty($user) && $user[$this->alias]['email_authenticated'] == 0){ + } 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.')); @@ -430,7 +430,7 @@ public function view($slug = null) { $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') )))); @@ -485,7 +485,7 @@ public function resendVerification($postData = array()) { return false; } - if ($user[$this->alias]['email_authenticated'] == 1) { + if ($user[$this->alias]['email_verified'] == 1) { $this->invalidate('email', __d('users', 'Your account is already authenticaed.')); return false; } @@ -552,7 +552,7 @@ protected function _beforeRegistration($postData = array(), $useEmailVerificatio $postData[$this->alias]['email_token'] = $this->generateToken(); $postData[$this->alias]['email_token_expires'] = 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; @@ -705,7 +705,7 @@ public function edit($userId = null, $postData = null) { */ protected function _removeExpiredRegistrations() { $this->deleteAll(array( - $this->alias . '.email_authenticated' => 0, + $this->alias . '.email_verified' => 0, $this->alias . '.email_token_expires <' => date('Y-m-d H:i:s'))); } } diff --git a/Model/Detail.php b/Model/UserDetail.php similarity index 98% rename from Model/Detail.php rename to Model/UserDetail.php index d0a3273cf..803d0466b 100644 --- a/Model/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 diff --git a/Test/Fixture/UserFixture.php b/Test/Fixture/UserFixture.php index 52fcc90b1..528f00aa1 100644 --- a/Test/Fixture/UserFixture.php +++ b/Test/Fixture/UserFixture.php @@ -50,7 +50,7 @@ class UserFixture extends CakeTestFixture { 'email_token_expires' => 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), @@ -78,7 +78,7 @@ class UserFixture extends CakeTestFixture { 'email_token_expires' => '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', @@ -97,7 +97,7 @@ class UserFixture extends CakeTestFixture { 'email_token_expires' => '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', @@ -116,7 +116,7 @@ class UserFixture extends CakeTestFixture { 'email_token_expires' => '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', @@ -135,7 +135,7 @@ class UserFixture extends CakeTestFixture { 'email_token_expires' => '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', @@ -154,7 +154,7 @@ class UserFixture extends CakeTestFixture { 'email_token_expires' => '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', @@ -173,7 +173,7 @@ class UserFixture extends CakeTestFixture { 'email_token_expires' => '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', From fa1f05d5ec2fcaaaa5bb5dd3fdeb3ae2cc8a4f52 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 26 Jun 2011 12:39:22 -0700 Subject: [PATCH 47/80] Fixed expiry field change, and moved paging element to avoid view mess --- Model/User.php | 16 ++++---- View/Users/index.ctp | 88 ++++++++++++++++++++++---------------------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Model/User.php b/Model/User.php index 8757a6b6d..5dadc760a 100644 --- a/Model/User.php +++ b/Model/User.php @@ -247,10 +247,10 @@ public function validateToken($token = null, $reset = false, $now = null) { $data = false; $match = $this->find(array( $this->alias . '.email_token' => $token), - 'id, email, email_token_expires, role'); + 'id, email, email_token_expiry, role'); if (!empty($match)){ - $expires = strtotime($match[$this->alias]['email_token_expires']); + $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']; @@ -263,7 +263,7 @@ public function validateToken($token = null, $reset = false, $now = null) { } $data[$this->alias]['email_token'] = null; - $data[$this->alias]['email_token_expires'] = null; + $data[$this->alias]['email_token_expiry'] = null; } } return $data; @@ -301,7 +301,7 @@ public function passwordReset($postData = array()) { $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_verified'] == 0){ @@ -324,7 +324,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; } @@ -497,7 +497,7 @@ public function resendVerification($postData = array()) { } $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); } @@ -551,7 +551,7 @@ 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_verified'] = 1; } @@ -707,6 +707,6 @@ public function edit($userId = null, $postData = null) { protected function _removeExpiredRegistrations() { $this->deleteAll(array( $this->alias . '.email_verified' => 0, - $this->alias . '.email_token_expires <' => date('Y-m-d H:i:s'))); + $this->alias . '.email_token_expiry <' => date('Y-m-d H:i:s'))); } } diff --git a/View/Users/index.ctp b/View/Users/index.ctp index c85a56b32..ace9a8241 100644 --- a/View/Users/index.ctp +++ b/View/Users/index.ctp @@ -10,53 +10,53 @@ */ ?>
-

+

-

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->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('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->sort('username'); ?>Paginator->sort('created'); ?>
-
-
- Paginator->prev('<< ' . __d('users', 'previous'), array(), null, array('class' => 'disabled')); ?> - | Paginator->numbers(); ?> - Paginator->next(__d('users', 'next') . ' >>', array(), null, array('class' => 'disabled')); ?> + + > + + + + + + + + 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')); ?> +
    From 80d33655c41855290cc285412cf22bf2541b4148 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 26 Jun 2011 12:40:30 -0700 Subject: [PATCH 48/80] Minor html changes --- View/Users/index.ctp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/View/Users/index.ctp b/View/Users/index.ctp index ace9a8241..1b2ef76e6 100644 --- a/View/Users/index.ctp +++ b/View/Users/index.ctp @@ -33,12 +33,8 @@ } ?> > - - - - - - + + Html->link(__d('users', 'View'), array('action' => 'view', $user[$model]['id'])); ?> Html->link(__d('users', 'Edit'), array('action' => 'edit', $user[$model]['id'])); ?> From ddfadfdd2f6dc1fa8ad44d8f28613018e7ebbcc0 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 26 Jun 2011 12:42:24 -0700 Subject: [PATCH 49/80] Changed register action to add --- Controller/UsersController.php | 2 +- View/Users/{register.ctp => add.ctp} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename View/Users/{register.ctp => add.ctp} (100%) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 32731e440..130efbd31 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -298,7 +298,7 @@ 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!')); $this->redirect('/'); diff --git a/View/Users/register.ctp b/View/Users/add.ctp similarity index 100% rename from View/Users/register.ctp rename to View/Users/add.ctp From f86f4405e5b648f9b635754a74af20bf580a5acd Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Fri, 5 Nov 2010 15:00:23 +1100 Subject: [PATCH 50/80] Added class variable for Detail model instance. --- Model/User.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Model/User.php b/Model/User.php index 5dadc760a..76417972d 100644 --- a/Model/User.php +++ b/Model/User.php @@ -67,6 +67,13 @@ class User extends UsersAppModel { */ public $validate = array(); +/** + * Detail model + * + * @var Detail + */ + public $Detail = null; + /** * Constructor * From 0b5ef3c7e30faf165606e79d09d558d3c524f249 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Mon, 8 Nov 2010 16:11:39 +1100 Subject: [PATCH 51/80] Renamed register() action to add() Conflicts: Controller/UsersController.php --- Controller/UsersController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 130efbd31..b85144dfa 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -106,9 +106,9 @@ public function beforeFilter() { * @return void */ public function _setupAuth() { - $this->Auth->allow('register', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password'); + $this->Auth->allow('add', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password'); - if ($this->action == 'register') { + if ($this->action == 'add') { $this->Components->disable('Auth'); } From f99efdcc07087baa405b5bb69892fc98c8f00379 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Mon, 8 Nov 2010 16:43:14 +1100 Subject: [PATCH 52/80] Cleanup user login form. Conflicts: views/users/add.ctp --- View/Users/add.ctp | 167 ++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 84 deletions(-) diff --git a/View/Users/add.ctp b/View/Users/add.ctp index 9b089ace6..318f85e7e 100644 --- a/View/Users/add.ctp +++ b/View/Users/add.ctp @@ -9,93 +9,92 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ ?> -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'), - 'username_min' => __d('users', 'Must be at least 3 characters'), - 'alpha' => __d('users', 'Username must contain numbers and letters only'), - 'required' => __d('users', 'Please choose username')) - )); - echo $this->Form->input('email', array( - 'label' => __d('users', 'E-mail (used as login)'), - 'error' => array('isValid' => __d('users', 'Must be a valid email address'), - 'isUnique' => __d('users', 'An account with that email already exists')) - )); - echo $this->Form->input('password', array( - 'label' => __d('users', 'Password'), - 'error' => __d('users', 'Must be at least 5 characters long') - )); - echo $this->Form->input('temppassword', array( - 'label' => __d('users', 'Password (confirm)'), - 'type' => 'password', - 'error' => __d('users', 'Passwords must match') - )); - echo $this->Form->input('tos', array( - 'type' => 'checkbox', - 'label' => __d('users', 'I have read and agreed to ') . $this->Html->link(__d('users', 'Terms of Service'), array('controller' => 'pages', 'action' => 'tos')), - 'error' => __d('users', 'You must verify you have read the Terms of Service') - )); - echo $this->Form->end(__d('users', 'Submit')); - } else { - if (isset($openIdAuthData['openid_claimed_id'])) { - $oid = $openIdAuthData['openid_claimed_id']; +
    +
    + + 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('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 { - $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') - )); + echo $this->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) + ) + ); - 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'), - )); - - if (isset($this->params['named']['username_taken'])) { + $username = isset($openIdAuthData['openid_sreg_nickname']) ? $openIdAuthData['openid_sreg_nickname'] : ''; echo $this->Form->input('username', array( - 'value' => $openIdAuthData['openid_sreg_nickname'], - 'label' => __d('users', 'Username'), + 'value' => $username, + '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'), - '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'), - 'type' => 'hidden', - )); + 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)); } - echo $this->Form->input('tos', array( - 'type' => 'checkbox', - 'label' => __d('users', 'I have read and agreed to ') . $this->Html->link(__d('users', 'Terms of Service'), array('controller' => 'pages', 'action' => 'tos')), - 'error' => __d('users', 'You must verify you have read the Terms of Service') - )); - echo $this->Form->end(__d('users', 'Submit')); - } - ?> -
    \ No newline at end of file + ?> +
    +
+
+
    +
  • Html->link(__d('users', 'List Users', true), array('action'=>'index'));?>
  • +
+
From 5e378bd5fc51527b9dfe31b63bf2f7ef14f08d3a Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 26 Jun 2011 22:34:14 -0700 Subject: [PATCH 53/80] Export openid to separate view. Fixed AND/OR Mix --- Controller/UsersController.php | 14 +++-- View/Users/add.ctp | 104 +++++++++------------------------ View/Users/openid_add.ctp | 70 ++++++++++++++++++++++ 3 files changed, 107 insertions(+), 81 deletions(-) create mode 100644 View/Users/openid_add.ctp diff --git a/Controller/UsersController.php b/Controller/UsersController.php index b85144dfa..3ff13d96f 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -140,10 +140,8 @@ public function index() { 'order' => $this->modelClass . '.username ASC', 'by' => $searchTerm, 'conditions' => array( - 'OR' => array( - 'AND' => array( - $this->modelClass . '.active' => 1, - $this->modelClass . '.email_verified' => 1)))); + $this->modelClass . '.active' => 1, + $this->modelClass . '.email_verified' => 1)); $this->set('users', $this->paginate($this->modelClass)); $this->set('searchTerm', $searchTerm); @@ -195,6 +193,14 @@ public function edit() { } $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'); + } } /** diff --git a/View/Users/add.ctp b/View/Users/add.ctp index 318f85e7e..aa4cbc5b2 100644 --- a/View/Users/add.ctp +++ b/View/Users/add.ctp @@ -13,83 +13,33 @@
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('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 { - echo $this->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)); - } + echo $this->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('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)); ?>
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)); + ?> +
+
+
+
    +
  • Html->link(__d('users', 'List Users', true), array('action'=>'index'));?>
  • +
+
\ No newline at end of file From 706a76c011763d91d56306f1e6e9029741b15822 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 26 Jun 2011 22:56:18 -0700 Subject: [PATCH 54/80] Echo user add heading --- View/Users/add.ctp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/View/Users/add.ctp b/View/Users/add.ctp index aa4cbc5b2..38d7660ca 100644 --- a/View/Users/add.ctp +++ b/View/Users/add.ctp @@ -11,7 +11,7 @@ ?>
- + Form->create($model); echo $this->Form->input('username', array( From 05920909429e85b66fe04093a72c66f84233d896 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 26 Jun 2011 22:58:46 -0700 Subject: [PATCH 55/80] Move logout message to setFlash --- Controller/UsersController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 3ff13d96f..9220e457c 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -406,11 +406,10 @@ public function login() { * @return void */ public function logout() { - $message = sprintf(__d('users', '%s you have successfully logged out'), $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()); } From 2528fed85c85b5f34415a024a14c9a9d7dba9efa Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 26 Jun 2011 23:13:18 -0700 Subject: [PATCH 56/80] Restructure userscontroller verify --- Controller/UsersController.php | 87 +++++++++++++++------------------- 1 file changed, 38 insertions(+), 49 deletions(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 9220e457c..0e15efcad 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -419,64 +419,53 @@ public function logout() { * @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')); - $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]['password']; - $data[$this->modelClass]['password'] = $this->Auth->password($newPassword); - } - - if ($type === 'email') { - $data[$this->modelClass]['active'] = 1; - } + 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 ($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'); - $this->Email->template = null; - $content[] = __d('users', 'Your password has been reset'); - $content[] = __d('users', 'Please login using this password and change your password'); - $content[] = $newPassword; - $this->Email->send($content); - $this->Session->setFlash(__d('users', 'Your password was sent to your registered email account')); - $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!')); - $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.')); - $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')); - $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('/'); } /** From b6c56fb42f9efbeedb61cf832b86801a7eab307f Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sun, 26 Jun 2011 23:20:24 -0700 Subject: [PATCH 57/80] Update comments --- Controller/UsersController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 0e15efcad..19a8ad591 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -414,7 +414,7 @@ public function logout() { } /** - * Confirm email action + * Confirm email action and password reset action * * @param string $type Type * @return void From d31ef3ed5c51df01ecdb925016361d8b1ad55dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=E4mer?= Date: Tue, 2 Aug 2011 01:33:13 +0200 Subject: [PATCH 58/80] Made the tests accessible again by fixing the naming --- ...ontrollerTest.php => UserDetailsControllerTest.php} | 10 +++++----- Test/Case/Controller/UsersControllerTest.php | 6 +++--- Test/Case/Model/{DetailTest.php => UserDetailTest.php} | 7 +++---- Test/Case/Model/UserTest.php | 10 +++++----- .../{DetailFixture.php => UserDetailFixture.php} | 6 +++--- 5 files changed, 19 insertions(+), 20 deletions(-) rename Test/Case/Controller/{DetailsControllerTest.php => UserDetailsControllerTest.php} (73%) rename Test/Case/Model/{DetailTest.php => UserDetailTest.php} (95%) rename Test/Fixture/{DetailFixture.php => UserDetailFixture.php} (95%) diff --git a/Test/Case/Controller/DetailsControllerTest.php b/Test/Case/Controller/UserDetailsControllerTest.php similarity index 73% rename from Test/Case/Controller/DetailsControllerTest.php rename to Test/Case/Controller/UserDetailsControllerTest.php index 239f3fb08..6acb90c28 100644 --- a/Test/Case/Controller/DetailsControllerTest.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/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index db84871f9..fd425e7d2 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -203,7 +203,7 @@ public function testFailedUserLogin() { */ public function testRegister() { $_SERVER['HTTP_HOST'] = 'test.com'; - $this->Users->params['action'] = 'register'; + $this->Users->params['action'] = 'add'; $this->__setPost(array( 'User' => array( 'username' => 'newUser', @@ -212,7 +212,7 @@ public function testRegister() { '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( 'User' => array( @@ -222,7 +222,7 @@ public function testRegister() { '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)); } diff --git a/Test/Case/Model/DetailTest.php b/Test/Case/Model/UserDetailTest.php similarity index 95% rename from Test/Case/Model/DetailTest.php rename to Test/Case/Model/UserDetailTest.php index 182400cdf..81611748b 100644 --- a/Test/Case/Model/DetailTest.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,8 +31,7 @@ class DetailTestCase extends CakeTestCase { */ public $fixtures = array( 'plugin.users.user', - 'plugin.users.detail', - 'plugin.users.identity'); + 'plugin.users.user_detail'); /** * start @@ -41,7 +40,7 @@ class DetailTestCase extends CakeTestCase { */ public function startTest() { Configure::write('App.UserClass', null); - $this->Detail = ClassRegistry::init('Users.Detail'); + $this->Detail = ClassRegistry::init('Users.UserDetail'); } /** diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index 7073baf62..f5700b73d 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -70,7 +70,7 @@ public function testUserInstance() { } /** - * Test to compare the passwords when a user registers + * Test to compare the passwords when a user adds * * @return void */ @@ -244,7 +244,7 @@ public function testView() { */ public function testRegister() { $postData = array(); - $result = $this->User->register($postData); + $result = $this->User->add($postData); $this->assertFalse($result); $postData = array('User' => array( @@ -253,7 +253,7 @@ public function testRegister() { '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')); @@ -264,7 +264,7 @@ public function testRegister() { '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( 'password')); @@ -275,7 +275,7 @@ public function testRegister() { 'password' => 'password', 'temppassword' => 'password', 'tos' => 1)); - $result = $this->User->register($postData); + $result = $this->User->add($postData); $this->assertTrue(is_array($result)); $this->assertEqual($result['User']['active'], 1); $this->assertEqual($result['User']['password'], Security::hash('password', 'sha1', true)); diff --git a/Test/Fixture/DetailFixture.php b/Test/Fixture/UserDetailFixture.php similarity index 95% rename from Test/Fixture/DetailFixture.php rename to Test/Fixture/UserDetailFixture.php index 3067c3039..66e9ee4c4 100644 --- a/Test/Fixture/DetailFixture.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 From f69abaf68a36fdb674be3da1518fc1503a805fd0 Mon Sep 17 00:00:00 2001 From: Niles Date: Tue, 2 Aug 2011 10:45:45 -0400 Subject: [PATCH 59/80] fix directory name and migrations map for cakephp 2.0 --- .../{migrations => Migration}/001_initialize_users_schema.php | 2 +- Config/{migrations => Migration}/map.php | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename Config/{migrations => Migration}/001_initialize_users_schema.php (99%) rename Config/{migrations => Migration}/map.php (100%) diff --git a/Config/migrations/001_initialize_users_schema.php b/Config/Migration/001_initialize_users_schema.php similarity index 99% rename from Config/migrations/001_initialize_users_schema.php rename to Config/Migration/001_initialize_users_schema.php index c57ce7bdc..41df9dc20 100644 --- a/Config/migrations/001_initialize_users_schema.php +++ b/Config/Migration/001_initialize_users_schema.php @@ -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 From 7b954e71e29d3508fc857a64fa43809d1279183a Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 10 Aug 2011 23:19:52 +1000 Subject: [PATCH 60/80] Changed start and ed test to setup and tesar down --- Test/Case/Model/UserTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index f5700b73d..46b47f33d 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -46,7 +46,7 @@ class UserTestCase extends CakeTestCase { * * @return void */ - public function startTest() { + public function setUp() { Configure::write('App.UserClass', null); $this->User = ClassRegistry::init('Users.User'); } @@ -56,7 +56,7 @@ public function startTest() { * * @return void */ - public function endTest() { + public function tearDown() { unset($this->User); ClassRegistry::flush(); } @@ -66,7 +66,7 @@ public function endTest() { * @return void */ public function testUserInstance() { - $this->assertTrue(is_a($this->User, 'User')); + $this->assertType('User', $this->User); } /** From 5e9c9072da0fa6d84995596f7b18ee6211a969cc Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 10 Aug 2011 23:20:02 +1000 Subject: [PATCH 61/80] Fixed find for token validation --- Model/User.php | 7 ++++--- Test/Fixture/UserFixture.php | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Model/User.php b/Model/User.php index 76417972d..f562732be 100644 --- a/Model/User.php +++ b/Model/User.php @@ -252,9 +252,10 @@ 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_expiry, role'); + $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_expiry']); diff --git a/Test/Fixture/UserFixture.php b/Test/Fixture/UserFixture.php index 528f00aa1..6b376399a 100644 --- a/Test/Fixture/UserFixture.php +++ b/Test/Fixture/UserFixture.php @@ -47,7 +47,7 @@ class UserFixture extends CakeTestFixture { 'email' => array('type'=>'string', 'null' => true, 'default' => NULL), 'email_authenticated' => 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_action' => array('type'=>'datetime', 'null' => true, 'default' => NULL), From 02eeb8d3067eca5384e6040a3e999e8230b4e957 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 10 Aug 2011 23:22:19 +1000 Subject: [PATCH 62/80] Fixed field name on user fixture --- Test/Fixture/UserFixture.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Test/Fixture/UserFixture.php b/Test/Fixture/UserFixture.php index 6b376399a..703c5439e 100644 --- a/Test/Fixture/UserFixture.php +++ b/Test/Fixture/UserFixture.php @@ -75,7 +75,7 @@ class UserFixture extends CakeTestFixture { 'email' => 'adminuser@cakedc.com', 'email_authenticated' => 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_action' => '2008-03-25 02:45:46', @@ -94,7 +94,7 @@ class UserFixture extends CakeTestFixture { 'email' => 'testuser@cakedc.com', 'email_authenticated' => '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_action' => '2008-03-25 02:45:46', @@ -113,7 +113,7 @@ class UserFixture extends CakeTestFixture { 'email' => 'testuser1@testuser.com', 'email_authenticated' => 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_action' => '2008-03-25 02:45:46', @@ -132,7 +132,7 @@ class UserFixture extends CakeTestFixture { 'email' => 'oidtest@testuser.com', 'email_authenticated' => 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_action' => '2008-03-25 02:45:46', @@ -151,7 +151,7 @@ class UserFixture extends CakeTestFixture { 'email' => 'oidtest2@testuser.com', 'email_authenticated' => 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_action' => '2008-03-25 02:45:46', @@ -170,7 +170,7 @@ class UserFixture extends CakeTestFixture { 'email' => 'resetuser@testuser.com', 'email_authenticated' => 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_action' => '2008-03-25 02:45:46', From e4d1be3533f6d681e703d5838eb474d42e67a33f Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 10 Aug 2011 23:23:27 +1000 Subject: [PATCH 63/80] Fixed field name for last_action in users test --- Test/Case/Model/UserTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index 46b47f33d..255e288a0 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -135,9 +135,9 @@ function testValidateToken() { public function testUpdateLastActivity() { $id = '1'; $this->User->id = $id; - $lastDate = $this->User->field('last_activity'); + $lastDate = $this->User->field('last_action'); $this->User->updateLastActivity($id); - $newDate = $this->User->field('last_activity'); + $newDate = $this->User->field('last_action'); $this->assertTrue($lastDate < $newDate); $this->assertFalse($this->User->updateLastActivity('invalid-id!')); } From cd84c2fdb26f14cce3e9c68b2e9d88721a78e8a4 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 10 Aug 2011 23:24:32 +1000 Subject: [PATCH 64/80] Brace spacing --- Model/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/User.php b/Model/User.php index f562732be..265deb2cc 100644 --- a/Model/User.php +++ b/Model/User.php @@ -257,7 +257,7 @@ public function validateToken($token = null, $reset = false, $now = null) { 'fields' => array('id', 'email', 'email_token_expiry', 'role') )); - if (!empty($match)){ + if (!empty($match)) { $expires = strtotime($match[$this->alias]['email_token_expiry']); if ($expires > $now) { $data[$this->alias]['id'] = $match[$this->alias]['id']; From 6fa33b42cf1b23cbd1a808768bb1142fb70cb419 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 10 Aug 2011 23:28:24 +1000 Subject: [PATCH 65/80] Fix expires field name testing --- Test/Case/Model/UserTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index 255e288a0..3a1ddf9b7 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -177,7 +177,7 @@ public function testResetPassword() { */ public function testCheckPasswordToken() { $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'))); $this->assertInternalType('array', $this->User->checkPasswordToken('testtoken')); $this->assertFalse($this->User->checkPasswordToken('something-wrong-here')); } @@ -195,7 +195,7 @@ public function testPasswordReset() { $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, From 88712af9f5f45c5e759db9223fb16e172c41f4dd Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 10 Aug 2011 23:34:00 +1000 Subject: [PATCH 66/80] remove recursion for password resetting --- Model/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/User.php b/Model/User.php index 265deb2cc..a97b4f26f 100644 --- a/Model/User.php +++ b/Model/User.php @@ -300,11 +300,11 @@ 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']))); - //debug($user); if (!empty($user) && $user[$this->alias]['email_verified'] == 1) { $sixtyMins = time() + 43000; $token = $this->generateToken(); From 08453cd5c54486ad5b67257f98a4d0d982638d35 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 10 Aug 2011 23:35:02 +1000 Subject: [PATCH 67/80] Fixed email_authenticated field rename --- Config/Migration/001_initialize_users_schema.php | 2 +- Test/Fixture/UserFixture.php | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Config/Migration/001_initialize_users_schema.php b/Config/Migration/001_initialize_users_schema.php index 41df9dc20..89f7d8f40 100644 --- a/Config/Migration/001_initialize_users_schema.php +++ b/Config/Migration/001_initialize_users_schema.php @@ -53,7 +53,7 @@ class M49c3417a54874a9d276811502cedc421 extends CakeMigration { '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_expiry' => array('type'=>'datetime', 'null' => true, 'default' => NULL), 'tos' => array('type'=>'boolean', 'null' => true, 'default' => '0'), diff --git a/Test/Fixture/UserFixture.php b/Test/Fixture/UserFixture.php index 703c5439e..3e78f5373 100644 --- a/Test/Fixture/UserFixture.php +++ b/Test/Fixture/UserFixture.php @@ -45,7 +45,7 @@ class UserFixture extends CakeTestFixture { '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_expiry' => array('type'=>'datetime', 'null' => true, 'default' => NULL), 'tos' => array('type'=>'boolean', 'null' => true, 'default' => '0'), @@ -73,7 +73,7 @@ class UserFixture extends CakeTestFixture { 'password' => 'test', // test 'password_token' => 'testtoken', 'email' => 'adminuser@cakedc.com', - 'email_authenticated' => 1, + 'email_verified' => 1, 'email_token' => 'testtoken', 'email_token_expiry' => '2008-03-25 02:45:46', 'tos' => 1, @@ -92,7 +92,7 @@ class UserFixture extends CakeTestFixture { 'password' => 'secretkey', // secretkey 'password_token' => '', 'email' => 'testuser@cakedc.com', - 'email_authenticated' => '1', + 'email_verified' => '1', 'email_token' => '', 'email_token_expiry' => '2008-03-25 02:45:46', 'tos' => 1, @@ -111,7 +111,7 @@ class UserFixture extends CakeTestFixture { 'password' => 'newpass', // newpass 'password_token' => '', 'email' => 'testuser1@testuser.com', - 'email_authenticated' => 0, + 'email_verified' => 0, 'email_token' => 'testtoken2', 'email_token_expiry' => '2008-03-28 02:45:46', 'tos' => 0, @@ -130,7 +130,7 @@ class UserFixture extends CakeTestFixture { 'password' => 'newpass', // newpass 'password_token' => '', 'email' => 'oidtest@testuser.com', - 'email_authenticated' => 0, + 'email_verified' => 0, 'email_token' => 'testtoken2', 'email_token_expiry' => '2008-03-28 02:45:46', 'tos' => 0, @@ -149,7 +149,7 @@ class UserFixture extends CakeTestFixture { 'password' => 'newpass', // newpass 'password_token' => '', 'email' => 'oidtest2@testuser.com', - 'email_authenticated' => 0, + 'email_verified' => 0, 'email_token' => 'testtoken2', 'email_token_expiry' => '2008-03-28 02:45:46', 'tos' => 1, @@ -168,7 +168,7 @@ class UserFixture extends CakeTestFixture { 'password' => 'newpass', // newpass 'password_token' => 'testtoken', 'email' => 'resetuser@testuser.com', - 'email_authenticated' => 1, + 'email_verified' => 1, 'email_token' => 'testtoken', 'email_token_expiry' => '2008-03-28 02:45:46', 'tos' => 1, From ad1e6b197c84c6f22680d59f9ff8fcb3ee93e135 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 10 Aug 2011 23:50:35 +1000 Subject: [PATCH 68/80] Fixed UserDetails association and fixture import --- Model/User.php | 2 +- Test/Case/Model/UserTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Model/User.php b/Model/User.php index a97b4f26f..50e594dbe 100644 --- a/Model/User.php +++ b/Model/User.php @@ -434,7 +434,7 @@ public function view($slug = null) { $user = $this->find('first', array( 'contain' => array( //'Tag', - 'Detail'), + 'UserDetail'), 'conditions' => array( $this->alias . '.slug' => $slug, 'OR' => array( diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index 3a1ddf9b7..a9509fab1 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -38,7 +38,7 @@ class UserTestCase extends CakeTestCase { */ public $fixtures = array( 'plugin.users.user', - 'plugin.users.detail', + 'plugin.users.user_detail', 'plugin.users.identity'); /** From 714f83ad064ea477c330a4ecb8f466772f2f9024 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 10 Aug 2011 23:52:07 +1000 Subject: [PATCH 69/80] Added false retun from User::add when data is not saved --- Model/User.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Model/User.php b/Model/User.php index 50e594dbe..6f75acef0 100644 --- a/Model/User.php +++ b/Model/User.php @@ -663,7 +663,7 @@ 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)) { @@ -672,6 +672,7 @@ public function add($postData = null) { return true; } } + return false; } /** From 5313613e82caae205662f58e05a321c2c5cb4b4a Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 10 Aug 2011 23:54:49 +1000 Subject: [PATCH 70/80] Fixed Detail->UserDetail assocation on User --- Model/User.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Model/User.php b/Model/User.php index 6f75acef0..6a4012d0a 100644 --- a/Model/User.php +++ b/Model/User.php @@ -200,8 +200,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->Detail->getSection($row[$this->alias]['id'], $this->alias); } } return $results; @@ -684,10 +684,9 @@ 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)) { From 6b2b0f0ec9a7f5fe64b02ab3e9e3a5c90ada3b22 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 10 Aug 2011 23:56:05 +1000 Subject: [PATCH 71/80] Change Detail instance variable to UserDetail --- Model/User.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Model/User.php b/Model/User.php index 6a4012d0a..4cd68502c 100644 --- a/Model/User.php +++ b/Model/User.php @@ -68,11 +68,11 @@ class User extends UsersAppModel { public $validate = array(); /** - * Detail model + * UserDetail model * - * @var Detail + * @var UserDetail */ - public $Detail = null; + public $UserDetail = null; /** * Constructor @@ -157,19 +157,19 @@ protected function _setupValidation() { } /** - * 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')))); @@ -201,7 +201,7 @@ public function afterSave($created) { public function afterFind($results, $primary = false) { foreach ($results as &$row) { if (isset($row['UserDetail']) && (is_array($row))) { - $row['UserDetail'] = $this->Detail->getSection($row[$this->alias]['id'], $this->alias); + $row['UserDetail'] = $this->UserDetail->getSection($row[$this->alias]['id'], $this->alias); } } return $results; From b2acdc0f8e6392af75a77d461bbb64077a3732c6 Mon Sep 17 00:00:00 2001 From: Alejandro Ibarra Date: Wed, 10 Aug 2011 11:44:09 -0430 Subject: [PATCH 72/80] Fixed construct (Added response parameter) Moved validations declaration to class attribute --- Controller/UsersController.php | 4 +- Model/User.php | 78 +++++++++++++++++----------------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 19a8ad591..b92178eb9 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -56,8 +56,8 @@ class UsersController extends UsersAppController { * @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 __construct($request = null) { - parent::__construct($request); + public function __construct($request, $response) { + parent::__construct($request, $response); $this->_setupComponents(); $this->_setupHelpers(); } diff --git a/Model/User.php b/Model/User.php index 4cd68502c..062a242b8 100644 --- a/Model/User.php +++ b/Model/User.php @@ -59,13 +59,52 @@ class User extends UsersAppModel { 'UserDetail' => array( 'className' => 'Users.UserDetail', 'foreign_key' => 'user_id')); +/** + * Validation domain for translations + */ + public $validationDomain = 'users'; /** * Validation parameters * * @var array */ - public $validate = array(); + public $validate = array( + 'username' => array( + 'required' => array( + 'rule' => array('notEmpty'), + 'required' => true, 'allowEmpty' => false, + 'message' => 'Please enter a username')), + 'alpha' => array( + 'rule' => array('alphaNumeric'), + 'message' => 'The username must be alphanumeric'), + 'unique_username' => array( + 'rule'=>array('isUnique','username'), + 'message' => 'This username is already in use.'), + 'username_min' => array( + 'rule' => array('minLength', '3'), + 'message' => 'The username must have at least 3 characters.'), + 'email' => array( + 'isValid' => array( + 'rule' => 'email', + 'required' => true, + 'message' => 'Please enter a valid email address.')), + 'isUnique' => array( + 'rule' => array('isUnique','email'), + 'message' => 'This email is already in use.'), + 'password' => array( + 'to_short' => array( + 'rule' => array('minLength', '6'), + 'message' => 'The password must have at least 6 characters.'), + 'required' => array( + 'rule' => 'notEmpty', + 'message' => 'Please enter a password.')), + 'temppassword' => array( + 'rule' => 'confirmPassword', + 'message' => 'The passwords are not equal, please try again.'), + 'tos' => array( + 'rule' => array('custom','[1]'), + 'message' => 'You must agree to the terms of use.')); /** * UserDetail model @@ -111,43 +150,6 @@ protected function _setupBehaviors() { * @return void */ protected function _setupValidation() { - $this->validate = array( - 'username' => array( - 'required' => array( - 'rule' => array('notEmpty'), - 'required' => true, 'allowEmpty' => false, - 'message' => __d('users', 'Please enter a username')), - 'alpha' => array( - 'rule'=>array('alphaNumeric'), - 'message' => __d('users', 'The username must be alphanumeric')), - 'unique_username' => array( - 'rule'=>array('isUnique','username'), - 'message' => __d('users', 'This username is already in use.')), - 'username_min' => array( - 'rule' => array('minLength', '3'), - 'message' => __d('users', '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.')), - 'isUnique' => array( - 'rule' => array('isUnique','email'), - 'message' => __d('users', '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.')), - 'required' => array( - 'rule' => 'notEmpty', - 'message' => __d('users', 'Please enter a password.'))), - 'temppassword' => array( - 'rule' => 'confirmPassword', - 'message' => __d('users', '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.'))); - $this->validatePasswordChange = array( 'new_password' => $this->validate['password'], 'confirm_password' => array( From c0a225126b2176c4943a7c2ca2fb0ed28d441e62 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Sat, 13 Aug 2011 09:44:08 +1000 Subject: [PATCH 73/80] Changed passwd to password --- Controller/UsersController.php | 4 ++-- View/Users/add.ctp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index b92178eb9..6f9603bfa 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -435,8 +435,8 @@ public function verify($type = 'email', $token = null) { unset($data[$this->modelClass]['email']); if ($type === 'reset') { - $newPassword = $data[$this->modelClass]['passwd']; - $data[$this->modelClass]['passwd'] = $this->Auth->password($newPassword); + $newPassword = $data[$this->modelClass]['password']; + $data[$this->modelClass]['password'] = $this->Auth->password($newPassword); } if ($type === 'email') { $data[$this->modelClass]['active'] = 1; diff --git a/View/Users/add.ctp b/View/Users/add.ctp index 38d7660ca..5844fb16c 100644 --- a/View/Users/add.ctp +++ b/View/Users/add.ctp @@ -24,7 +24,7 @@ '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( + echo $this->Form->input('password', array( 'label' => __d('users', 'Password',true), 'type' => 'password', 'error' => __d('users', 'Must be at least 5 characters long', true))); From 9635ef9c5d794459a4317fce80899e522312a5f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Tue, 30 Aug 2011 18:34:46 +0200 Subject: [PATCH 74/80] Fixing the validation array, fixing a few test cases --- Model/User.php | 6 +++--- Model/UserDetail.php | 2 +- Test/Case/Model/UserDetailTest.php | 10 ++++++---- Test/Case/Model/UserTest.php | 3 ++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Model/User.php b/Model/User.php index 062a242b8..fa12feb38 100644 --- a/Model/User.php +++ b/Model/User.php @@ -59,6 +59,7 @@ class User extends UsersAppModel { 'UserDetail' => array( 'className' => 'Users.UserDetail', 'foreign_key' => 'user_id')); + /** * Validation domain for translations */ @@ -74,7 +75,7 @@ class User extends UsersAppModel { 'required' => array( 'rule' => array('notEmpty'), 'required' => true, 'allowEmpty' => false, - 'message' => 'Please enter a username')), + 'message' => 'Please enter a username'), 'alpha' => array( 'rule' => array('alphaNumeric'), 'message' => 'The username must be alphanumeric'), @@ -83,7 +84,7 @@ class User extends UsersAppModel { 'message' => 'This username is already in use.'), 'username_min' => array( 'rule' => array('minLength', '3'), - 'message' => 'The username must have at least 3 characters.'), + 'message' => 'The username must have at least 3 characters.')), 'email' => array( 'isValid' => array( 'rule' => 'email', @@ -435,7 +436,6 @@ public function compareFields($field1, $field2) { public function view($slug = null) { $user = $this->find('first', array( 'contain' => array( - //'Tag', 'UserDetail'), 'conditions' => array( $this->alias . '.slug' => $slug, diff --git a/Model/UserDetail.php b/Model/UserDetail.php index 803d0466b..ad18e34c5 100644 --- a/Model/UserDetail.php +++ b/Model/UserDetail.php @@ -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/Test/Case/Model/UserDetailTest.php b/Test/Case/Model/UserDetailTest.php index 81611748b..26041a835 100644 --- a/Test/Case/Model/UserDetailTest.php +++ b/Test/Case/Model/UserDetailTest.php @@ -49,7 +49,7 @@ public function startTest() { * @return void */ public function testDetailInstance() { - $this->assertInstanceOf('Detail', $this->Detail); + $this->assertTrue(is_a($this->Detail, 'UserDetail')); } /** @@ -107,7 +107,7 @@ public function testGetSection() { */ public function testSaveSection() { $data = array( - 'Detail' => array( + 'UserDetail' => array( 'biography' => 'Lipsum...', 'firstname' => 'Florian', 'lastname' => 'Krämer')); @@ -121,7 +121,7 @@ public function testSaveSection() { $data = array( - 'Detail' => array( + 'UserDetail' => array( 'biography' => 'Lipsum...', 'firstname' => 'Foo', 'lastname' => 'Bar')); @@ -135,11 +135,13 @@ 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/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index a9509fab1..463201cd1 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -136,7 +136,8 @@ public function testUpdateLastActivity() { $id = '1'; $this->User->id = $id; $lastDate = $this->User->field('last_action'); - $this->User->updateLastActivity($id); + $this->assertTrue($this->User->updateLastActivity($id)); + $this->User->id = $id; $newDate = $this->User->field('last_action'); $this->assertTrue($lastDate < $newDate); $this->assertFalse($this->User->updateLastActivity('invalid-id!')); From f234a5a98687524b0ff7af0db36bebaa047fb69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Tue, 30 Aug 2011 23:26:40 +0200 Subject: [PATCH 75/80] Fixing more test cases --- Controller/UsersController.php | 2 +- Model/User.php | 12 ++++-------- Test/Case/Controller/UsersControllerTest.php | 9 ++++++--- Test/Case/Model/UserTest.php | 17 ++++++++++------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 6f9603bfa..8d4a0b26c 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -426,7 +426,7 @@ public function verify($type = 'email', $token = null) { } $data = $this->User->validateToken($token, $type === 'reset'); - if (!data) { + if (!$data) { $this->Session->setFlash(__d('users', 'The url you accessed is not longer valid', true)); return $this->redirect('/'); } diff --git a/Model/User.php b/Model/User.php index fa12feb38..f01158841 100644 --- a/Model/User.php +++ b/Model/User.php @@ -107,13 +107,6 @@ class User extends UsersAppModel { 'rule' => array('custom','[1]'), 'message' => 'You must agree to the terms of use.')); -/** - * UserDetail model - * - * @var UserDetail - */ - public $UserDetail = null; - /** * Constructor * @@ -670,7 +663,10 @@ function paginateCount($conditions = array(), $recursive = 0, $extra = array()) 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; } } diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index fd425e7d2..51482d593 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -109,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 @@ -140,7 +139,11 @@ class UsersControllerTestCase extends CakeTestCase { */ public function startTest() { Configure::write('App.UserClass', null); - $this->Users = new TestUsersController(new CakeRequest()); + + $request = new CakeRequest(); + $response = $this->getMock('CakeResponse'); + $this->Users = new TestUsersController($request, $response); + $this->Users->constructClasses(); $this->Users->request->params = array( 'pass' => array(), diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index 463201cd1..0ce8759ba 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -38,8 +38,7 @@ class UserTestCase extends CakeTestCase { */ public $fixtures = array( 'plugin.users.user', - 'plugin.users.user_detail', - 'plugin.users.identity'); + 'plugin.users.user_detail'); /** * startTest @@ -57,6 +56,7 @@ public function setUp() { * @return void */ public function tearDown() { + parent::tearDown(); unset($this->User); ClassRegistry::flush(); } @@ -133,12 +133,13 @@ function testValidateToken() { * @return void */ public function testUpdateLastActivity() { - $id = '1'; + $id = 1; $this->User->id = $id; $lastDate = $this->User->field('last_action'); - $this->assertTrue($this->User->updateLastActivity($id)); + $result = $this->User->updateLastActivity($id); + $this->assertTrue(is_array($result)); $this->User->id = $id; - $newDate = $this->User->field('last_action'); + $newDate = $result['User']['last_action']; $this->assertTrue($lastDate < $newDate); $this->assertFalse($this->User->updateLastActivity('invalid-id!')); } @@ -277,8 +278,10 @@ public function testRegister() { 'temppassword' => 'password', 'tos' => 1)); $result = $this->User->add($postData); - $this->assertTrue(is_array($result)); - $this->assertEqual($result['User']['active'], 1); + $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'])); From 878b83b8a02a84baa8cb8aef477909fc2180c222 Mon Sep 17 00:00:00 2001 From: Ben McClure Date: Mon, 12 Sep 2011 13:18:32 -0500 Subject: [PATCH 76/80] Updated to match the latest Migration schema file. --- Config/Schema/schema.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Config/Schema/schema.php b/Config/Schema/schema.php index fd3691150..0653c4614 100644 --- a/Config/Schema/schema.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'), @@ -44,9 +44,9 @@ function after($event = array()) { '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), From d83a8ed4b174a8d18a8ab5b7c3bcafa32c9918c1 Mon Sep 17 00:00:00 2001 From: Ben McClure Date: Mon, 12 Sep 2011 13:32:16 -0500 Subject: [PATCH 77/80] 'Register an account' link on the index page was pointing to non-existent action 'register'. Changed it to 'add'. --- View/Users/index.ctp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/View/Users/index.ctp b/View/Users/index.ctp index 1b2ef76e6..fa0d4706c 100644 --- a/View/Users/index.ctp +++ b/View/Users/index.ctp @@ -56,6 +56,6 @@
    -
  • Html->link(__d('users', 'Register an account'), array('action' => 'register')); ?>
  • +
  • Html->link(__d('users', 'Register an account'), array('action' => 'add')); ?>
From ec5c4f4f9ea17bf1c89f3174d78e6528e0860425 Mon Sep 17 00:00:00 2001 From: Alejandro Ibarra Date: Fri, 16 Sep 2011 16:34:40 +0200 Subject: [PATCH 78/80] Fixed App:import to App:uses --- Model/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/User.php b/Model/User.php index f01158841..a61030fea 100644 --- a/Model/User.php +++ b/Model/User.php @@ -10,7 +10,7 @@ */ App::uses('Security', 'Utility'); -App::import('Users.UsersAppModel'); +App::uses('UsersAppModel', 'Users.Model'); /** * Users Plugin User Model From b26957425a74cafe7128bfaa6a11818056bd8edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Fri, 30 Sep 2011 16:11:40 +0200 Subject: [PATCH 79/80] Unified the add() and register() method, fixed some more tests by this and changed the 2nd param of register() but kept backward compatibility. --- Controller/UsersController.php | 88 +++++++++++++++++----------------- Model/User.php | 36 ++++++++++---- Test/Case/Model/UserTest.php | 10 ++-- 3 files changed, 78 insertions(+), 56 deletions(-) diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 8d4a0b26c..808642578 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -108,7 +108,7 @@ public function beforeFilter() { public function _setupAuth() { $this->Auth->allow('add', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password'); - if ($this->action == 'add') { + if ($this->action == 'register') { $this->Components->disable('Auth'); } @@ -123,7 +123,6 @@ public function _setupAuth() { * @return void */ public function index() { - //$this->User->contain('Detail'); $searchTerm = ''; //$this->Prg->commonProcess($this->modelClass, $this->modelClass, 'index', false); @@ -193,8 +192,7 @@ public function edit() { } $this->_setLanguages(); - - // Render the OpenID form if that data is present + $oid = $this->Session->read('openIdAuthData'); if ($oid) { $this->autoRender = false; @@ -211,12 +209,12 @@ public function edit() { public function admin_index() { // $this->Prg->commonProcess(); $this->{$this->modelClass}->data[$this->modelClass] = $this->passedArgs; - 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; + 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; @@ -368,37 +366,41 @@ public function login() { * * @return void */ - // 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); - // } + public function search() { + if (!App::import('Component', 'Search.Prg')) { + throw new MissingPluginException(array('plugin' => '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 @@ -406,10 +408,10 @@ public function login() { * @return void */ public function logout() { + $user = $this->Auth->user(); $this->Session->destroy(); $this->Cookie->destroy(); - - $this->Session->setFlash(sprintf(__d('users', '%s you have successfully logged out'), $this->Auth->user('username'))); + $this->Session->setFlash(sprintf(__d('users', '%s you have successfully logged out'), $user[$this->{$this->modelClass}->displayField])); $this->redirect($this->Auth->logout()); } diff --git a/Model/User.php b/Model/User.php index a61030fea..cd349bafd 100644 --- a/Model/User.php +++ b/Model/User.php @@ -434,9 +434,7 @@ public function view($slug = null) { $this->alias . '.slug' => $slug, 'OR' => array( 'AND' => - array($this->alias . '.active' => 1, $this->alias . '.email_verified' => 1), - //array($this->alias . '.active' => 1, $this->alias . '.account_type' => 'remote') - )))); + array($this->alias . '.active' => 1, $this->alias . '.email_verified' => 1))))); if (empty($user)) { throw new Exception(__d('users', 'The user does not exist.')); @@ -448,20 +446,42 @@ public function view($slug = null) { /** * Registers a new user * + * Options: + * - bool emailVerification : Default is true, generates the token for email verification + * - bool removeExpiredRegistrations : Default is true, removes expired registrations to do cleanup when no cron is configured for that + * - bool returnData : Default is true, if false the method returns true/false the data is always available through $this->User->data + * * @param array $postData Post data from controller - * @param boolean $useEmailVerification If set to true a token will be generated + * @param mixed should be array now but can be boolean for emailVerification because of backward compatibility * @return mixed */ - public function register($postData = array(), $useEmailVerification = true) { - $postData = $this->_beforeRegistration($postData, $useEmailVerification); + public function register($postData = array(), $options = array()) { + if (is_bool($options)) { + $options = array('emailVerification' => $options); + } - $this->_removeExpiredRegistrations(); + $defaults = array( + 'emailVerification' => true, + 'removeExpiredRegistrations' => true, + 'returnData' => true); + extract(array_merge($defaults, $options)); + + $postData = $this->_beforeRegistration($postData, $emailVerification); + + if ($removeExpiredRegistrations) { + $this->_removeExpiredRegistrations(); + } $this->set($postData); if ($this->validates()) { $postData[$this->alias]['password'] = Security::hash($postData[$this->alias]['password'], 'sha1', true); $this->create(); - return $this->save($postData, false); + $this->data = $this->save($postData, false); + $this->data[$this->alias]['id'] = $this->id; + if ($returnData) { + return $this->data; + } + return true; } return false; diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php index 0ce8759ba..b03be4c04 100644 --- a/Test/Case/Model/UserTest.php +++ b/Test/Case/Model/UserTest.php @@ -246,7 +246,7 @@ public function testView() { */ public function testRegister() { $postData = array(); - $result = $this->User->add($postData); + $result = $this->User->register($postData); $this->assertFalse($result); $postData = array('User' => array( @@ -255,7 +255,7 @@ public function testRegister() { 'password' => 'password', 'temppassword' => 'wrong', 'tos' => 0)); - $result = $this->User->add($postData); + $result = $this->User->register($postData); $this->assertFalse($result); $this->assertEqual(array_keys($this->User->invalidFields()), array( 'username', 'email', 'temppassword', 'tos')); @@ -266,7 +266,7 @@ public function testRegister() { 'password' => '12345', 'temppassword' => '12345', 'tos' => 1)); - $result = $this->User->add($postData); + $result = $this->User->register($postData); $this->assertFalse($result); $this->assertEqual(array_keys($this->User->invalidFields()), array( 'password')); @@ -277,11 +277,11 @@ public function testRegister() { 'password' => 'password', 'temppassword' => 'password', 'tos' => 1)); - $result = $this->User->add($postData); + $result = $this->User->register($postData, array('returnData' => false)); $this->assertTrue($result); $result = $this->User->data; - $this->assertEqual($result['User']['active'], 0); + $this->assertEqual($result['User']['active'], 1); $this->assertEqual($result['User']['password'], Security::hash('password', 'sha1', true)); $this->assertTrue(is_string($result['User']['email_token'])); From 03e1fea29161f70fb6cb4fb3aa39150fedaaed8c Mon Sep 17 00:00:00 2001 From: ceeram Date: Mon, 24 Oct 2011 15:04:56 +0300 Subject: [PATCH 80/80] fix package location for User model --- Test/Case/Controller/UsersControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Case/Controller/UsersControllerTest.php b/Test/Case/Controller/UsersControllerTest.php index 51482d593..cd4826bda 100644 --- a/Test/Case/Controller/UsersControllerTest.php +++ b/Test/Case/Controller/UsersControllerTest.php @@ -10,7 +10,7 @@ */ App::uses('UsersController', 'Users.Controller'); -App::uses('User', 'Users.User'); +App::uses('User', 'Users.Model'); App::uses('AuthComponent', 'Controller/Component'); App::uses('CookieComponent', 'Controller/Component'); App::uses('SessionComponent', 'Controller/Component');