diff --git a/Config/Schema/schema.php b/Config/Schema/schema.php index 827c14344..af992cd36 100644 --- a/Config/Schema/schema.php +++ b/Config/Schema/schema.php @@ -1,19 +1,4 @@ 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'), - 'field' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index'), - 'value' => array('type' => 'text', 'null' => true, 'default' => null), - 'input' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 16), - 'data_type' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 16), - 'label' => array('type' => 'string', 'null' => false, 'length' => 128), - 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), - 'UNIQUE_PROFILE_PROPERTY' => array('column' => array('field', 'user_id'), 'unique' => 1) - ) + public $details = array( + 'id' => array('type' => 'string', 'null' => false, 'length' => 36, 'key' => 'primary'), + 'first_name' => array('type' => 'string', 'null' => true, 'length' => 50), + 'last_name' => array('type' => 'string', 'null' => true, 'length' => 50), + 'birthdate' => array('type' => 'date', 'null' => true), + 'cellphone' => array('type' => 'string', 'null' => true, 'length' => 20), + 'telephone' => array('type' => 'string', 'null' => true, 'length' => 20), + 'country' => array('type' => 'string', 'null' => true, 'length' => 50), + 'state' => array('type' => 'string', 'null' => true, 'length' => 50), + 'city' => array('type' => 'string', 'null' => true, 'length' => 50), + 'street' => array('type' => 'string', 'null' => true, 'length' => 100), + 'number' => array('type' => 'string', 'null' => true, 'length' => 20), + 'zipcode' => array('type' => 'string', 'null' => true, 'length' => 10), + 'created' => array('type' => 'datetime', 'null' => true), + 'modified' => array('type' => 'text', 'null' => true), + 'user_id' => array('type' => 'string', 'null' => false, 'length' => 36), + 'indexes' => array( + 'PRIMARY' => array('unique' => true, 'column' => 'id') + ), + 'tableParameters' => array() ); public $users = 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), + 'id' => array('type' => 'string', 'null' => false, 'length' => 36, 'key' => 'primary'), + 'username' => array('type' => 'string', 'null' => false), + 'slug' => array('type' => 'string', 'null' => false), '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_verified' => array('type' => 'boolean', 'null' => true, 'default' => '0'), + 'email' => array('type' => 'string', 'null' => true, 'default' => null), + 'email_verified' => array('type' => 'boolean', 'null' => true, 'default' => false), 'email_token' => array('type' => 'string', 'null' => true, 'default' => null), - '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_login' => 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'), + 'email_token_expires' => array('type' => 'datetime', 'null' => true), + 'tos' => array('type' => 'boolean', 'null' => true, 'default' => false), + 'active' => array('type' => 'boolean', 'null' => true, 'default' => false), + 'last_login' => array('type' => 'datetime', 'null' => true), + 'last_action' => array('type' => 'datetime', 'null' => true), + 'is_admin' => array('type' => 'boolean', 'null' => true, 'default' => false), 'role' => array('type' => 'string', 'null' => true, 'default' => null), - 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'created' => array('type' => 'datetime', 'null' => true), + 'modified' => array('type' => 'datetime', 'null' => true), 'indexes' => array( - 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'BY_USERNAME' => array('column' => array('username'), 'unique' => 0), - 'BY_EMAIL' => array('column' => array('email'), 'unique' => 0) - ) + 'PRIMARY' => array('unique' => true, 'column' => 'id'), + 'by_email' => array('unique' => false, 'column' => 'email'), + 'by_username' => array('unique' => false, 'column' => 'username') + ), + 'tableParameters' => array() ); + } diff --git a/Config/Schema/schema_old.php b/Config/Schema/schema_old.php new file mode 100644 index 000000000..827c14344 --- /dev/null +++ b/Config/Schema/schema_old.php @@ -0,0 +1,68 @@ + 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'), + 'field' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index'), + 'value' => array('type' => 'text', 'null' => true, 'default' => null), + 'input' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 16), + 'data_type' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 16), + 'label' => array('type' => 'string', 'null' => false, 'length' => 128), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), + 'UNIQUE_PROFILE_PROPERTY' => array('column' => array('field', 'user_id'), 'unique' => 1) + ) + ); + + public $users = 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), + '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_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), + '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_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), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'BY_USERNAME' => array('column' => array('username'), 'unique' => 0), + 'BY_EMAIL' => array('column' => array('email'), 'unique' => 0) + ) + ); +} diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 74f1df63d..ef59a7bd4 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -65,6 +65,7 @@ class UsersController extends UsersAppController { 'Cookie', 'Paginator', 'Security', + 'Search.Prg', 'Users.RememberMe', ); @@ -219,6 +220,14 @@ protected function _setupAuth() { if (Configure::read('Users.disableDefaultAuth') === true) { return; } + //prevent acces to admin routes if not admin + if (isset($this->params['prefix']) && $this->params['prefix'] == 'admin') { +// if ($this->Session->check('Auth.User.role') and 'admin' !== $this->Session->read('Auth.User.role')) { + if(!$this->Session->read('Auth.User.is_admin')) { + $this->Auth->deny('*'); + return $this->flash('Non admin access - unauthorized', '/'); + } + } $this->Auth->allow('add', 'reset', 'verify', 'logout', 'view', 'reset_password', 'login', 'resend_verification'); @@ -285,16 +294,34 @@ public function view($slug = null) { /** * Edit the current logged in user * - * Extend the plugin and implement your custom logic here, mostly thought to be - * used as a dashboard or profile page like method. - * - * See the plugins documentation for how to extend the plugin. - * + * @param string $id User ID * @return void */ - public function edit() { + public function edit($slug = null) { + // @todo replace this with something better than the user details that were removed + try { + $this->set('user', $this->{$this->modelClass}->view($slug)); + if($this->{$this->modelClass}->Detail->hasAny(array('user_id'=>$this->Auth->user('id')))){ + $detail = $this->{$this->modelClass}->Detail->find('first',array('user_id'=>$this->Auth->user('id'))); + if(!$this->request->data) { + $this->request->data = $detail; + } + } + + if ($this->request->is('post')) { + $this->Session->setFlash(__d('users', 'Your profile has been updated')); + $this->request->data['Detail']['user_id'] = $this->Auth->user('id'); + $this->{$this->modelClass}->Detail->save($this->request->data); + }else{ + + } + } catch (Exception $e) { + $this->Session->setFlash($e->getMessage()); + $this->redirect('/'); + } } + /** * Admin Index * @@ -595,6 +622,8 @@ public function resend_verification() { $this->Session->setFlash($e->getMessage()); } } + $allowRegistration = Configure::read('Users.allowRegistration'); + $this->set('allowRegistration', (is_null($allowRegistration) ? true : $allowRegistration)); } /** diff --git a/Model/Detail.php b/Model/Detail.php new file mode 100644 index 000000000..701f9dc18 --- /dev/null +++ b/Model/Detail.php @@ -0,0 +1,51 @@ + array( + 'uuid' => array( + 'rule' => array('uuid'), + //'message' => 'Your custom message here', + //'allowEmpty' => false, + //'required' => false, + //'last' => false, // Stop validation after this rule + //'on' => 'create', // Limit validation to 'create' or 'update' operations + ), + 'unique' => array( + 'rule' => array('isUnique'), + ), + ), + 'first_name' => array( + 'required' => array( + 'rule' => array('notEmpty')) + ), + ); + + //The Associations below have been created with all possible keys, those that are not needed can be removed + +/** + * belongsTo associations + * + * @var array + */ + public $belongsTo = array( + 'User' => array( + 'className' => 'User', + 'foreignKey' => 'user_id', + 'conditions' => '', + 'fields' => '', + 'order' => '' + ) + ); +} diff --git a/Model/User.php b/Model/User.php index 31f68c685..41b113f59 100644 --- a/Model/User.php +++ b/Model/User.php @@ -29,6 +29,9 @@ class User extends UsersAppModel { */ public $name = 'User'; + public $hasOne = array('Users.Detail'); + + /** * Additional Find methods * @@ -694,7 +697,11 @@ protected function _beforeRegistration($postData = array(), $useEmailVerificatio } else { $postData[$this->alias]['email_verified'] = 1; } - $postData[$this->alias]['active'] = 1; + if (!is_null(Configure::read('Users.manualActivation')) && Configure::read('Users.manualActivation')===true) { + $postData[$this->alias]['active'] = 0; + }else{ + $postData[$this->alias]['active'] = 1; + } $defaultRole = Configure::read('Users.defaultRole'); if ($defaultRole) { $postData[$this->alias]['role'] = $defaultRole; diff --git a/Model/UsersAppModel.php b/Model/UsersAppModel.php index 94765e049..2fdd87b87 100644 --- a/Model/UsersAppModel.php +++ b/Model/UsersAppModel.php @@ -18,7 +18,7 @@ * @subpackage users.models */ class UsersAppModel extends AppModel { - + /** * Plugin name * diff --git a/README.md b/README.md index 84c5e08fe..01058cb83 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,26 @@ +Bootstrap 3.0 Version of Users Plugin for CakePHP +================================================= + +Main differences from CakeDC users plugin + +We are trying to create a more plug and play version of cake dc users plugins with very little customization + +Main differences: + +* Views using bootstrap 3.0 +* Allow manual activation of users +* Registered users cant access admin routes +* Link do resend verification +* Simple profile + +Manual Activation +----------------- + +This option enforces a manual activation by the system administration after a user register + + Configure::write('Users.manualActivation',true); + + CakeDC Users Plugin =================== diff --git a/Test/Case/Model/DetailTest.php b/Test/Case/Model/DetailTest.php new file mode 100644 index 000000000..1ce6f5f0f --- /dev/null +++ b/Test/Case/Model/DetailTest.php @@ -0,0 +1,41 @@ +Detail = ClassRegistry::init('Users.Detail'); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + unset($this->Detail); + + parent::tearDown(); + } + +} diff --git a/Test/Case/Model/ProfileTest.php b/Test/Case/Model/ProfileTest.php new file mode 100644 index 000000000..074285119 --- /dev/null +++ b/Test/Case/Model/ProfileTest.php @@ -0,0 +1,41 @@ +Profile = ClassRegistry::init('Users.Profile'); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + unset($this->Profile); + + parent::tearDown(); + } + +} diff --git a/Test/Fixture/DetailFixture.php b/Test/Fixture/DetailFixture.php new file mode 100644 index 000000000..63007bc8d --- /dev/null +++ b/Test/Fixture/DetailFixture.php @@ -0,0 +1,60 @@ + array('type' => 'string', 'null' => false, 'length' => 36, 'key' => 'primary'), + 'first_name' => array('type' => 'string', 'null' => true, 'length' => 50), + 'last_name' => array('type' => 'string', 'null' => true, 'length' => 50), + 'birthdate' => array('type' => 'date', 'null' => true), + 'cellphone' => array('type' => 'string', 'null' => true, 'length' => 20), + 'telephone' => array('type' => 'string', 'null' => true, 'length' => 20), + 'country' => array('type' => 'string', 'null' => true, 'length' => 50), + 'state' => array('type' => 'string', 'null' => true, 'length' => 50), + 'city' => array('type' => 'string', 'null' => true, 'length' => 50), + 'street' => array('type' => 'string', 'null' => true, 'length' => 100), + 'number' => array('type' => 'string', 'null' => true, 'length' => 20), + 'zipcode' => array('type' => 'string', 'null' => true, 'length' => 10), + 'created' => array('type' => 'datetime', 'null' => true), + 'modified' => array('type' => 'text', 'null' => true), + 'user_id' => array('type' => 'string', 'null' => false, 'length' => 36), + 'indexes' => array( + 'PRIMARY' => array('unique' => true, 'column' => 'id') + ), + 'tableParameters' => array() + ); + +/** + * Records + * + * @var array + */ + public $records = array( + array( + 'id' => '531f1066-2864-4b29-b294-1c814400960e', + 'first_name' => 'Lorem ipsum dolor sit amet', + 'last_name' => 'Lorem ipsum dolor sit amet', + 'birthdate' => '2014-03-11', + 'cellphone' => 'Lorem ipsum dolor ', + 'telephone' => 'Lorem ipsum dolor ', + 'country' => 'Lorem ipsum dolor sit amet', + 'state' => 'Lorem ipsum dolor sit amet', + 'city' => 'Lorem ipsum dolor sit amet', + 'street' => 'Lorem ipsum dolor sit amet', + 'number' => 'Lorem ipsum dolor ', + 'zipcode' => 'Lorem ip', + 'created' => '2014-03-11 13:32:22', + 'modified' => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida, phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit, feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.', + 'user_id' => 'Lorem ipsum dolor sit amet' + ), + ); + +} diff --git a/Test/Fixture/ProfileFixture.php b/Test/Fixture/ProfileFixture.php new file mode 100644 index 000000000..a481a7a92 --- /dev/null +++ b/Test/Fixture/ProfileFixture.php @@ -0,0 +1,60 @@ + array('type' => 'string', 'null' => false, 'length' => 36, 'key' => 'primary'), + 'first_name' => array('type' => 'string', 'null' => true, 'length' => 50), + 'last_name' => array('type' => 'string', 'null' => true, 'length' => 50), + 'birthdate' => array('type' => 'date', 'null' => true), + 'cellphone' => array('type' => 'string', 'null' => true, 'length' => 20), + 'telephone' => array('type' => 'string', 'null' => true, 'length' => 20), + 'country' => array('type' => 'string', 'null' => true, 'length' => 50), + 'state' => array('type' => 'string', 'null' => true, 'length' => 50), + 'city' => array('type' => 'string', 'null' => true, 'length' => 50), + 'street' => array('type' => 'string', 'null' => true, 'length' => 100), + 'number' => array('type' => 'string', 'null' => true, 'length' => 20), + 'zipcode' => array('type' => 'string', 'null' => true, 'length' => 10), + 'created' => array('type' => 'datetime', 'null' => true), + 'modified' => array('type' => 'text', 'null' => true), + 'user_id' => array('type' => 'string', 'null' => false, 'length' => 36), + 'indexes' => array( + 'PRIMARY' => array('unique' => true, 'column' => 'id') + ), + 'tableParameters' => array() + ); + +/** + * Records + * + * @var array + */ + public $records = array( + array( + 'id' => '531f011a-ec38-4a6d-8161-15364400960e', + 'first_name' => 'Lorem ipsum dolor sit amet', + 'last_name' => 'Lorem ipsum dolor sit amet', + 'birthdate' => '2014-03-11', + 'cellphone' => 'Lorem ipsum dolor ', + 'telephone' => 'Lorem ipsum dolor ', + 'country' => 'Lorem ipsum dolor sit amet', + 'state' => 'Lorem ipsum dolor sit amet', + 'city' => 'Lorem ipsum dolor sit amet', + 'street' => 'Lorem ipsum dolor sit amet', + 'number' => 'Lorem ipsum dolor ', + 'zipcode' => 'Lorem ip', + 'created' => '2014-03-11 12:27:06', + 'modified' => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida, phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit, feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.', + 'user_id' => 'Lorem ipsum dolor sit amet' + ), + ); + +} diff --git a/View/Elements/Users/admin_sidebar.ctp b/View/Elements/Users/admin_sidebar.ctp index fb93c0c38..5c5c46891 100644 --- a/View/Elements/Users/admin_sidebar.ctp +++ b/View/Elements/Users/admin_sidebar.ctp @@ -1,5 +1,5 @@ -
-