diff --git a/controllers/users_controller.php b/controllers/users_controller.php index 3c289abb3..12641c688 100644 --- a/controllers/users_controller.php +++ b/controllers/users_controller.php @@ -55,7 +55,8 @@ class UsersController extends UsersAppController { */ public function beforeFilter() { parent::beforeFilter(); - $this->Auth->allow('register', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password'); + $this->Auth->fields = array('username' => 'email', 'password' => 'passwd'); + $this->Auth->allow('register', 'reset', 'verify', 'logout', 'index', 'view', 'reset_password','login'); if ($this->action == 'register') { $this->Auth->enabled = false; @@ -191,9 +192,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')); + 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; + } } } @@ -281,36 +291,39 @@ 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'])); } - if (isset($this->params['named']['return_to'])) { $this->set('return_to', urldecode($this->params['named']['return_to'])); } else { @@ -364,7 +377,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()); } diff --git a/readme.md b/readme.md index ce5df404a..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): @@ -16,6 +18,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. 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/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 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 @@ - -