From c85e513c1f3c334e0f76bb68bdd03c089c957f7d Mon Sep 17 00:00:00 2001 From: Brandon Plasters Date: Tue, 21 Sep 2010 01:40:11 -0400 Subject: [PATCH 01/11] crud actions user variables fixed --- views/users/index.ctp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/users/index.ctp b/views/users/index.ctp index a87620910..2ebc2a9bd 100644 --- a/views/users/index.ctp +++ b/views/users/index.ctp @@ -39,9 +39,9 @@ foreach ($users as $user): - Html->link(__d('users', 'View', true), array('action'=>'view', $user[$model]['id'])); ?> + Html->link(__d('users', 'View', true), array('action'=>'view', $user[$model]['slug'])); ?> 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', 'Delete', true), array('action'=>'delete', $user[$model]['id']), null, sprintf(__d('users', 'Are you sure you want to delete # %s?', true), $user[$model]['username'])); ?> From bebef0228acf015efd79ea85bf5065a910a6d336 Mon Sep 17 00:00:00 2001 From: Brandon Plasters Date: Tue, 21 Sep 2010 03:00:29 -0400 Subject: [PATCH 02/11] added Auth->fields in before filter for login with manual db entry to work --- controllers/users_controller.php | 2 +- views/users/login.ctp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/users_controller.php b/controllers/users_controller.php index 3c289abb3..48db1e8f3 100644 --- a/controllers/users_controller.php +++ b/controllers/users_controller.php @@ -55,6 +55,7 @@ class UsersController extends UsersAppController { */ public function beforeFilter() { parent::beforeFilter(); + $this->Auth->fields = array('username' => 'email', 'password' => 'passwd'); $this->Auth->allow('register', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password'); if ($this->action == 'register') { @@ -310,7 +311,6 @@ 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'])); } else { diff --git a/views/users/login.ctp b/views/users/login.ctp index bbabce902..26c6a64a6 100644 --- a/views/users/login.ctp +++ b/views/users/login.ctp @@ -13,8 +13,8 @@
Form->create($model, array( - 'action' => 'login')); + echo $this->Form->create($model, array('url'=>array( + 'action' => 'login', 'plugin'=>null))); echo $this->Form->input('email', array( 'label' => __d('users', 'Email', true))); echo $this->Form->input('passwd', array( From b769b8430c7104980e98301e8d93f572e4d1e1a4 Mon Sep 17 00:00:00 2001 From: Brandon Plasters Date: Thu, 23 Sep 2010 21:40:27 -0400 Subject: [PATCH 03/11] added admin Routing.prefixes note --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index ce5df404a..d3f714b54 100644 --- a/readme.md +++ b/readme.md @@ -16,6 +16,10 @@ or You will also need the [CakeDC Search plugin](http://github.com/CakeDC/search), just grab it and put it into your application's plugin folder. +If you would like to use admin routing, remember to un-comment the line in app/config/core.php: + + Configure::write('Routing.prefixes', array('admin')); + ## How to use it ## You can use the plugin as it comes if you're happy with it or, more common, extend your app specific user implementation from the plugin. From 21c7b3bb298acb2ce1ba489e1a229c295f57bb3e Mon Sep 17 00:00:00 2001 From: Brandon Plasters Date: Sat, 2 Oct 2010 15:09:55 -0400 Subject: [PATCH 04/11] added 'login' to auth->allow in users controller --- controllers/users_controller.php | 4 +++- tests/cases/controllers/users_controller.test.php | 2 +- views/users/index.ctp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/controllers/users_controller.php b/controllers/users_controller.php index 48db1e8f3..df74cadd3 100644 --- a/controllers/users_controller.php +++ b/controllers/users_controller.php @@ -56,7 +56,7 @@ class UsersController extends UsersAppController { public function beforeFilter() { parent::beforeFilter(); $this->Auth->fields = array('username' => 'email', 'password' => 'passwd'); - $this->Auth->allow('register', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password'); + $this->Auth->allow('register', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password','login'); if ($this->action == 'register') { $this->Auth->enabled = false; @@ -195,6 +195,8 @@ public function admin_add() { if ($this->User->add($this->data)) { $this->Session->setFlash(__d('users', 'The User has been saved', true)); $this->redirect(array('action' => 'index')); + }else{ + $this->Session->setFlash(__d('users', 'The User could not be saved', true)); } } diff --git a/tests/cases/controllers/users_controller.test.php b/tests/cases/controllers/users_controller.test.php index e514056f5..fdee393f4 100644 --- a/tests/cases/controllers/users_controller.test.php +++ b/tests/cases/controllers/users_controller.test.php @@ -264,7 +264,7 @@ public function testView() { $this->assertTrue(isset($this->Users->viewVars['user'])); $this->Users->view('INVALID-SLUG'); - $this->assertEqual($this->Users->redirectUrl, array('action' => 'index')); + $this->assertEqual($this->Users->redirectUrl, '/'); } /** diff --git a/views/users/index.ctp b/views/users/index.ctp index 2ebc2a9bd..1183260b2 100644 --- a/views/users/index.ctp +++ b/views/users/index.ctp @@ -54,6 +54,6 @@ foreach ($users as $user):
    -
  • Html->link(__d('users', 'New User', true), array('action'=>'add')); ?>
  • +
  • Html->link(__d('users', 'New User', true), array('admin'=>true,'action'=>'add')); ?>
From 73947d268ecfa654a4922a5069c26e28eafce5f3 Mon Sep 17 00:00:00 2001 From: Brandon Plasters Date: Sat, 2 Oct 2010 15:14:02 -0400 Subject: [PATCH 05/11] removed plugin=>null in login add form option --- views/users/login.ctp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/users/login.ctp b/views/users/login.ctp index 26c6a64a6..557cb726c 100644 --- a/views/users/login.ctp +++ b/views/users/login.ctp @@ -14,7 +14,7 @@ Form->create($model, array('url'=>array( - 'action' => 'login', 'plugin'=>null))); + 'action' => 'login'))); echo $this->Form->input('email', array( 'label' => __d('users', 'Email', true))); echo $this->Form->input('passwd', array( From e7f31f7f3a54737403a01e69eeab6bedb9d6f5f3 Mon Sep 17 00:00:00 2001 From: Brandon Plasters Date: Sat, 2 Oct 2010 15:44:06 -0400 Subject: [PATCH 06/11] added plugin=>users option to Auth=>loginAction url --- controllers/users_controller.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/controllers/users_controller.php b/controllers/users_controller.php index df74cadd3..ab06d8475 100644 --- a/controllers/users_controller.php +++ b/controllers/users_controller.php @@ -56,6 +56,7 @@ class UsersController extends UsersAppController { public function beforeFilter() { parent::beforeFilter(); $this->Auth->fields = array('username' => 'email', 'password' => 'passwd'); + $this->Auth->loginAction = array('admin' => false, 'plugin'=>'users','controller' => 'users', 'action' => 'login'); $this->Auth->allow('register', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password','login'); if ($this->action == 'register') { @@ -287,7 +288,6 @@ public function login() { if ($this->Auth->user()) { $this->User->id = $this->Auth->user('id'); $this->User->saveField('last_login', date('Y-m-d H:i:s')); - if ($this->here == $this->Auth->loginRedirect) { $this->Auth->loginRedirect = '/'; } @@ -312,6 +312,9 @@ public function login() { $data['return_to'] = null; } $this->redirect($this->Auth->redirect($data['return_to'])); + }else{ + $this->Session->setFlash(sprintf(__d('users', 'Login Incorrect', true))); + $this->data[$this->modelClass][$this->Auth->fields['password']] = null; } if (isset($this->params['named']['return_to'])) { $this->set('return_to', urldecode($this->params['named']['return_to'])); From 2469127aeab5d12c007cfc73a1644b15845e19a4 Mon Sep 17 00:00:00 2001 From: Brandon Plasters Date: Sat, 2 Oct 2010 16:33:12 -0400 Subject: [PATCH 07/11] removed views/users/add.ctp - no corresponding controller action modified add/edit views in admin to work out of the box --- controllers/users_controller.php | 17 ++++++++++++----- views/users/add.ctp | 28 ---------------------------- views/users/admin_add.ctp | 13 +++++++++++-- views/users/admin_edit.ctp | 4 ++++ views/users/edit.ctp | 6 +++++- 5 files changed, 32 insertions(+), 36 deletions(-) delete mode 100644 views/users/add.ctp diff --git a/controllers/users_controller.php b/controllers/users_controller.php index ab06d8475..23cf00b92 100644 --- a/controllers/users_controller.php +++ b/controllers/users_controller.php @@ -193,11 +193,18 @@ public function admin_view($id = null) { * @return void */ public function admin_add() { - if ($this->User->add($this->data)) { - $this->Session->setFlash(__d('users', 'The User has been saved', true)); - $this->redirect(array('action' => 'index')); - }else{ - $this->Session->setFlash(__d('users', 'The User could not be saved', true)); + if($this->data){ + if(isset($this->data[$this->modelClass]['temppassword'])){ + $this->data[$this->modelClass]['temppassword'] = $this->Auth->password($this->data[$this->modelClass]['temppassword']); + } + if ($this->User->add($this->data)) { + $this->Session->setFlash(__d('users', 'The User has been saved', true)); + $this->redirect(array('action' => 'index')); + }else{ + $this->Session->setFlash(__d('users', 'The User could not be saved', true)); + $this->data[$this->modelClass][$this->Auth->fields['password']] = null; + $this->data[$this->modelClass]['temppassword'] = null; + } } } diff --git a/views/users/add.ctp b/views/users/add.ctp deleted file mode 100644 index 12a2f6e4f..000000000 --- a/views/users/add.ctp +++ /dev/null @@ -1,28 +0,0 @@ - -
-Form->create($model);?> -
- - Form->input('username'); - echo $this->Form->input('passwd'); - echo $this->Form->input('password_token'); - ?> -
-Form->end('Submit');?> -
-
-
    -
  • Html->link(__d('users', 'List Users', true), array('action'=>'index'));?>
  • -
-
diff --git a/views/users/admin_add.ctp b/views/users/admin_add.ctp index bd583f141..6865a408b 100644 --- a/views/users/admin_add.ctp +++ b/views/users/admin_add.ctp @@ -9,18 +9,27 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ ?> +
Form->create($model);?>
Form->input('username'); + echo $this->Form->input('passwd'); + echo $this->Form->input('temppassword',array('type'=>'password')); + echo $this->Form->input('email'); + echo $this->Form->input('tos'); + echo $this->Form->input('active'); + echo $this->Form->input('is_admin'); + echo $this->Form->input('role'); ?>
-Form->end('Submit');?> +Form->end(__('Submit', true));?>
  • Html->link(__d('users', 'List Users', true), array('action'=>'index'));?>
-
+ \ No newline at end of file diff --git a/views/users/admin_edit.ctp b/views/users/admin_edit.ctp index fbdebb627..1f95d815f 100644 --- a/views/users/admin_edit.ctp +++ b/views/users/admin_edit.ctp @@ -16,6 +16,10 @@ Form->input('id'); echo $this->Form->input('username'); + echo $this->Form->input('email'); + echo $this->Form->input('active'); + echo $this->Form->input('is_admin'); + echo $this->Form->input('role'); ?>
Form->end('Submit');?> diff --git a/views/users/edit.ctp b/views/users/edit.ctp index 85f8745c8..aae2483de 100644 --- a/views/users/edit.ctp +++ b/views/users/edit.ctp @@ -22,4 +22,8 @@ echo $this->Form->input('Addon'); ?> -Form->end('Submit');?> \ No newline at end of file +Form->end('Submit');?> + + + Html->link(__d('users', 'List Users', true), array('action'=>'index')); ?> + \ No newline at end of file From 71543956b5d7736690f49e7704a23eaeb483552f Mon Sep 17 00:00:00 2001 From: Brandon Plasters Date: Sat, 2 Oct 2010 17:08:28 -0400 Subject: [PATCH 08/11] added data check for flash messages --- controllers/users_controller.php | 60 +++++++++++++++++--------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/controllers/users_controller.php b/controllers/users_controller.php index 23cf00b92..019e04a30 100644 --- a/controllers/users_controller.php +++ b/controllers/users_controller.php @@ -57,6 +57,7 @@ public function beforeFilter() { parent::beforeFilter(); $this->Auth->fields = array('username' => 'email', 'password' => 'passwd'); $this->Auth->loginAction = array('admin' => false, 'plugin'=>'users','controller' => 'users', 'action' => 'login'); + $this->Auth->logoutRedirect = array('admin' => false, 'plugin'=>'users','controller' => 'users', 'action' => 'index'); $this->Auth->allow('register', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password','login'); if ($this->action == 'register') { @@ -292,36 +293,38 @@ public function register() { * @return void */ public function login() { - if ($this->Auth->user()) { - $this->User->id = $this->Auth->user('id'); - $this->User->saveField('last_login', date('Y-m-d H:i:s')); - if ($this->here == $this->Auth->loginRedirect) { - $this->Auth->loginRedirect = '/'; - } - - $this->Session->setFlash(sprintf(__d('users', '%s you have successfully logged in', true), $this->Auth->user('username'))); - if (!empty($this->data)) { - $data = $this->data[$this->modelClass]; - - $this->Cookie->name = 'rememberMe'; - if (!isset($this->data[$this->modelClass]['remember_me'])) { - $this->Cookie->delete($this->modelClass); - } else { - $cookie = array(); - $cookie[$this->Auth->fields['username']] = $this->data[$this->modelClass][$this->Auth->fields['username']]; - $cookie[$this->Auth->fields['password']] = $this->data[$this->modelClass][$this->Auth->fields['password']]; - $this->Cookie->write($this->modelClass, $cookie, true, '1 Month'); + if($this->data){ + if ($this->Auth->user()) { + $this->User->id = $this->Auth->user('id'); + $this->User->saveField('last_login', date('Y-m-d H:i:s')); + if ($this->here == $this->Auth->loginRedirect) { + $this->Auth->loginRedirect = '/'; } - unset($this->data[$this->modelClass]['remember_me']); - } - - if (empty($data['return_to'])) { - $data['return_to'] = null; + + $this->Session->setFlash(sprintf(__d('users', '%s you have successfully logged in', true), $this->Auth->user('username'))); + if (!empty($this->data)) { + $data = $this->data[$this->modelClass]; + + $this->Cookie->name = 'rememberMe'; + if (!isset($this->data[$this->modelClass]['remember_me'])) { + $this->Cookie->delete($this->modelClass); + } else { + $cookie = array(); + $cookie[$this->Auth->fields['username']] = $this->data[$this->modelClass][$this->Auth->fields['username']]; + $cookie[$this->Auth->fields['password']] = $this->data[$this->modelClass][$this->Auth->fields['password']]; + $this->Cookie->write($this->modelClass, $cookie, true, '1 Month'); + } + unset($this->data[$this->modelClass]['remember_me']); + } + + if (empty($data['return_to'])) { + $data['return_to'] = null; + } + $this->redirect($this->Auth->redirect($data['return_to'])); + }else{ + $this->Session->setFlash(sprintf(__d('users', 'Login Incorrect', true))); + $this->data[$this->modelClass][$this->Auth->fields['password']] = null; } - $this->redirect($this->Auth->redirect($data['return_to'])); - }else{ - $this->Session->setFlash(sprintf(__d('users', 'Login Incorrect', true))); - $this->data[$this->modelClass][$this->Auth->fields['password']] = null; } if (isset($this->params['named']['return_to'])) { $this->set('return_to', urldecode($this->params['named']['return_to'])); @@ -376,7 +379,6 @@ public function logout() { $message = sprintf(__d('users', '%s you have successfully logged out', true), $this->Auth->user('username')); $this->Session->destroy(); $this->Cookie->destroy(); - $this->Session->setFlash($message); $this->redirect($this->Auth->logout()); } From a26a77f1905976146bb45465719fa365e9063c80 Mon Sep 17 00:00:00 2001 From: Brandon Plasters Date: Sat, 2 Oct 2010 17:11:20 -0400 Subject: [PATCH 09/11] updated readme --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index d3f714b54..56a6e094c 100644 --- a/readme.md +++ b/readme.md @@ -4,6 +4,8 @@ The users plugin is for allowing users to register and login manage their profil The plugin is thought as a base to extend your app specific users controller and model from. +This fork is modified to work out of the box. + ## Installation ## The plugin is pretty easy to set up, all you need to do is to copy it to you application plugins folder and load the needed tables. You can create database tables using either the schema shell or the [CakeDC Migrations plugin](http://github.com/CakeDC/migrations): From b7a007f3e48acac2f8dd405622424c4e6caee001 Mon Sep 17 00:00:00 2001 From: Brandon Plasters Date: Sat, 2 Oct 2010 17:18:30 -0400 Subject: [PATCH 10/11] added elements/paging.ctp; fetched cakedc changes --- views/elements/paging.ctp | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 views/elements/paging.ctp diff --git a/views/elements/paging.ctp b/views/elements/paging.ctp new file mode 100644 index 000000000..77d7fc705 --- /dev/null +++ b/views/elements/paging.ctp @@ -0,0 +1,7 @@ +Paginator->counter(array( + 'format' => 'Page %page% of %pages%, + showing %current% records out of %count% total, + starting on record %start%, ending on %end%' +)); +?> \ No newline at end of file From 1f0c706569f00a8e3d9b380380cf9294086087d4 Mon Sep 17 00:00:00 2001 From: Brandon Plasters Date: Sat, 2 Oct 2010 21:20:09 -0400 Subject: [PATCH 11/11] removed defined auth variables from users_controller beforFilter --- controllers/users_controller.php | 2 -- views/users/index.ctp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/controllers/users_controller.php b/controllers/users_controller.php index 019e04a30..12641c688 100644 --- a/controllers/users_controller.php +++ b/controllers/users_controller.php @@ -56,8 +56,6 @@ class UsersController extends UsersAppController { public function beforeFilter() { parent::beforeFilter(); $this->Auth->fields = array('username' => 'email', 'password' => 'passwd'); - $this->Auth->loginAction = array('admin' => false, 'plugin'=>'users','controller' => 'users', 'action' => 'login'); - $this->Auth->logoutRedirect = array('admin' => false, 'plugin'=>'users','controller' => 'users', 'action' => 'index'); $this->Auth->allow('register', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password','login'); if ($this->action == 'register') { diff --git a/views/users/index.ctp b/views/users/index.ctp index 1183260b2..fbd4fca14 100644 --- a/views/users/index.ctp +++ b/views/users/index.ctp @@ -9,7 +9,7 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ ?> -
+