diff --git a/Config/Schema/schema.php b/Config/Schema/schema.php index 4dabf4b01..ca9dd8581 100644 --- a/Config/Schema/schema.php +++ b/Config/Schema/schema.php @@ -25,6 +25,28 @@ public function before($event = array()) { public function after($event = array()) { } + public $social_profiles = array( + 'id' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 36, 'key' => 'primary'), + 'user_id' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 36), + 'oid' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 136), + 'email' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index'), + 'family_name' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 128), + 'given_name' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 128), + 'gender' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 128), + 'locale' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 128), + 'birthday' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 128), + 'picture' => array('type' => 'string', 'null' => false, 'length' => 128), + 'provider' => array('type' => 'string', 'null' => false, 'length' => 128), + 'raw' => array('type' => 'text', '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('user_id'), 'unique' => 0), + 'BY_OID' => array('column' => array('oid'), 'unique' => 0) + ) + ); + 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'), diff --git a/Config/routes.php b/Config/routes.php index 844bd54f0..049aff799 100644 --- a/Config/routes.php +++ b/Config/routes.php @@ -5,4 +5,4 @@ Router::connect('/users/users/:action/*', array('plugin' => 'users', 'controller' => 'users')); Router::connect('/login', array('plugin' => 'users', 'controller' => 'users', 'action' => 'login')); Router::connect('/logout', array('plugin' => 'users', 'controller' => 'users', 'action' => 'logout')); -Router::connect('/register', array('plugin' => 'users', 'controller' => 'users', 'action' => 'add')); \ No newline at end of file +Router::connect('/register', array('plugin' => 'users', 'controller' => 'users', 'action' => 'add')); diff --git a/Controller/GenericUsersController.php b/Controller/GenericUsersController.php new file mode 100644 index 000000000..4ea1f41e8 --- /dev/null +++ b/Controller/GenericUsersController.php @@ -0,0 +1,115 @@ +GenericUser->recursive = 0; + $genericUsers = $this->GenericUser->find('all', array( + 'contain' => array( + 'Rol' + ), + 'conditions' => array( + //'machin_name !=' => ROL_DUENIO + ) + )); + $this->set('genericUsers', $this->Paginator->paginate()); + } + +/** + * view method + * + * @throws NotFoundException + * @param string $id + * @return void + */ + public function view($id = null) { + if (!$this->GenericUser->exists($id)) { + throw new NotFoundException(__('Invalid generic user')); + } + $options = array('conditions' => array('GenericUser.' . $this->GenericUser->primaryKey => $id)); + $this->set('genericUser', $this->GenericUser->find('first', $options)); + } + +/** + * add method + * + * @return void + */ + public function add() { + + if ($this->request->is('post')) { + $this->GenericUser->create(); + if ($this->GenericUser->save($this->request->data)) { + $this->Flash->success(__('The generic user has been saved.')); + return $this->redirect(array('action' => 'index')); + } else { + $this->Flash->error(__('The generic user could not be saved. Please, try again.')); + } + } + $roles = $this->GenericUser->Rol->find('list'); + $this->set(compact('roles')); + $this->render("form"); + } + +/** + * edit method + * + * @throws NotFoundException + * @param string $id + * @return void + */ + public function edit( $id = null) { + + if (!$this->GenericUser->exists($id)) { + throw new NotFoundException(__('Invalid generic user')); + } + if ($this->request->is(array('post', 'put'))) { + if ($this->GenericUser->save($this->request->data)) { + $this->Flash->success(__('The generic user has been saved.')); + return $this->redirect(array('action' => 'index')); + } else { + $this->Flash->error(__('The generic user could not be saved. Please, try again.')); + } + } else { + $options = array('conditions' => array('GenericUser.' . $this->GenericUser->primaryKey => $id)); + $this->request->data = $this->GenericUser->find('first', $options); + } + $roles = $this->GenericUser->Rol->find('list'); + $this->set(compact('roles')); + $this->render("form"); + } + +/** + * delete method + * + * @throws NotFoundException + * @param string $id + * @return void + */ + public function delete($id = null) { + $this->GenericUser->id = $id; + if (!$this->GenericUser->exists()) { + throw new NotFoundException(__('Invalid generic user')); + } + if ($this->GenericUser->delete()) { + $this->Flash->success(__('The generic user has been deleted.')); + } else { + $this->Flash->error(__('The generic user could not be deleted. Please, try again.')); + } + return $this->redirect(array('action' => 'index')); + } +} diff --git a/Controller/RolesController.php b/Controller/RolesController.php new file mode 100644 index 000000000..725764845 --- /dev/null +++ b/Controller/RolesController.php @@ -0,0 +1,146 @@ +Rol->recursive = 0; + $this->set('roles', $this->paginate()); + } + +/** + * view method + * + * @param string $id + * @return void + */ + public function view($id = null) { + $this->Rol->id = $id; + if (!$this->Rol->exists()) { + throw new NotFoundException(__('Invalid rol')); + } + $this->set('rol', $this->Rol->read(null, $id)); + } + +/** + * add method + * + * @return void + */ + public function add() { + if ($this->request->is('post')) { + $this->Rol->create(); + if ($this->Rol->save($this->request->data)) { + $this->Session->setFlash(__('The rol has been saved'),'Risto.flash_success'); + $this->redirect($this->referer()); + } else { + $this->Session->setFlash(__('The rol could not be saved. Please, try again.'),'Risto.flash_error'); + } + } + $roles_machine_names = $this->Rol->find('list', array( + 'recursive' => -1, + 'fields' => array( + 'machin_name', + 'name' + ), + 'conditions' => array( + 'machin_name !=' => ROL_DUENIO + ), + 'order' => array( + 'Rol.created' => 'DESC' + ))); + $this->set('roles_machine_names', $roles_machine_names); + $this->render('edit'); + } + +/** + * edit method + * + * @param string $id + * @return void + */ + public function edit($id = null) { + $this->Rol->id = $id; + if (!$this->Rol->exists()) { + throw new NotFoundException(__('Invalid rol')); + } + if ($this->request->is('post') || $this->request->is('put')) { + if ($this->Rol->save($this->request->data)) { + $this->Session->setFlash(__('The rol has been saved'),'Risto.flash_success'); + $this->redirect(array('action' => 'index')); + } else { + $this->Session->setFlash(__('The rol could not be saved. Please, try again.'),'Risto.flash_error'); + } + } else { + $this->request->data = $this->Rol->read(null, $id); + } + + $roles_machine_names = $this->Rol->find('list', array( + 'recursive' => -1, + 'fields' => array( + 'machin_name', + 'name' + ), + 'conditions' => array( + 'machin_name !=' => ROL_DUENIO + ), + 'order' => array( + 'Rol.created' => 'DESC' + ))); + $this->set('roles_machine_names', $roles_machine_names); + } + +/** + * delete method + * + * @param string $id + * @return void + */ + public function delete($id = null) { + $this->Rol->id = $id; + if (!$this->Rol->exists()) { + throw new NotFoundException(__('Invalid Rol Id')); + } + if ($this->Rol->delete($id, true)) { + $this->Rol->GenericUser->deleteAll(array('GenericUser.rol_id' => $id)); + $this->Session->setFlash(__('Usuario Generico Borrado'),'Risto.flash_success'); + $this->redirect($this->referer()); + } else { + $this->Session->setFlash(__('Error: Usuario Generico No pudo ser borrado'),'Risto.flash_error'); + } + + $this->redirect(array('action' => 'index')); + } + + + public function edit_for_user( $userId ) { + $this->Rol->User->id = $userId; + if (!$this->Rol->User->exists()) { + throw new NotFoundException(__('Invalid User')); + } + + if ($this->request->is('post') || $this->request->is('put')) { + if ($this->Rol->RolUser->asignarRol($this->request->data)) { + $this->Session->setFlash(__('The rol has been saved'),'Risto.flash_success'); + $this->redirect($this->referer()); + } else { + $this->Session->setFlash(__('The rol could not be saved. Please, try again.'),'Risto.flash_error'); + } + } else { + $this->Rol->User->contain(array('Rol')); + $user = $this->Rol->User->read(); + $this->request->data = $user; + } + $this->set('roles', $this->Rol->find("list")); + } +} diff --git a/Controller/SuperRolesController.php b/Controller/SuperRolesController.php new file mode 100644 index 000000000..034f8ec5a --- /dev/null +++ b/Controller/SuperRolesController.php @@ -0,0 +1,29 @@ +SuperRol->User->id = $userId; + if (!$this->SuperRol->User->exists()) { + throw new NotFoundException(__('Invalid User')); + } + + if ($this->request->is('post') || $this->request->is('put')) { + if ($this->SuperRol->SuperRolUser->asignarRol($this->request->data)) { + $this->Session->setFlash(__('The rol has been saved'),'Risto.flash_success'); + $this->redirect($this->referer()); + } else { + $this->Session->setFlash(__('The rol could not be saved. Please, try again.'),'Risto.flash_error'); + } + } else { + $this->SuperRol->User->contain(array('SuperRol')); + $user = $this->SuperRol->User->read(); + $this->request->data = $user; + } + $this->set('superRoles', $this->SuperRol->find("list")); + } + +} + +?> \ No newline at end of file diff --git a/Controller/UsersController.php b/Controller/UsersController.php index 74f1df63d..e815b01ac 100644 --- a/Controller/UsersController.php +++ b/Controller/UsersController.php @@ -11,6 +11,9 @@ App::uses('CakeEmail', 'Network/Email'); App::uses('UsersAppController', 'Users.Controller'); +App::uses('MtSites', 'MtSites.Utility'); +App::uses('HttpSocket', 'Network/Http'); +App::uses('JwtUtil', 'JwtAuth.Utility'); /** * Users Users Controller @@ -39,35 +42,21 @@ class UsersController extends UsersAppController { * * @var mixed */ - public $plugin = null; + public $plugin = 'Users'; -/** - * Helpers - * - * @var array - */ - public $helpers = array( - 'Html', - 'Form', - 'Session', - 'Time', - 'Text' - ); /** * Components * * @var array */ - public $components = array( - 'Auth', - 'Session', - 'Cookie', - 'Paginator', - 'Security', + public $extra_components = array( + // 'Security', 'Users.RememberMe', ); + + /** * Preset vars * @@ -105,6 +94,7 @@ protected function _reInitControllerName() { } } + /** * Returns $this->plugin with a dot, used for plugin loading using the dot notation * @@ -141,8 +131,11 @@ protected function _pluginLoaded($plugin, $exception = true) { */ protected function _setupComponents() { if ($this->_pluginLoaded('Search', false)) { - $this->components[] = 'Search.Prg'; + // no quiero que me lo cargue este plugin ya lo tengo cargado de mi App + //$this->components[] = 'Search.Prg'; } + + $this->components = array_merge( $this->components, $this->extra_components); } /** @@ -152,10 +145,13 @@ protected function _setupComponents() { */ public function beforeFilter() { parent::beforeFilter(); + $this->_setupAuth(); $this->_setupPagination(); - + $this->set('model', $this->modelClass); + + $this->Auth->allow(["wishlist"]); $this->_setDefaultEmail(); } @@ -220,7 +216,7 @@ protected function _setupAuth() { return; } - $this->Auth->allow('add', 'reset', 'verify', 'logout', 'view', 'reset_password', 'login', 'resend_verification'); + $this->Auth->allow('add', 'reset', 'verify', 'logout', 'view', 'reset_password', 'login', 'resend_verification', 'auth_login', 'auth_callback', 'tenant_login', 'fb_login'); if (!is_null(Configure::read('Users.allowRegistration')) && !Configure::read('Users.allowRegistration')) { $this->Auth->deny('add'); @@ -230,33 +226,44 @@ protected function _setupAuth() { $this->Components->disable('Auth'); } - $this->Auth->authenticate = array( - 'Form' => array( - 'fields' => array( - 'username' => 'email', - 'password' => 'password'), - 'userModel' => $this->_pluginDot() . $this->modelClass, - 'scope' => array( - $this->modelClass . '.active' => 1, - $this->modelClass . '.email_verified' => 1 - ) - ) - ); - - $this->Auth->loginRedirect = '/'; - $this->Auth->logoutRedirect = array('plugin' => Inflector::underscore($this->plugin), 'controller' => 'users', 'action' => 'login'); - $this->Auth->loginAction = array('admin' => false, 'plugin' => Inflector::underscore($this->plugin), 'controller' => 'users', 'action' => 'login'); } -/** - * Simple listing of all users - * - * @return void - */ - public function index() { - $this->set('users', $this->Paginator->paginate($this->modelClass)); + public function wishlist() { + + if ($this->request->is('post')) { + $nombre = $this->request->data['Wishlist']['name']; + $boliche = $this->request->data['Wishlist']['business']; + + $emailTo = Configure::read('Email.soporte'); + $mensaje = "Nombre: " . $this->request->data['Wishlist']['name'] . "\n"; + $mensaje .= "Email: " . $this->request->data['Wishlist']['email'] . "\n"; + $mensaje .= "Negocio: " . $this->request->data['Wishlist']['business'] . "\n"; + $mensaje .= "Teléfono: " . $this->request->data['Wishlist']['phone'] . "\n"; + $mensaje .= "Razón Social: " . $this->request->data['Wishlist']['razon_social'] . "\n"; + $mensaje .= "CUIT: " . $this->request->data['Wishlist']['cuit'] . "\n"; + $mensaje .= "Dirección: " . $this->request->data['Wishlist']['address'] . "\n"; + $mensaje .= "Código postal: " . $this->request->data['Wishlist']['zip'] . "\n"; + $mensaje .= "Ciudad: " . $this->request->data['Wishlist']['city'] . "\n"; + $mensaje .= "País: " . $this->request->data['Wishlist']['country'] . "\n"; + $mensaje .= "Sitio web: " . $this->request->data['Wishlist']['website'] . "\n"; + $mensaje .= "Comentarios: " . $this->request->data['Wishlist']['comments'] . "\n"; + + try { + //code... + sendFastMail( $emailTo, "Pedido Whishlist de $nombre [$boliche]", $mensaje ); + $this->Session->SetFlash("Gracias por tu pedido, nos pondremos en contacto a la brevedad."); + } catch (\Throwable $th) { + //throw $th; + $this->Session->SetFlash("Error al enviar mail.", 'Risto.flash_error'); + } + + $this->redirect(['plugin' => 'paxapos','controller' => 'paxapos', 'action' => 'display', 'free']); + } + + } + /** * The homepage of a users giving him an overview about everything * @@ -292,21 +299,75 @@ public function view($slug = null) { * * @return void */ - public function edit() { + public function my_edit() { + if ( !$this->Auth->loggedIn() ) { + throw new ForbiddenException(__("You must be logged in")); + } + $user = $this->Auth->user(); + if ( $this->request->is('post') || $this->request->is('put') ) { + $this->request->data['User']['tos'] = 1; + if ($this->User->save( $this->request->data) ) { + $this->Session->setFlash(__('Se ha guardado la información correctamente')); + MtSites::loadSessionData(); + } else { + $this->Session->setFlash(__('El usuario no pudo ser guardado. Por favor, intente nuevamente.')); + } + } else { + $this->request->data['User'] = $user; + } + $socialProfiles = $this->User->SocialProfile->find('all', array( + 'recursive' => -1, + 'conditions' => array( + 'SocialProfile.user_id' => $user['id'] + ), + )); + $this->set("socialProfiles", $socialProfiles); } + + public function index_deleted() { + $this->Paginator->settings[$this->modelClass] = array( + 'contain' => array('SuperRol', 'Site'), + 'order' => array('User.deleted_date' => 'desc'), + 'conditions' => array( + 'User.deleted' => 1, + ), + 'limit' => 50, + ); + + $this->set('users', $this->Paginator->paginate($this->modelClass)); + $this->set('title', "Usuarios Borrados"); + $this->render('index'); + } + + public function restaurar($id){ + if (!$this->User->exists($id) ){ + throw new NotFoundException("El usuario no pudo ser encontrado"); + } + + $this->User->id = $id; + if ( !$this->User->saveField('deleted', 0) ) { + throw new CakeException("Error al restaurar Usuario"); + } + + $this->redirect($this->referer()); + } + + /** * Admin Index * * @return void */ - public function admin_index() { + public function index() { + if ($this->{$this->modelClass}->Behaviors->loaded('Searchable')) { $this->Prg->commonProcess(); - unset($this->{$this->modelClass}->validate['username']); - unset($this->{$this->modelClass}->validate['email']); + // unset($this->{$this->modelClass}->validate['username']); + // unset($this->{$this->modelClass}->validate['email']); $this->{$this->modelClass}->data[$this->modelClass] = $this->passedArgs; } + if ($this->{$this->modelClass}->Behaviors->loaded('Searchable')) { $parsedConditions = $this->{$this->modelClass}->parseCriteria($this->passedArgs); @@ -314,142 +375,266 @@ public function admin_index() { $parsedConditions = array(); } - $this->_setupAdminPagination(); - $this->Paginator->settings[$this->modelClass]['conditions'] = $parsedConditions; - $this->set('users', $this->Paginator->paginate()); + $this->Paginator->settings[$this->modelClass] = array( + 'contain' => array('SuperRol', 'Site'), + 'order' => array('User.last_login' => 'desc'), + 'conditions' => $parsedConditions, + 'limit' => 50, + ); + $this->set('title', "Usuarios"); + $this->set('users', $this->Paginator->paginate($this->modelClass)); } + + /** - * Admin view + * Admin Index * - * @param string $id User ID * @return void */ - public function admin_view($id = null) { - try { - $user = $this->{$this->modelClass}->view($id, 'id'); - } catch (NotFoundException $e) { - $this->Session->setFlash(__d('users', 'Invalid User.')); - $this->redirect(array('action' => 'index')); + public function index_for_tenant() { + + if ( !MtSites::isTenant() ) { + throw new CakeException("No se encuentra en un Tenant"); } - $this->set('user', $user); - } -/** - * Admin add - * - * @return void - */ - public function admin_add() { - if (!empty($this->request->data)) { - $this->request->data[$this->modelClass]['tos'] = true; - $this->request->data[$this->modelClass]['email_verified'] = true; + if ($this->User->Behaviors->loaded('Searchable')) { + $this->Prg->commonProcess(); + } + - if ($this->{$this->modelClass}->add($this->request->data)) { - $this->Session->setFlash(__d('users', 'The User has been saved')); - $this->redirect(array('action' => 'index')); - } + $parsedConditions = $this->User->parseCriteria($this->passedArgs); + + $site_alias = MtSites::getSiteName(); + $site = $this->User->Site->findByAlias($site_alias); + + if ( empty($parsedConditions)) { + + + $usersIds = $this->User->SiteUser->find('list', array( + 'fields' => array( + 'SiteUser.user_id', 'SiteUser.user_id' + ), + 'conditions' => array( + 'SiteUser.site_id' => $site['Site']['id'], + ) + )); + + $parsedConditions = array( + 'User.id' => $usersIds, + ); + $esBusquedaGeneral = false; + } else { + + $esBusquedaGeneral = true; } - $this->set('roles', Configure::read('Users.roles')); + + + + + $this->Paginator->settings['User'] = array( + 'conditions' => $parsedConditions, + 'contain' => array( + 'Site', + 'Rol', + ) + ); + + $this->set('busqueda_general_realizada', $esBusquedaGeneral); + $this->set('users', $this->Paginator->paginate('User')); + $this->set('modelName', "User"); + if ( $esBusquedaGeneral ) { + $this->set('title', 'Usuarios no vinculados con mi comercio'); + } else { + $this->set('title', 'Usuarios vinculados'); + } + $this->set(compact('site_alias')); } + + + + /** * Admin edit * * @param null $userId * @return void */ - public function admin_edit($userId = null) { - try { - $result = $this->{$this->modelClass}->edit($userId, $this->request->data); - if ($result === true) { + public function edit($userId = null) { + if ( $this->request->is('post')) { + unset ( $this->request->data[$this->modelClass]['last_login'] ); + if(!empty($this->request->data[$this->modelClass]['password'])) { + $this->request->data = $this->User->hashNewPassword($this->request->data); + } else { + unset($this->request->data[$this->modelClass]['password']); + } + if ( $this->User->saveAll($this->request->data) ) { $this->Session->setFlash(__d('users', 'User saved')); $this->redirect(array('action' => 'index')); } else { - unset($result[$this->modelClass]['password']); - $this->request->data = $result; + $this->Session->setFlash(__d('users', 'Error saving'), 'Risto.flash_error'); } - } catch (OutOfBoundsException $e) { - $this->Session->setFlash($e->getMessage()); - $this->redirect(array('action' => 'index')); } if (empty($this->request->data)) { + $this->{$this->modelClass}->recursive = -1; $this->request->data = $this->{$this->modelClass}->read(null, $userId); unset($this->request->data[$this->modelClass]['password']); } - $this->set('roles', Configure::read('Users.roles')); + $roles = array(); + //$roles = $this->{$this->modelClass}->Rol->find('list'); + $this->set(compact( 'roles')); + $this->render('admin_form'); } + + + /** * Delete a user account * * @param string $userId User ID * @return void */ - public function admin_delete($userId = null) { - if ($this->{$this->modelClass}->delete($userId)) { + public function delete($userId = null) { + if ( !$this->{$this->modelClass}->exists($userId) ){ + throw new NotFoundException("El usuario no existe"); + + } + if ($this->{$this->modelClass}->softDelete($userId)) { $this->Session->setFlash(__d('users', 'User deleted')); - } else { - $this->Session->setFlash(__d('users', 'Invalid User')); } - - $this->redirect(array('action' => 'index')); + $this->redirect($this->referer()); } -/** - * Search for a user - * - * @return void - */ - public function admin_search() { - $this->search(); - } + /** * User register action * * @return void */ - public function add() { + public function register() { if ($this->Auth->user()) { $this->Session->setFlash(__d('users', 'You are already registered and logged in!')); $this->redirect('/'); } if (!empty($this->request->data)) { - $user = $this->{$this->modelClass}->register($this->request->data); - if ($user !== false) { - $Event = new CakeEvent( - 'Users.Controller.Users.afterRegistration', - $this, - array( - 'data' => $this->request->data, - ) - ); - $this->getEventManager()->dispatch($Event); - if ($Event->isStopped()) { + $HttpSocket = new HttpSocket(); + $response_recaptcha = $this->request->data['g-recaptcha-response']; + + $link = 'https://www.google.com/recaptcha/api/siteverify?secret='.RECAPTCHA_SECRET_SITE_ID.'&response='.$response_recaptcha; + + $captcha_result = json_decode($HttpSocket->get($link)); + $resultado = $captcha_result->success; + + if(!$resultado && !in_array($_SERVER['HTTP_HOST'], array('dev.paxapos.com', 'paxapos.com', 'www.paxapos.com'))) { + //si dio false y estoy en gonza.paxapos.com u otro dominio de desarrollo en el cual no tengo habilitado el reCaptcha, pues que me permita registrar cuenta de todas formas... + $resultado = true; + } + + if($resultado) { + + $user = $this->{$this->modelClass}->register($this->request->data); + if ($user !== false) { + $Event = new CakeEvent( + 'Users.Controller.Users.afterRegistration', + $this, + array( + 'data' => $this->request->data, + ) + ); + $this->getEventManager()->dispatch($Event); + if ($Event->isStopped()) { + $this->redirect(array('action' => 'login')); + } + + try { + $this->_sendVerificationEmail($this->{$this->modelClass}->data); + } catch (Exception $e) { + $this->log("ERROR al enviar mails:: ".$e->getMessage()); + } + //$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.', array('class' => 'message big'))); + $this->__loguearUsuario(); $this->redirect(array('action' => 'login')); + } else { + 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')); } - - $this->_sendVerificationEmail($this->{$this->modelClass}->data); - $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->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')); + $this->Session->setFlash(__d('users', 'Error en la comprobación del reCaptcha. Por favor, intentelo de nuevo.'), 'default', array('class' => 'message warning')); } } } -/** - * Common login action - * - * @return void - */ - public function login() { + + + public function tenant_login() { + if ($this->request->is('post')) { + $this->request->data['GenericUser']['pin'] = $this->request->data['GenericUser']['k1'] + . $this->request->data['GenericUser']['k2'] + . $this->request->data['GenericUser']['k3'] + . $this->request->data['GenericUser']['k4']; + } + $this->login(); + } + + public function __loguearUsuario() { + if ($this->Auth->login()) { + $Event = new CakeEvent( + 'Users.Controller.Users.afterLogin', + $this, + array( + 'data' => $this->request->data, + 'isFirstLogin' => !$this->Auth->user('last_login') + ) + ); + + $this->getEventManager()->dispatch($Event); + + $this->{$this->modelClass}->id = $this->Auth->user('id'); + if ($this->User->exists()) { + $this->{$this->modelClass}->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'), $this->Auth->user($this->{$this->modelClass}->displayField))); + if (!empty($this->request->data[$this->modelClass])) { + $data = $this->request->data[$this->modelClass]; + if (empty($this->request->data[$this->modelClass]['remember_me'])) { + $this->RememberMe->destroyCookie(); + } else { + $this->_setCookie(); + } + } + + if (empty($data[$this->modelClass]['return_to'])) { + $data[$this->modelClass]['return_to'] = null; + } + + if ( empty($this->request->ext) ) { + $this->redirect($this->Auth->redirectUrl($data[$this->modelClass]['return_to'])); + } + } else { + $this->Auth->flash['element'] = 'Risto.flash_error'; + $this->Auth->flash(__d('users', 'Invalid e-mail / password combination. Please try again')); + + if ( !empty($this->request->ext) ) { + throw new NotFoundException("Invalid e-mail / password combination. Please try again"); + } + } + } + + public function fb_login(){ + $user = false; $Event = new CakeEvent( 'Users.Controller.Users.beforeLogin', $this, @@ -463,106 +648,86 @@ public function login() { if ($Event->isStopped()) { return; } - - if ($this->request->is('post')) { - if ($this->Auth->login()) { + if( $this->request->is('ajax', 'post') ) { + $user = $this->Auth->login(); + if ( $user ) { $Event = new CakeEvent( 'Users.Controller.Users.afterLogin', $this, array( - 'data' => $this->request->data, + 'data' => $user, 'isFirstLogin' => !$this->Auth->user('last_login') ) ); $this->getEventManager()->dispatch($Event); + } + } - $this->{$this->modelClass}->id = $this->Auth->user('id'); - $this->{$this->modelClass}->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'), $this->Auth->user($this->{$this->modelClass}->displayField))); - if (!empty($this->request->data)) { - $data = $this->request->data[$this->modelClass]; - if (empty($this->request->data[$this->modelClass]['remember_me'])) { - $this->RememberMe->destroyCookie(); - } else { - $this->_setCookie(); - } - } + $this->set('user', $user); + $this->set('_serialize', array('user')); + } - if (empty($data[$this->modelClass]['return_to'])) { - $data[$this->modelClass]['return_to'] = null; - } - // Checking for 2.3 but keeping a fallback for older versions - if (method_exists($this->Auth, 'redirectUrl')) { - $this->redirect($this->Auth->redirectUrl($data[$this->modelClass]['return_to'])); - } else { - $this->redirect($this->Auth->redirect($data[$this->modelClass]['return_to'])); - } - } else { - $this->Auth->flash(__d('users', 'Invalid e-mail / password combination. Please try again')); - } - } - if (isset($this->request->params['named']['return_to'])) { - $this->set('return_to', urldecode($this->request->params['named']['return_to'])); - } elseif (isset($this->request->query['return_to'])) { - $this->set('return_to', $this->request->query['return_to']); + public function get_token() { + if ( $this->Auth->user('is_jwt') ) { + $this->set('msg', 'ya tiene un token de acceso activo'); + $this->set('_serialize', array('msg')); } else { - $this->set('return_to', false); + $jwt = JwtUtil::generateToken( $this->Auth->user() ); + + $this->set('token', $jwt); + $this->set('_serialize', array('token')); } - $allowRegistration = Configure::read('Users.allowRegistration'); - $this->set('allowRegistration', (is_null($allowRegistration) ? true : $allowRegistration)); } + /** - * Search - Requires the CakeDC Search plugin to work + * Common login action * - * @throws MissingPluginException * @return void - * @link https://github.com/CakeDC/search */ - public function search() { - $this->_pluginLoaded('Search'); + public function login() { + $Event = new CakeEvent( + 'Users.Controller.Users.beforeLogin', + $this, + array( + 'data' => $this->request->data, + ) + ); - $searchTerm = ''; - $this->Prg->commonProcess($this->modelClass); + $this->getEventManager()->dispatch($Event); - $by = null; - if (!empty($this->request->params['named']['search'])) { - $searchTerm = $this->request->params['named']['search']; - $by = 'any'; + if ($Event->isStopped()) { + return; } - if (!empty($this->request->params['named']['username'])) { - $searchTerm = $this->request->params['named']['username']; - $by = 'username'; + + if ($this->request->is(['post', 'ajax'])) { + $this->__loguearUsuario(); } - if (!empty($this->request->params['named']['email'])) { - $searchTerm = $this->request->params['named']['email']; - $by = 'email'; + + // si ext es json, devolvemos el usuario el token de JWT + if ( $this->request->ext == 'json' ) { + if ( $this->Auth->user() ) { + $jwt = JwtUtil::generateToken( $this->Auth->user() ); + $this->set('jwt', $jwt); + $this->set('_serialize', array('jwt')); + } } - $this->request->data[$this->modelClass]['search'] = $searchTerm; - - $this->Paginator->settings = 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->Paginator->paginate($this->modelClass)); - $this->set('searchTerm', $searchTerm); + if (isset($this->request->params['named']['return_to'])) { + $this->set('return_to', urldecode($this->request->params['named']['return_to'])); + } elseif (isset($this->request->query['return_to'])) { + $this->set('return_to', $this->request->query['return_to']); + } else { + $this->set('return_to', false); + } + $allowRegistration = Configure::read('Users.allowRegistration'); + $this->set('allowRegistration', (is_null($allowRegistration) ? true : $allowRegistration)); } + + /** * Common logout action * @@ -682,6 +847,8 @@ public function change_password() { // we don't want to keep the cookie with the old password around $this->RememberMe->destroyCookie(); $this->redirect('/'); + } else { + $this->Session->setFlash(__d('users', 'Error changing the password, please try again.'), 'Risto.Flash/flash_error'); } } } @@ -783,18 +950,21 @@ protected function _sendPasswordReset($admin = null, $options = array()) { $user = $this->{$this->modelClass}->passwordReset($this->request->data); if (!empty($user)) { - - $Email = $this->_getMailInstance(); - $Email->to($user[$this->modelClass]['email']) - ->from($options['from']) - ->emailFormat($options['emailFormat']) - ->subject($options['subject']) - ->template($options['template'], $options['layout']) - ->viewVars(array( - 'model' => $this->modelClass, - 'user' => $this->{$this->modelClass}->data, - 'token' => $this->{$this->modelClass}->data[$this->modelClass]['password_token'])) - ->send(); + try { + $Email = $this->_getMailInstance(); + $Email->to($user[$this->modelClass]['email']) + ->from($options['from']) + ->emailFormat($options['emailFormat']) + ->subject($options['subject']) + ->template($options['template'], $options['layout']) + ->viewVars(array( + 'model' => $this->modelClass, + 'user' => $this->{$this->modelClass}->data, + 'token' => $this->{$this->modelClass}->data[$this->modelClass]['password_token'])) + ->send(); + } catch (Exception $e) { + $this->log("ERROR al enviar mails:: ".$e->getMessage()); + } if ($admin) { $this->Session->setFlash(sprintf( @@ -874,7 +1044,187 @@ protected function _getMailInstance() { * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#using-controllerauthorize */ public function isAuthorized($user = null) { - return parent::isAuthorized($user); + $ret = parent::isAuthorized($user); + if ( $this->action == 'index') { + + if( !userIsAdmin($user) ){ + $ret = false; + } + } + + return $ret; } + + + + /** + * + * ------------------------------------------------------------------------------------------- + * + * OAUTH + */ + + public function auth_login($provider) { + $result = $this->ExtAuth->login($provider); + if ($result['success']) { + $this->Auth->loginRedirect = $result['redirectURL']; + $this->redirect( $this->Auth->loginRedirect ); + } else { + $this->Session->setFlash($result['message']); + $this->redirect($this->Auth->redirectUrl()); + } + } + + public function auth_callback($provider) { + $result = $this->ExtAuth->loginCallback($provider); + + if ($result['success']) { + try { + $this->__successfulExtAuth($result['profile'], $result['accessToken']); + } catch (Exception $e) { + $this->Session->setFlash("No se ha podido registrar con las credenciales. Pruebe con otra red social, o, por favor, crear una cuenta PaxaPos en lugar de usas sus cuentas existentes: ".$e->getMessage(), 'Risto.flash_error'); + } + } else { + $this->Session->setFlash($result['message']); + } + $this->redirect($this->Auth->redirectUrl() ); + } + + + private function __loginExistingProfile( $existingProfile ){ + $this->__doAuthLogin($existingProfile); + } + + + private function __loginExistingUserWithNoProfile( $user, $incomingProfile, $accessToken ){ + + + // User exists but never (logged using oauth) saved UserProfile => save UserProfile + // $incomingProfile['user_id'] = $user['User']['id']; + $incomingProfile['last_login'] = date('Y-m-d h:i:s'); + $incomingProfile['access_token'] = serialize($accessToken); + $this->__attachProfileToUser($user['User']['id'], $incomingProfile); + + // log in + $this->__doAuthLogin($user); + $this->redirect($this->Auth->redirectUrl()); + } + + + private function __attachProfileToUser( $userId, $incomingProfile ){ + // user logged in already, attach profile to logged in user. + // create social profile linked to current user + $incomingProfile['user_id'] = $userId; + if ( $this->User->SocialProfile->save($incomingProfile) ) { + $this->Session->setFlash('Your ' . $incomingProfile['provider'] . ' account has been linked.'); + } else { + $this->Session->setFlash('Your ' . $incomingProfile['provider'] . ' account could not be linked.', 'Risto.flash_error'); + } + } + + private function __loginNewRegistration( $incomingProfile, $accessToken ) { + // no-one logged in, must be a registration. + unset($incomingProfile['id']); + $this->User->validate['email']['isValid']['required'] = false; + $this->User->validate['email']['isValid']['allowEmpty'] = true; + $this->User->validate['email']['isUnique']['required'] = false; + $this->User->validate['email']['isUnique']['allowEmpty'] = true; + + if ( empty( $incomingProfile['username'] ) ) { + if ( !empty($incomingProfile['email']) ) { + $incomingProfile['username'] = $incomingProfile['email']; + } else if ( !empty($incomingProfile['first_name']) || !empty($incomingProfile['last_name'])) { + $nom = !empty($incomingProfile['first_name']) ? $incomingProfile['first_name']:""; + $ape = !empty($incomingProfile['last_name']) ? $incomingProfile['last_name']:""; + $username = Inflector::slug( $nom.$ape ); + $incomingProfile['username'] = $username."_" . substr( CakeText::uuid(), rand(0,36), 4 ); + } else { + $incomingProfile['username'] = 'UsuarioOauth_'. substr( CakeText::uuid(), rand(0,36), 4 ); + } + } + + $user = $this->User->register(array('User' => $incomingProfile), array('emailVerification'=>false)); + if (!$user) { + throw new CakeException(__d('users', 'Error registering users')); + } + // create social profile linked to new user + $incomingProfile['user_id'] = $user['User']['id']; + $incomingProfile['last_login'] = date('Y-m-d h:i:s'); + $incomingProfile['access_token'] = serialize($accessToken); + $this->User->SocialProfile->save($incomingProfile); + + // log in + $this->__doAuthLogin($user); + } + + + private function __successfulExtAuth($incomingProfile, $accessToken) { + // search for profile + $this->User->SocialProfile->recursive = -1; + $oid = !empty($incomingProfile['oid']) ? $incomingProfile['oid'] : ''; + $oid = !empty($incomingProfile['id']) ? $incomingProfile['id'] : $oid; + + $existingProfile = $this->User->SocialProfile->find('first', array( + 'conditions' => array('SocialProfile.oid' => $oid), + 'contain' => array('User'=>['Site','SuperRol']) + )); + if ($existingProfile) { + $this->__loginExistingProfile($existingProfile); + } else { + + // New profile. + if ($this->Auth->loggedIn()) { + // user logged in already, attach profile to logged in user. + // create social profile linked to current user + $userId = $this->Auth->user('id'); + $this->__attachProfileToUser( $userId, $incomingProfile ); + $this->redirect($this->Auth->redirectUrl()); + + } else { + + // verificar que no se haya registrado con otra credencial + if ( !empty( $incomingProfile['email'] ) ) { + $user = $this->User->find('first', array( + 'conditions' => array('User.email' => $incomingProfile['email']), + 'contain' => array('Site'), + )); + if ( $user ) { + // crea el nuevo profile,. lo vincula con el usuario y logea + $this->__loginExistingUserWithNoProfile( $user, $incomingProfile, $accessToken ); + } + } + + + $this->__loginNewRegistration( $incomingProfile, $accessToken ); + } + } + } + + private function __doAuthLogin($user) { + if ($this->Auth->login($user['User'])) { + + $this->{$this->modelClass}->id = $user['User']['id']; + $this->{$this->modelClass}->saveField('last_login', date('Y-m-d H:i:s')); + + $Event = new CakeEvent( + 'Users.Controller.Users.afterLogin', + $this, + array( + 'data' => $user, + 'isFirstLogin' => !$this->Auth->user('last_login') + ) + ); + + $this->getEventManager()->dispatch($Event); + + $this->Session->setFlash(sprintf(__d('users', '%s you have successfully logged in'), $this->Auth->user('username'))); + + $redUrl = $this->Auth->redirectUrl(); + if ( $this->Auth->redirectUrl() != '/') { + $redUrl = $this->Auth->redirectUrl() ."/"; + } + $this->redirect( $redUrl ); + } + } } diff --git a/Model/GenericUser.php b/Model/GenericUser.php new file mode 100644 index 000000000..e2584e601 --- /dev/null +++ b/Model/GenericUser.php @@ -0,0 +1,106 @@ + array( + 'rule' => array('esUnicoPeroNoBorrado'), + 'message' => 'Este PIN ya está siendo utilizado por otro usuario. Por favor ingresar otro número', + //'allowEmpty' => false, + //'required' => false, + //'last' => false, // Stop validation after this rule + 'on' => 'create', // Limit validation to 'create' or 'update' operations + ), + 'rol_id' => array( + 'numeric' => array( + 'rule' => array('numeric'), + //'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 + ), + ), + ); + + // 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( + 'Rol' => array( + 'className' => 'Users.Rol', + 'foreignKey' => 'rol_id', + 'conditions' => '', + 'fields' => '', + 'order' => '', + ) + ); + +/** + * lista todos los usuarios genericos + * + * @return array + */ + +public function listarGenericosConNombreRol($ops = []) { + + $default = array( + 'fields' => ['GenericUser.id', 'GenericUser.username'], + 'recursive' => -1, + 'contain' => array( + 'Rol(name)' + ) + ); + $ops = Hash::merge($default, $ops); + $ret = $this->find('list', $ops); + return $ret; + +} + + /** + * Regla de validación que comprueba si el pin es unico, y a su vez, que + * el campo deleted este en cero, para lanzar mensaje de error avisando + * de que ya existe un usuario generico con ese pin. + * + * @param $pin = el pin del usuario generico a crear. + * @example $pin = array("pin" => 2018); + * + * @return boolean true || false + */ + + public function esUnicoPeroNoBorrado($pin) { + $existeUsuarioGenerico = $this->find('count', + array( + 'conditions' => array($pin, 'GenericUser.deleted' => 0), + 'recursive' => -1 + ) + ); + + if ($existeUsuarioGenerico > 0) { + return false; + } + + return true; + } + +} diff --git a/Model/Rol.php b/Model/Rol.php new file mode 100644 index 000000000..9d0b45401 --- /dev/null +++ b/Model/Rol.php @@ -0,0 +1,89 @@ + array( + 'className' => 'Users.User', + 'joinTable' => 'roles_users', + 'foreignKey' => 'rol_id', + 'associationForeignKey' => 'user_id', + 'unique' => 'keepExisting', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'finderQuery' => '', + 'with' => 'Users.RolUser' + ) + ); + + + + + +/** + * Validation rules + * + * @var array + */ + public $validate = array( + 'name' => array( + 'notBlank' => array( + 'rule' => array('notBlank'), + //'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 + ), + ), + 'machin_name' => array( + 'notBlank' => array( + 'rule' => array('notBlank'), + //'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 + ), + ), + ); + + //The Associations below have been created with all possible keys, those that are not needed can be removed + + + + public function beforeSave($options = array()) { + if (empty($this->data['Rol']['machin_name']) && empty($this->data['Rol']['id'])) { + $this->data['Rol']['machin_name'] = strtolower( Inflector::slug( $this->data['Rol']['name'])) ; + } + return true; + } + + +} diff --git a/Model/RolUser.php b/Model/RolUser.php new file mode 100644 index 000000000..cd80e5526 --- /dev/null +++ b/Model/RolUser.php @@ -0,0 +1,39 @@ +request->data (array con las ids de roles + id usuario en sub-indices) + * @return true + */ + public function asignarRol($data) { + $this->deleteAll(array('user_id' => $data['User']['id']), false); + $indice = 0; + if($data['Rol']['Rol'] == null) { + return true; + } + foreach($data['Rol']['Rol'] as $r) { + + $rolesUser[$indice] = array('user_id' => $data['User']['id'], 'rol_id' => $r); + + $indice = $indice + 1; + } + $this->saveAll($rolesUser); + return true; + } + +} \ No newline at end of file diff --git a/Model/SocialProfile.php b/Model/SocialProfile.php new file mode 100644 index 000000000..a9f4e2dad --- /dev/null +++ b/Model/SocialProfile.php @@ -0,0 +1,16 @@ + array( + 'className' => 'Users.User', + 'joinTable' => 'super_roles_users', + 'foreignKey' => 'rol_id', + 'associationForeignKey' => 'user_id', + 'unique' => 'keepExisting', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'finderQuery' => '', + 'with' => 'Users.SuperRolUser' + ) + ); + + + + + +/** + * Validation rules + * + * @var array + */ + public $validate = array( + 'name' => array( + 'notBlank' => array( + 'rule' => array('notBlank'), + //'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 + ), + ), + 'machin_name' => array( + 'notBlank' => array( + 'rule' => array('notBlank'), + //'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 + ), + ), + ); + + + +} diff --git a/Model/SuperRolUser.php b/Model/SuperRolUser.php new file mode 100644 index 000000000..6be1b62e5 --- /dev/null +++ b/Model/SuperRolUser.php @@ -0,0 +1,35 @@ +request->data (array con las ids de roles + id usuario en sub-indices) + * @return true + */ + public function asignarRol($data) { + $this->deleteAll(array('user_id' => $data['User']['id']), false); + $indice = 0; + if($data['SuperRol']['SuperRol'] == null) { + return true; + } + foreach($data['SuperRol']['SuperRol'] as $r) { + + $rolesUser[$indice] = array('user_id' => $data['User']['id'], 'rol_id' => $r); + + $indice = $indice + 1; + } + $this->saveAll($rolesUser); + return true; + } + +} \ No newline at end of file diff --git a/Model/User.php b/Model/User.php index a73ab8c56..9b8ed1740 100644 --- a/Model/User.php +++ b/Model/User.php @@ -13,7 +13,8 @@ App::uses('UsersAppModel', 'Users.Model'); App::uses('SearchableBehavior', 'Search.Model/Behavior'); App::uses('SluggableBehavior', 'Utils.Model/Behavior'); - +App::uses('MtSites', 'MtSites.Utility'); +App::uses('CakeText', 'Utility'); /** * Users Plugin User Model * @@ -46,9 +47,114 @@ class User extends UsersAppModel { */ public $filterArgs = array( 'username' => array('type' => 'like'), - 'email' => array('type' => 'value') + 'email' => array('type' => 'value'), + 'txt_search' => array( + 'type' => 'query', + 'method' => '__searchTextGeneric' + ), + 'site_alias' => array( + 'type' => 'expression', + 'method' => '__searchFromSite', + 'field' => 'User.id', + ), + ); + + +/** + * hasMany associations + * + * @var array + */ + public $hasMany = array( + 'SocialProfile' => array( + 'className' => 'Users.SocialProfile', + 'foreignKey' => 'user_id', + 'unique' => 'keepExisting', + 'dependent' => true, + ), ); + +/** + * hasAndBelongsToMany associations + * + * @var array + */ + public $hasAndBelongsToMany = array( + 'Site' => array( + 'className' => 'MtSites.Site', + 'joinTable' => 'sites_users', + 'foreignKey' => 'user_id', + 'associationForeignKey' => 'site_id', + 'unique' => 'keepExisting', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'finderQuery' => '', + 'with' => 'MtSites.SiteUser' + ), + 'Rol' => array( + 'className' => 'Users.Rol', + 'joinTable' => 'roles_users', + 'foreignKey' => 'user_id', + 'associationForeignKey' => 'rol_id', + 'unique' => 'keepExisting', + 'conditions' => array('RolUser.deleted' => 0), + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'finderQuery' => '', + 'with' => 'Users.RolUser' + ), + 'Caja' => array( + 'className' => 'Cash.Caja', + 'joinTable' => 'cash_cajas_users', + 'foreignKey' => 'user_id', + 'associationForeignKey' => 'caja_id', + 'unique' => 'keepExisting', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'finderQuery' => '', + 'with' => 'Cash.CajaUser' + ), + 'Mozo' => array( + 'className' => 'Mesa.Mozo', + 'joinTable' => 'mozos_users', + 'foreignKey' => 'user_id', + 'associationForeignKey' => 'mozo_id', + 'unique' => 'keepExisting', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'finderQuery' => '', + 'with' => 'Mesa.MozoUser' + ), + + 'SuperRol' => array( + 'className' => 'Users.SuperRol', + 'joinTable' => 'super_roles_users', + 'foreignKey' => 'user_id', + 'associationForeignKey' => 'rol_id', + 'unique' => 'keepExisting', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'finderQuery' => '', + 'with' => 'Users.SuperRolUser' + ), + ); + + /** * Displayfield * @@ -91,13 +197,11 @@ class User extends UsersAppModel { '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.' + 'message' => 'This username is already in use.', + 'on' => 'create', ), 'username_min' => array( 'rule' => array('minLength', '3'), @@ -112,7 +216,8 @@ class User extends UsersAppModel { ), 'isUnique' => array( 'rule' => array('isUnique', 'email'), - 'message' => 'This email is already in use.' + 'message' => 'This email is already in use.', + 'on' => 'create', ) ), 'password' => array( @@ -120,6 +225,10 @@ class User extends UsersAppModel { 'rule' => array('minLength', '6'), 'message' => 'The password must have at least 6 characters.' ), + 'required' => array( + 'rule' => 'notBlank', + 'message' => 'Please enter a password.' + ) ), 'temppassword' => array( 'rule' => 'confirmPassword', @@ -139,11 +248,16 @@ class User extends UsersAppModel { * @param string $ds Datasource */ public function __construct($id = false, $table = null, $ds = null) { + + $this->_setupBehaviors(); $this->_setupValidation(); parent::__construct($id, $table, $ds); + } + + /** * Setup available plugins * @@ -182,6 +296,7 @@ protected function _setupValidation() { ); } + /** * Create a hash from string using given method. * Fallback on next available method. @@ -314,7 +429,8 @@ public function passwordReset($postData = array()) { $this->alias . '.active' => 1, $this->alias . '.email' => $postData[$this->alias]['email']))); - if (!empty($user) && $user[$this->alias]['email_verified'] == 1) { + //if (!empty($user) && $user[$this->alias]['email_verified'] == 1) { + if(!empty($user)) { $sixtyMins = time() + 43000; $token = $this->generateToken(); $user[$this->alias]['password_token'] = $token; @@ -322,8 +438,8 @@ public function passwordReset($postData = array()) { $user = $this->save($user, false); $this->data = $user; return $user; - } elseif (!empty($user) && $user[$this->alias]['email_verified'] == 0) { - $this->invalidate('email', __d('users', 'This Email Address exists but was never validated.')); + //} 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.')); } @@ -403,7 +519,17 @@ public function changePassword($postData = array()) { $this->validate = $this->validatePasswordChange; $this->set($postData); - if ($this->validates()) { + $this->validates(); //tuve que hacer pequeñas modificaciones, lee el issue #117 para saber el porque. + + $erroresValidaciones = $this->validationErrors; + + if(empty($erroresValidaciones)) { + $allOK = true; //si no hay errores pasa por acá + } else { + $allOK = false; //sino acá + } + + if ($allOK) { //si es true hace esto $this->data[$this->alias]['password'] = $this->hash($this->data[$this->alias]['new_password'], null, true); $this->save($postData, array( 'validate' => false, @@ -412,6 +538,14 @@ public function changePassword($postData = array()) { } return false; } + + public function hashNewPassword($postData = array()) { + if(userIsAdmin()) { + $postData[$this->alias]['password'] = $this->hash($postData[$this->alias]['password'], null, true); + return $postData; + } + return false; + } /** * Validation method to check the old password @@ -496,6 +630,24 @@ public function findByEmail($email = null) { )); } +/** + * Buscar usuarios con las IDs del filtrado previo de usuarios por sitio (comercio). + * Se usa para sacar los usernames y así crear la lista de usuarios (select) del action + * cambiar_creador (para los arqueos). El is_admin va como condición que sea 0 para evitar + * que los admins que puedan entrar en comercios de otros usuarios para brindar un mejor soporte + * aparezcan en dicho listado. + * + * @param array $users con ids de usuarios. + * @return array $usernames['id_usuario' => 'nombre_usuario']; + */ + public function findById($users) { + + $usernames[] = array($this->find('list',array( + 'conditions' => array('id' => $users)))); + + return $usernames; + } + /** * Checks if an email is already verified and if not renews the expiration time * @@ -562,7 +714,7 @@ public function register($postData = array(), $options = array()) { $defaults = array( 'emailVerification' => true, - 'removeExpiredRegistrations' => true, + 'removeExpiredRegistrations' => false, 'returnData' => true); extract(array_merge($defaults, $options)); @@ -571,9 +723,12 @@ public function register($postData = array(), $options = array()) { if ($removeExpiredRegistrations) { $this->_removeExpiredRegistrations(); } - $this->set($postData); if ($this->validates()) { + if ( empty( $postData[$this->alias]['password'] )) { + // Oauth registering + $postData[$this->alias]['password'] = CakeText::uuid(); + } $postData[$this->alias]['password'] = $this->hash($postData[$this->alias]['password'], 'sha1', true); $this->create(); $this->data = $this->save($postData, false); @@ -832,6 +987,7 @@ public function add($postData = null) { } $postData[$this->alias]['password'] = $this->hash($postData[$this->alias]['password'], 'sha1', true); $this->create(); + $result = $this->save($postData, false); if ($result) { $result[$this->alias][$this->primaryKey] = $this->id; @@ -843,6 +999,17 @@ public function add($postData = null) { return false; } + + + public function edit($postData = null) { + if (!empty($postData)) { + $this->data = $postData; + $this->create(); + return $this->save($postData, ['fieldList' => ['User.id' ]]); + } + return false; + } + /** * Edits an existing user * @@ -852,13 +1019,16 @@ public function add($postData = null) { * @param array $postData controller post data usually $this->data * @throws NotFoundException * @return mixed True on successfully save else post data as array - */ + public function edit($userId = null, $postData = null) { + debug($this->data); + die; $user = $this->getUserForEditing($userId); $this->set($user); if (!empty($postData)) { $this->set($postData); if ($this->validates()) { + $this->data = array('User' => $this->data['User']); if(isset($postData[$this->alias]['password'])) { $this->data[$this->alias]['password'] = $this->hash($postData[$this->alias]['password'], 'sha1', true); } @@ -872,6 +1042,7 @@ public function edit($userId = null, $postData = null) { } } } +*/ /** * Gets the user data that needs to be edited @@ -909,10 +1080,13 @@ public function getUserForEditing($userId = null, $options = array()) { * @return void */ protected function _removeExpiredRegistrations() { + // no queremos eliminar a los expirados + /* $this->deleteAll(array( $this->alias . '.email_verified' => 0, $this->alias . '.email_token_expires <' => date('Y-m-d H:i:s')) ); + */ } /** @@ -928,4 +1102,92 @@ public function getMailInstance() { } return new CakeEmail('default'); } + + +/** + * Returns an array $conditions for Search Plugin $filterArgs + * + * @return array + */ + public function __searchTextGeneric ($data = array() ) { + $condition = array( + 'OR' => array( + 'lower(User.username) LIKE' => '%'. trim(strtolower( $data['txt_search'] )) .'%', + 'lower(User.email) LIKE' => '%'. trim(strtolower( $data['txt_search'] )) .'%', + )); + return $condition; + } + + + +/** + * + * Returns an array of User id for Searchg Plugin $filterArgs + * + * @return array + */ + public function __searchFromSite ($data = array() ) { + $sites = $this->Site->find('all', array('conditions'=>array( + 'Site.alias' => $data['site_alias'] + ), + )); + $users = Hash::extract($sites, '{n}.User.{n}.id'); + return $users; + } + + + + public function addIntoSite( $site_id, $user_id = null ){ + if ( is_null( $user_id) ) { + $user_id = $this->id; + } + + $siteUser['SiteUser']['site_id'] = $site_id; + $siteUser['SiteUser']['user_id'] = $user_id; + return $this->SiteUser->save($siteUser, array('fieldList', array('SiteUser.site_id', 'SiteUser.user_id'))); + } + + public function addRoleIntoSite ( $rol_id, $user_id = null ) { + if ( is_null( $user_id) ) { + $user_id = $this->id; + } + + $user['RolUser']['rol_id'] = $rol_id; + $user['RolUser']['user_id'] = $user_id; + + $this->hasAndBelongsToMany['Rol']['unique'] = false; + + return $this->RolUser->save( $user ); + } + +/* + public function getSitesSuperRolesForSession($userId){ + $user = ClassRegistry::init('Users.User', true)->find('first', array( + 'conditions' => array('User.id' => $userId), + 'contain' => ['Site','SuperRol'], + )); + if ( !$user ) { + return false; + } + + $nuser = $user['User']; + $nuser['Site'] = $user['Site']; + $nuser['SuperRol'] = $user['SuperRol']; + return $nuser; + } +*/ + + public function getSites($userId){ + $user = $this->find('first', array( + 'fields' => ['User.id'], + 'conditions' => array('User.id' => $userId), + 'contain' => ['Site(name,alias)'] + )); + if ( !empty($user['Site'] ) ) { + return $user['Site']; + } + + return []; + } + } diff --git a/Model/UsersAppModel.php b/Model/UsersAppModel.php index 94765e049..5259f6966 100644 --- a/Model/UsersAppModel.php +++ b/Model/UsersAppModel.php @@ -19,6 +19,11 @@ */ class UsersAppModel extends AppModel { + + public $cacheQueries = true; + + + /** * Plugin name * @@ -39,9 +44,14 @@ class UsersAppModel extends AppModel { * @var array */ public $actsAs = array( - 'Containable' + 'Containable', + 'Search.Searchable', + 'Risto.RistoSoftDelete', ); + + + /** * Customized paginateCount method * diff --git a/Test/Case/Controller/GenericUseresControllerTest.php b/Test/Case/Controller/GenericUseresControllerTest.php new file mode 100644 index 000000000..ee317ba6e --- /dev/null +++ b/Test/Case/Controller/GenericUseresControllerTest.php @@ -0,0 +1,64 @@ +markTestIncomplete('testIndex not implemented.'); + } + +/** + * testView method + * + * @return void + */ + public function testView() { + $this->markTestIncomplete('testView not implemented.'); + } + +/** + * testAdd method + * + * @return void + */ + public function testAdd() { + $this->markTestIncomplete('testAdd not implemented.'); + } + +/** + * testEdit method + * + * @return void + */ + public function testEdit() { + $this->markTestIncomplete('testEdit not implemented.'); + } + +/** + * testDelete method + * + * @return void + */ + public function testDelete() { + $this->markTestIncomplete('testDelete not implemented.'); + } + +} diff --git a/Test/Case/Model/GenericUserTest.php b/Test/Case/Model/GenericUserTest.php new file mode 100644 index 000000000..12a201ea9 --- /dev/null +++ b/Test/Case/Model/GenericUserTest.php @@ -0,0 +1,40 @@ +GenericUser = ClassRegistry::init('Users.GenericUser'); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + unset($this->GenericUser); + + parent::tearDown(); + } + +} diff --git a/Test/Case/Model/RolTest.php b/Test/Case/Model/RolTest.php new file mode 100644 index 000000000..5ed342906 --- /dev/null +++ b/Test/Case/Model/RolTest.php @@ -0,0 +1,41 @@ +Rol = ClassRegistry::init('Users.Rol'); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + unset($this->Rol); + + parent::tearDown(); + } + +} diff --git a/Test/Case/Model/UserTest.php b/Test/Case/Model/UserTest.php old mode 100755 new mode 100644 diff --git a/Test/Fixture/GenericUserFixture.php b/Test/Fixture/GenericUserFixture.php new file mode 100644 index 000000000..a62b16a6d --- /dev/null +++ b/Test/Fixture/GenericUserFixture.php @@ -0,0 +1,47 @@ + 'Users.GenericUser']; + + public $table = 'generic_users'; + + public $fields = array( + 'id' => array('type' => 'integer', 'null' => false, 'length' => 10, 'unsigned' => true, 'key' => 'primary'), + 'pin' => array('type' => 'string', 'null' => true, 'length' => 128), + 'username' => array('type' => 'string', 'null' => true, 'length' => 128), + 'rol_id' => array('type' => 'integer', 'null' => false, 'length' => 10, 'unsigned' => true), + 'created' => array('type' => 'datetime', 'null' => true), + 'modified' => array('type' => 'datetime', 'null' => true), + 'created_by' => array('type' => 'string', 'length' => 36, 'null' => true), + + 'deleted_date' => array('type' => 'datetime', 'null' => true), + 'deleted' => array('type' => 'boolean', 'null' => false, 'default' => false), + + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'pin' => array('column' => 'pin', 'unique' => 0), + ), + ); + + + +/** + * Records + * + * @var array + */ + public $records = array( + array( + 'id' => 1, + 'pin' => '1234', + 'username' => 'usergeneric', + 'rol_id' => 1, + 'created' => 1464795357, + 'modified' => 1464795357 + ), + ); + +} diff --git a/Test/Fixture/Migrations201704/Rol201704Fixture.php b/Test/Fixture/Migrations201704/Rol201704Fixture.php new file mode 100644 index 000000000..8094d6365 --- /dev/null +++ b/Test/Fixture/Migrations201704/Rol201704Fixture.php @@ -0,0 +1,86 @@ + array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), + 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 64, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'machin_name' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 64, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'created' => array('type' => 'timestamp', 'null' => true, 'default' => null), + 'modified' => array('type' => 'timestamp', 'null' => true, 'default' => null), + 'created_by' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 36, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'deleted_date' => array('type' => 'timestamp', 'null' => true, 'default' => null), + 'deleted' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 4, 'unsigned' => false), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + +/** + * Records + * + * @var array + */ + public $records = array( + array( + 'id' => '1', + 'name' => 'Mozo', + 'machin_name' => ROL_MOZO, + 'created' => '2017-04-07 20:27:39', + 'modified' => '2017-04-07 20:27:39', + 'created_by' => null, + 'deleted_date' => null, + 'deleted' => '0' + ), + array( + 'id' => '2', + 'name' => 'Cajero', + 'machin_name' => ROL_CAJERO, + 'created' => '2017-04-07 20:27:39', + 'modified' => '2017-04-07 20:27:39', + 'created_by' => null, + 'deleted_date' => null, + 'deleted' => '0' + ), + array( + 'id' => '3', + 'name' => 'Encargado', + 'machin_name' => ROL_ENCARGADO, + 'created' => '2017-04-07 20:27:39', + 'modified' => '2017-04-07 20:27:39', + 'created_by' => null, + 'deleted_date' => null, + 'deleted' => '0' + ), + array( + 'id' => '4', + 'name' => 'Cocinero', + 'machin_name' => ROL_COCINERO, + 'created' => '2017-04-07 20:27:39', + 'modified' => '2017-04-07 20:27:39', + 'created_by' => null, + 'deleted_date' => null, + 'deleted' => '0' + ), + array( + 'id' => '5', + 'name' => 'Cocinero', + 'machin_name' => ROL_MOZO, + 'created' => '2017-04-07 20:27:39', + 'modified' => '2017-04-07 20:27:39', + 'created_by' => null, + 'deleted_date' => null, + 'deleted' => '0' + ), + ); +} diff --git a/Test/Fixture/RolFixture.php b/Test/Fixture/RolFixture.php new file mode 100644 index 000000000..79621421f --- /dev/null +++ b/Test/Fixture/RolFixture.php @@ -0,0 +1,66 @@ + 'Users.Rol', 'connection' => 'test_tenant']; + +/** + * Records + * + * @var array + */ + public $records = array( + array( + 'id' => '1', + 'name' => 'Mozo', + 'machin_name' => ROL_MOZO, + 'created' => '2017-04-07 20:27:39', + 'modified' => '2017-04-07 20:27:39', + 'created_by' => null, + 'deleted_date' => null, + 'deleted' => '0' + ), + array( + 'id' => '2', + 'name' => 'Cajero', + 'machin_name' => ROL_CAJERO, + 'created' => '2017-04-07 20:27:39', + 'modified' => '2017-04-07 20:27:39', + 'created_by' => null, + 'deleted_date' => null, + 'deleted' => '0' + ), + array( + 'id' => '3', + 'name' => 'Encargado', + 'machin_name' => ROL_ENCARGADO, + 'created' => '2017-04-07 20:27:39', + 'modified' => '2017-04-07 20:27:39', + 'created_by' => null, + 'deleted_date' => null, + 'deleted' => '0' + ), + array( + 'id' => '4', + 'name' => 'Cocinero', + 'machin_name' => ROL_COCINERO, + 'created' => '2017-04-07 20:27:39', + 'modified' => '2017-04-07 20:27:39', + 'created_by' => null, + 'deleted_date' => null, + 'deleted' => '0' + ), + array( + 'id' => '5', + 'name' => 'Dueño', + 'machin_name' => ROL_DUENIO, + 'created' => '2017-04-07 20:27:39', + 'modified' => '2017-04-07 20:27:39', + 'created_by' => null, + 'deleted_date' => null, + 'deleted' => '0' + ), + ); +} diff --git a/Test/Fixture/RolUserFixture.php b/Test/Fixture/RolUserFixture.php new file mode 100644 index 000000000..24c0f810a --- /dev/null +++ b/Test/Fixture/RolUserFixture.php @@ -0,0 +1,7 @@ + 'Users.RolUser', 'connection' => 'test_tenant', 'records' => true]; +} diff --git a/Test/Fixture/UserFixture.php b/Test/Fixture/UserFixture.php index 838df1cd2..af19a178d 100644 --- a/Test/Fixture/UserFixture.php +++ b/Test/Fixture/UserFixture.php @@ -1,195 +1,75 @@ 'Users.User'); -/** - * Table - * - * @var array $table - */ public $table = 'users'; +// public $canUseMemory = false; + /** * Fields * * @var array */ public $fields = array( - '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), - '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_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_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), - 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'indexes' => array( - 'PRIMARY' => array('column' => 'id', 'unique' => 1)) - ); + 'id' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 36, 'key' => 'primary', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'username' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'slug' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'password' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 128, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'password_token' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 128, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'email' => array('type' => 'string', 'null' => true, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'email_verified' => array('type' => 'boolean', 'null' => true, 'default' => '0'), + 'email_token' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + '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, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'deleted_date' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'deleted' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 4, 'unsigned' => false), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'BY_USERNAME' => array('column' => 'username', 'unique' => 0), + 'BY_EMAIL' => array('column' => 'email', 'unique' => 0) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); /** * Records * - * @var array + * @var arra */ public $records = array( array( - 'id' => '1', - 'username' => 'adminuser', - 'slug' => 'adminuser', - 'password' => 'test', // test - 'password_token' => 'testtoken', - 'email' => 'adminuser@cakedc.com', + 'id' => '590b8e47-d5e8-4691-b578-47bca73ba8b7', + 'username' => 'pascual_el_admin', + 'slug' => 'Lorem ipsum dolor sit amet', + 'password' => 'Lorem ipsum dolor sit amet', + 'password_token' => 'Lorem ipsum dolor sit amet', + 'email' => 'Lorem ipsum dolor sit amet', 'email_verified' => 1, - 'email_token' => 'testtoken', - 'email_token_expires' => '2008-03-25 02:45:46', + 'email_token' => 'Lorem ipsum dolor sit amet', + 'email_token_expires' => '2017-05-04 17:25:43', 'tos' => 1, 'active' => 1, - 'last_action' => '2008-03-25 02:45:46', - 'last_login' => '2008-03-25 02:45:46', + 'last_login' => '2017-05-04 17:25:43', + 'last_action' => '2017-05-04 17:25:43', 'is_admin' => 1, - 'role' => 'admin', - 'created' => '2008-03-25 02:45:46', - 'modified' => '2008-03-25 02:45:46' - ), - array( - 'id' => '47ea303a-3cyc-k251-b313-4811c0a800bf', - 'username' => 'testuser', - 'slug' => 'testuser', - 'password' => 'secretkey', // secretkey - 'password_token' => '', - 'email' => 'testuser@cakedc.com', - 'email_verified' => '1', - 'email_token' => '', - 'email_token_expires' => '2008-03-25 02:45:46', - 'tos' => 1, - 'active' => 1, - 'last_action' => '2008-03-25 02:45:46', - 'last_login' => '2008-03-25 02:45:46', - 'is_admin' => 0, - 'role' => 'user', - 'created' => '2008-03-25 02:45:46', - 'modified' => '2008-03-25 02:45:46' - ), - array( - 'id' => '37ea303a-3bdc-4251-b315-1316c0b300fa', - 'username' => 'user1', - 'slug' => 'user1', - 'password' => 'newpass', // newpass - 'password_token' => '', - 'email' => 'testuser1@testuser.com', - 'email_verified' => 0, - 'email_token' => 'testtoken2', - 'email_token_expires' => '2008-03-28 02:45:46', - 'tos' => 0, - 'active' => 0, - 'last_action' => '2008-03-25 02:45:46', - 'last_login' => '2008-03-25 02:45:46', - 'is_admin' => 0, - 'role' => 'user', - 'created' => '2008-03-25 02:45:46', - 'modified' => '2008-03-25 02:45:46' - ), - array( - 'id' => '495e36a2-1f00-46b9-8247-58a367265f11', - 'username' => 'oidtest', - 'slug' => 'oistest', - 'password' => 'newpass', // newpass - 'password_token' => '', - 'email' => 'oidtest@testuser.com', - 'email_verified' => 0, - 'email_token' => 'testtoken2', - 'email_token_expires' => '2008-03-28 02:45:46', - 'tos' => 0, - 'active' => 0, - 'last_action' => '2008-03-25 02:45:46', - 'last_login' => '2008-03-25 02:45:46', - 'is_admin' => 0, - 'role' => 'user', - 'created' => '2008-03-25 02:45:46', - 'modified' => '2008-03-25 02:45:46' - ), - array( - 'id' => '315e36a2-1fxj-46b9-8247-58a367265f11', - 'username' => 'oidtest2', - 'slug' => 'oistest', - 'password' => 'newpass', // newpass - 'password_token' => '', - 'email' => 'oidtest2@testuser.com', - 'email_verified' => 0, - 'email_token' => 'testtoken2', - 'email_token_expires' => '2008-03-28 02:45:46', - 'tos' => 1, - 'active' => 1, - 'last_action' => '2008-03-25 02:45:46', - 'last_login' => '2008-03-25 02:45:46', - 'is_admin' => 0, - 'role' => 'user', - 'created' => '2008-03-25 02:45:46', - 'modified' => '2008-03-25 02:45:46' + 'role' => 'Lorem ipsum dolor sit amet', + 'created' => '2017-05-04 17:25:43', + 'modified' => '2017-05-04 17:25:43', + 'deleted_date' => '2017-05-04 17:25:43', + 'deleted' => 1 ), - array( - 'id' => '515e36a2-5fjj-46b9-8247-584367265f11', - 'username' => 'resetuser', - 'slug' => 'resetuser', - 'password' => 'newpass', // newpass - 'password_token' => 'testtoken', - 'email' => 'resetuser@testuser.com', - 'email_verified' => 1, - 'email_token' => 'testtoken', - 'email_token_expires' => '2008-03-28 02:45:46', - 'tos' => 1, - 'active' => 1, - 'last_action' => '2008-03-25 02:45:46', - 'last_login' => '2008-03-25 02:45:46', - 'is_admin' => 0, - 'role' => 'user', - 'created' => '2008-03-25 02:45:46', - 'modified' => '2008-03-25 02:45:46' - ) ); -/** - * Constructor - * - */ - public function __construct() { - parent::__construct(); - $this->User = ClassRegistry::init('Users.User'); - foreach ($this->records as &$record) { - $record['password'] = $this->User->hash($record['password'], null, true); - } - } - } diff --git a/View/Elements/Users/register.ctp b/View/Elements/Users/register.ctp new file mode 100644 index 000000000..79c3d0ce9 --- /dev/null +++ b/View/Elements/Users/register.ctp @@ -0,0 +1,68 @@ + + +
+
+
+ Html->link("Crear Nueva Cuenta", + array('plugin'=>'users','controller'=>'users', 'action'=>'wishlist'), + array('class'=>'btn btn-success btn-lg signup-modal-trigger')); + ?> + + +
+ +
+
+

+
+ Form->create($model, array('url'=>array('plugin'=>'users','controller'=>'users', 'action'=>'register'))); + echo $this->Form->input('username', array( + 'label' => __d('users', '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'), + 'type' => 'password')); + echo $this->Form->input('temppassword', array( + 'label' => __d('users', 'Password (confirm)'), + 'type' => 'password')); + echo $this->form->hidden('g-recaptcha-response', array('id' => 'g-recaptcha-response')); + $tosLink = $this->Html->link(__d('users', 'Terms of Service'), array('controller' => 'pages', 'action' => 'tos', 'plugin' => null)); + echo $this->Form->input('tos', array( + 'label' => __d('users', 'I have read and agreed to ') . $tosLink)); + + echo $this->Form->submit(__d('paxapos', 'Crear cuenta PaxaPos'), array('class'=>'btn btn-primary btn-block')); + echo $this->Form->end(); + ?> +
+ This site is protected by reCAPTCHA and the Google + Privacy Policy and + Terms of Service apply. + +
+
+
+ + + append('script'); + ?> + + + Html->script('Risto.simple_captcha'); + echo $this->end(); + ?> \ No newline at end of file diff --git a/View/Elements/Users/sidebar.ctp b/View/Elements/Users/sidebar.ctp index 68bc08a98..63296b420 100644 --- a/View/Elements/Users/sidebar.ctp +++ b/View/Elements/Users/sidebar.ctp @@ -10,7 +10,7 @@
  • Html->link(__d('users', 'My Account'), array('plugin' => 'users', 'controller' => 'users', 'action' => 'edit')); ?>
  • Html->link(__d('users', 'Change password'), array('plugin' => 'users', 'controller' => 'users', 'action' => 'change_password')); ?> - Session->read('Auth.User.is_admin')) : ?> +
  •  
  • Html->link(__d('users', 'List Users'), array('plugin' => 'users', 'controller' => 'users', 'action' => 'index'));?>
  • diff --git a/View/Elements/Users/whishlist.ctp b/View/Elements/Users/whishlist.ctp new file mode 100644 index 000000000..b27c07ad3 --- /dev/null +++ b/View/Elements/Users/whishlist.ctp @@ -0,0 +1,26 @@ +

    Wishlist

    + +

    Estimado usuario,
    +Gracias por tu interés en nuestro software. Actualmente nos encontramos en pleno crecimiento y, aunque no podemos ofrecerte acceso +inmediato, registraremos tu solicitud en nuestra lista de usuarios interesados. A medida que expandimos nuestro servicio para +atender a más clientes, te contactaremos en el futuro para brindarte la oportunidad de utilizar PaxaPos en tu comercio. +Apreciamos tu paciencia y esperamos poder satisfacer tus necesidades en un futuro cercano. +

    + + +Form->create("Wishlist", ['url' => ['plugin'=>'users', 'controller' => 'users', 'action'=>'wishlist']]);?> +Form->input('name', array('label' => 'Nombre y Apellido', 'required' => true));?> +Form->input('email', array('type'=>'email', 'label' => 'Email', 'required' => true));?> +Form->input('business', array('label' => 'Nombre del negocio', 'required' => true));?> +Form->input('phone', array('label' => 'Teléfono (opcional)'));?> +Form->input('razon_social', array('label' => 'Razón Social (opcional)'));?> +Form->input('cuit', array('label' => 'CUIT (opcional)'));?> +Form->input('address', array('label' => 'Dirección (opcional)'));?> +Form->input('zip', array('label' => 'Código postal (opcional)'));?> +Form->input('city', array('label' => 'Ciudad (opcional)'));?> +Form->input('country', array('label' => 'País (opcional)'));?> +Form->input('website', array('label' => 'Sitio web (opcional)'));?> +Form->input('comments', array('type'=>'textarea','label' => 'Comentarios (opcional)'));?> +Form->submit('Enviar', array('class'=>'btn btn-primary btn-block'));?> +Form->end();?> + diff --git a/View/Elements/box_oauth_login.ctp b/View/Elements/box_oauth_login.ctp new file mode 100644 index 000000000..a6fe6eb1c --- /dev/null +++ b/View/Elements/box_oauth_login.ctp @@ -0,0 +1,40 @@ +start("css"); +echo $this->Html->css('Risto.ristorantino/boxlogin_oauth'); +$this->end(); +?> + + + + +
    + + + +
    + +start("script"); +echo $this->Html->script('Users.box_oauth_login'); +$this->end(); +?> \ No newline at end of file diff --git a/View/Elements/boxlogin.ctp b/View/Elements/boxlogin.ctp new file mode 100644 index 000000000..57854bd0d --- /dev/null +++ b/View/Elements/boxlogin.ctp @@ -0,0 +1,37 @@ + +Html->css('Risto.ristorantino/boxlogin'); ?> + + + +
    + + + Form->create('User', array('type'=>'post','url'=> array( 'full_base' => true,'plugin'=>'users','controller'=>'users','action'=>'login'), 'role'=>'form')); + + echo $this->Form->input('email',array('placeholder'=>'Email', 'label'=>false)); + echo $this->Form->input('password', array('type'=>'password','placeholder'=>'Contraseña', 'label'=>false)); + + echo $this->Form->input('remember_me', array('type' => 'checkbox', 'label' => 'Recordarme')); + + echo $this->Html->link('Olvidé la contraseña', + array('plugin'=>'users', 'controller'=>'users', 'action'=>'reset_password'), + array( + 'style'=>'margin-bottom: 5px; display: block;', + 'class'=>'small') + ); + + + + + echo $this->Form->button('Ingresar +', array('type'=>'submit', 'class'=>'btn btn-lg btn-primary btn-block btn-ico', "escape"=>false)); + + echo $this->Form->end(); + +?> + +
    + diff --git a/View/Elements/listado_usuarios.ctp b/View/Elements/listado_usuarios.ctp new file mode 100644 index 000000000..a2ff4b21f --- /dev/null +++ b/View/Elements/listado_usuarios.ctp @@ -0,0 +1,166 @@ + + + +
    + element('Users.paging'); ?> +
    + + + + + + + + + + + + + + + + > + + + + + + + + + + + + + + + + + + + + + + +
    Paginator->sort('username','Nombre de usuario'); ?>Paginator->sort('email','E-Mail'); ?>SitiosRolesPaginator->sort('active','Activo'); ?>Paginator->sort('created','en PaxaPos desde'); ?>Paginator->sort('last_login','Ultima vez conectado'); ?>
    + + + + + + Html->link( $site['name'], array('tenant' => $site['alias'], 'plugin'=>'risto', 'controller' => 'pages', 'action' => 'display','dashboard') ). + $this->Html->link("", + array('plugin' => 'mt_sites', 'controller' => 'SiteUsers', 'action' => 'desvincular_del_site', $user['User']['id'], $site['alias']), array('escape' => false, 'class' => 'btn btn-sm'), sprintf(__('¿Seguro que quieres desvincular a '.$user['User']['username'].' del sitio '.$site['name'].'?'))) + ."
    "; + } + echo trim( $sites, "," ); + } + ?> +
    + + + + + Time->niceShort( $user[$modelName]['created'] ); ?> + + Time->niceShort( $user[$modelName]['last_login']) + : __d('users','Nunca'); + ?> + + +
    + + + Html->link(__('Editar'), array('plugin'=>'users', 'action'=>'edit', $user[$modelName]['id']), array('class'=>'btn btn-default btn-sm btn-edit')); ?> + + + + + +
    + + + Html->link(__('Editar'), + array('plugin'=>'mt_sites','controller'=>'site_users', 'action'=>'edit', $user[$modelName]['id']), + array('class' => 'btn btn-sm btn-primary btn-edit') + ); + ?> + + Form->postLink(__('Desvincular del Comercio'), + array('plugin'=>'mt_sites','controller'=>'site_users', 'action'=>'delete_from_tenant', $user[$modelName]['id']), + array('class' => 'btn btn-sm btn-success') + ); + ?> +
    + +
    + + +
    + element('Risto.pagination'); ?> \ No newline at end of file diff --git a/View/Elements/paging.ctp b/View/Elements/paging.ctp index 477e734dc..e508d4043 100644 --- a/View/Elements/paging.ctp +++ b/View/Elements/paging.ctp @@ -1,4 +1,4 @@ Paginator->counter(array( - 'format' => 'Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%')); + 'format' => 'Página %page% de %pages%, mostrando %current% registros de un total de %count%, empezando en el registro %start% y finalizando en el registro %end%.')); ?> \ No newline at end of file diff --git a/View/Elements/pin_login.ctp b/View/Elements/pin_login.ctp new file mode 100644 index 000000000..90cb061d1 --- /dev/null +++ b/View/Elements/pin_login.ctp @@ -0,0 +1,37 @@ + +

    PIN

    +Form->create('GenericUser', array( 'id'=>'pinForm'));?> + + Form->password('k1', array( + 'class' => 'form-control input-lg pin', + 'id' => 'pin1', + 'maxlength' => 1 + ))?> + Form->password('k2', array( + 'class' => 'form-control input-lg pin', + 'id' => 'pin2', + 'maxlength' => 1 + ))?> + Form->password('k3', array( + 'class' => 'form-control input-lg pin', + 'id' => 'pin3', + 'maxlength' => 1 + ))?> + Form->password('k4', array( + 'class' => 'form-control input-lg pin input-block', + 'id' => 'pin4', + 'maxlength' => 1 + ))?> + +Form->end();?> + +request->is('mobile')) { ?> +
    + append('css') ?> + + end() ?> + + Html->script("Users.pin_keyboard"); ?> + + +Html->script("Users.pin_login"); ?> \ No newline at end of file diff --git a/View/GenericUsers/form.ctp b/View/GenericUsers/form.ctp new file mode 100644 index 000000000..584a12bdd --- /dev/null +++ b/View/GenericUsers/form.ctp @@ -0,0 +1,15 @@ + +Form->create('GenericUser'); ?> + +Form->input('id'); ?> +Form->input('username'); ?> +Form->input('rol_id'); ?> +Form->input('pin', array( + 'class'=>'form-control input-lg', + 'maxlength' => 4, + 'minlength' => 4, + ) + ); ?> + +Form->submit('Guardar', array('class' => 'btn btn-success')); ?> +Form->end(); ?> \ No newline at end of file diff --git a/View/GenericUsers/index.ctp b/View/GenericUsers/index.ctp new file mode 100644 index 000000000..7774eb736 --- /dev/null +++ b/View/GenericUsers/index.ctp @@ -0,0 +1,53 @@ +element("Risto.layout_modal_edit", array('title'=>'Usuario'));?> + + +
    +
    +
    +

    Usuarios

    +
    +
    + Html->link('Crear Usuario', array('plugin' => 'users', 'controller' => 'generic_users', 'action' => 'add'), array('class' => 'btn btn-primary btn-lg btn-add pull-right')) ?> +
    +
    +
    +
    + + + + + + + + + + + +
    + + + + + + +
    + + Html->link( + 'Habilitar Ingreso', array('action' => 'add'), array('class'=>'btn-add btn btn-success') + );?> + + Html->link( + 'Modificar PIN', array('action' => 'edit', $user['GenericUser']['id']), array('class' => 'btn-edit btn btn-default') + ); + } + echo $this->Html->link( + __('Eliminar Usuario'), array('plugin' => 'users', 'controller' => 'generic_users', 'action' => 'delete', $user['GenericUser']['id'] ), + array('class' => 'btn btn-danger'), sprintf(__("¿Esta seguro que desea borrar al usuario generico %s ?", $user['Rol']['name'])) + ); + ?> +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/View/Roles/edit.ctp b/View/Roles/edit.ctp new file mode 100644 index 000000000..15fdb39ea --- /dev/null +++ b/View/Roles/edit.ctp @@ -0,0 +1,16 @@ +
    +Form->create('Rol');?> +
    + request->data['Rol']['id'])) { ?> + + + + + Form->input('id'); + echo $this->Form->input('name', array('label' => 'Nombre')); + echo $this->Form->input('machin_name', array('label' => 'Rol', 'type' => 'select', 'options' => $roles_machine_names)); + ?> +
    +Form->end(array('label' => 'Guardar', 'class' => 'btn btn-primary btn-lg btn-block'));?> +
    \ No newline at end of file diff --git a/View/Roles/edit_for_user.ctp b/View/Roles/edit_for_user.ctp new file mode 100644 index 000000000..453d7fcf4 --- /dev/null +++ b/View/Roles/edit_for_user.ctp @@ -0,0 +1,9 @@ +Form->create('User'); +echo $this->Form->input('id'); +echo $this->Form->input("Rol", array("type"=>'radio')); + +echo $this->Form->submit("Actualizar", array('class' => 'btn btn-primary')); +echo $this->Form->end(); \ No newline at end of file diff --git a/View/Roles/index.ctp b/View/Roles/index.ctp new file mode 100644 index 000000000..814bceac6 --- /dev/null +++ b/View/Roles/index.ctp @@ -0,0 +1,50 @@ +
    +

    + + + + + + + + + + + + + + + + + + + +
    Paginator->sort('id');?>Paginator->sort('name');?>Paginator->sort('machin_name');?>Paginator->sort('created');?>Paginator->sort('modified');?>
          + Html->link(__('View'), array('action' => 'view', $rol['Rol']['id'])); ?> + Html->link(__('Edit'), array('action' => 'edit', $rol['Rol']['id'])); ?> + Form->postLink(__('Delete'), array('action' => 'delete', $rol['Rol']['id']), array(), __('Are you sure you want to delete # %s?', $rol['Rol']['id'])); ?> +
    +

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

    + +
    + Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled')); + echo $this->Paginator->numbers(array('separator' => '')); + echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled')); + ?> +
    +
    +
    +

    + +
    diff --git a/View/Roles/view.ctp b/View/Roles/view.ctp new file mode 100644 index 000000000..a1d2c93f2 --- /dev/null +++ b/View/Roles/view.ctp @@ -0,0 +1,92 @@ +
    +

    +
    +
    +
    + +   +
    +
    +
    + +   +
    +
    +
    + +   +
    +
    +
    + +   +
    +
    +
    + +   +
    +
    +
    +
    +

    + +
    + diff --git a/View/SuperRoles/edit_for_user.ctp b/View/SuperRoles/edit_for_user.ctp new file mode 100644 index 000000000..883201244 --- /dev/null +++ b/View/SuperRoles/edit_for_user.ctp @@ -0,0 +1,9 @@ +Form->create('User'); +echo $this->Form->input('id'); +echo $this->Form->input("SuperRol", array("multiple"=>'checkbox')); + +echo $this->Form->submit("Actualizar", array('class' => 'btn btn-primary')); +echo $this->Form->end(); \ No newline at end of file diff --git a/View/Users/add.ctp b/View/Users/add.ctp deleted file mode 100644 index c736d7d5c..000000000 --- a/View/Users/add.ctp +++ /dev/null @@ -1,36 +0,0 @@ - -
    -

    -
    - Form->create($model); - echo $this->Form->input('username', array( - 'label' => __d('users', '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'), - 'type' => 'password')); - echo $this->Form->input('temppassword', array( - 'label' => __d('users', 'Password (confirm)'), - 'type' => 'password')); - $tosLink = $this->Html->link(__d('users', 'Terms of Service'), array('controller' => 'pages', 'action' => 'tos', 'plugin' => null)); - echo $this->Form->input('tos', array( - 'label' => __d('users', 'I have read and agreed to ') . $tosLink)); - echo $this->Form->end(__d('users', 'Submit')); - ?> -
    -
    -element('Users.Users/sidebar'); ?> diff --git a/View/Users/admin_add.ctp b/View/Users/admin_add.ctp deleted file mode 100644 index 8b0efff4e..000000000 --- a/View/Users/admin_add.ctp +++ /dev/null @@ -1,41 +0,0 @@ - -
    - Form->create($model); ?> -
    - - Form->input('username', array( - 'label' => __d('users', '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'), - 'type' => 'password')); - echo $this->Form->input('temppassword', array( - 'label' => __d('users', 'Password (confirm)'), - 'type' => 'password')); - if (!empty($roles)) { - echo $this->Form->input('role', array( - 'label' => __d('users', 'Role'), 'values' => $roles)); - } - echo $this->Form->input('is_admin', array( - 'label' => __d('users', 'Is Admin'))); - echo $this->Form->input('active', array( - 'label' => __d('users', 'Active'))); - ?> -
    - Form->end('Submit'); ?> -
    -element('Users.Users/admin_sidebar'); ?> \ No newline at end of file diff --git a/View/Users/admin_edit.ctp b/View/Users/admin_edit.ctp deleted file mode 100644 index 02cd058ca..000000000 --- a/View/Users/admin_edit.ctp +++ /dev/null @@ -1,34 +0,0 @@ - -
    - Form->create($model); ?> -
    - - Form->input('id'); - echo $this->Form->input('username', array( - 'label' => __d('users', 'Username'))); - echo $this->Form->input('email', array( - 'label' => __d('users', 'Email'))); - if (!empty($roles)) { - echo $this->Form->input('role', array( - 'label' => __d('users', 'Role'), 'values' => $roles)); - } - echo $this->Form->input('is_admin', array( - 'label' => __d('users', 'Is Admin'))); - echo $this->Form->input('active', array( - 'label' => __d('users', 'Active'))); - ?> -
    - Form->end('Submit'); ?> -
    -element('Users.Users/admin_sidebar'); ?> \ No newline at end of file diff --git a/View/Users/admin_form.ctp b/View/Users/admin_form.ctp new file mode 100644 index 000000000..8f5247f46 --- /dev/null +++ b/View/Users/admin_form.ctp @@ -0,0 +1,59 @@ + +
    + Form->create($model, array('type'=>'post')); ?> +
    + + request->data[$model]['id']) ): ?> + + + + + + Form->input('id'); + echo $this->Form->input('username', array( + 'label' => __d('users', 'Username'))); + echo $this->Form->input('email', array( + 'label' => __d('users', 'Email'))); + + + if (!empty($sites)) { + echo $this->Form->input('Site', array( + 'label' => __d('users', 'Site') + )); + } + + echo $this->Form->input('password', array( + 'label' => __d('users', 'Contraseña'), + 'required' => false + )); + + echo $this->Form->input('active', array( + 'label' => __d('users', 'Active'))); + + echo $this->Form->input('email_verified', array( + 'label' => __d('users', 'Email Verified'))); + + + if ( empty($this->request->data['$model']['tos']) ) { + $tosLink = $this->Html->link(__d('users', 'Terms of Service') + , array('tenant'=>false,'controller' => 'pages', 'action' => 'tos', 'plugin' => null)); + echo $this->Form->input('tos', array( + 'label' => __d('users', 'I have read and agreed to ') . $tosLink)); + } + ?> +
    + Form->button('Actualizar', array('class'=>'btn btn-primary')); ?> + Html->link(__('Cancelar'), array('action'=>'index'), array('class'=>'btn btn-default') ); ?> + Form->end(); ?> +
    diff --git a/View/Users/admin_index.ctp b/View/Users/admin_index.ctp deleted file mode 100644 index b89b567c2..000000000 --- a/View/Users/admin_index.ctp +++ /dev/null @@ -1,70 +0,0 @@ - -
    -

    - - ' . __d('users', 'Filter') . ''; - 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('Users.paging'); ?> - element('Users.pagination'); ?> - - - - - - - - - - - > - - - - - - - - -
    Paginator->sort('username'); ?>Paginator->sort('email'); ?>Paginator->sort('email_verified'); ?>Paginator->sort('active'); ?>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'])); ?> -
    - element('Users.pagination'); ?> -
    -element('Users.Users/admin_sidebar'); ?> diff --git a/View/Users/change_password.ctp b/View/Users/change_password.ctp index 3817a0532..f0979a82b 100644 --- a/View/Users/change_password.ctp +++ b/View/Users/change_password.ctp @@ -9,11 +9,12 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ ?> -
    -

    -

    +
    +
    +

    +

    Form->create($model, array('action' => 'change_password')); + echo $this->Form->create($model, array( 'url' => array('action' => 'change_password') )); echo $this->Form->input('old_password', array( 'label' => __d('users', 'Old Password'), 'type' => 'password')); @@ -23,7 +24,8 @@ echo $this->Form->input('confirm_password', array( 'label' => __d('users', 'Confirm'), 'type' => 'password')); - echo $this->Form->end(__d('users', 'Submit')); + echo $this->Form->submit(__d('users', 'Submit'), array('class'=>'btn btn-block btn-primary')); + echo $this->Form->end(); ?>
    -element('Users.Users/sidebar'); ?> \ No newline at end of file +
    \ No newline at end of file diff --git a/View/Users/dashboard.ctp b/View/Users/dashboard.ctp index 41cccf50b..d4e308d94 100644 --- a/View/Users/dashboard.ctp +++ b/View/Users/dashboard.ctp @@ -12,4 +12,16 @@

    -
    \ No newline at end of file +
    + + + + + + + \ No newline at end of file diff --git a/View/Users/edit.ctp b/View/Users/edit.ctp deleted file mode 100644 index cc929de0b..000000000 --- a/View/Users/edit.ctp +++ /dev/null @@ -1,22 +0,0 @@ - -
    - Form->create($model); ?> -
    - -

    - Html->link(__d('users', 'Change your password'), array('action' => 'change_password')); ?> -

    -
    - Form->end(__d('users', 'Submit')); ?> -
    -element('Users.Users/sidebar'); ?> \ No newline at end of file diff --git a/View/Users/get_token.ctp b/View/Users/get_token.ctp new file mode 100644 index 000000000..770d8448b --- /dev/null +++ b/View/Users/get_token.ctp @@ -0,0 +1,3 @@ +

    Access Token

    +

    Use this token to access the API.

    +
    diff --git a/View/Users/index.ctp b/View/Users/index.ctp index 82116ca27..7ba8ef60d 100644 --- a/View/Users/index.ctp +++ b/View/Users/index.ctp @@ -8,39 +8,49 @@ * @copyright Copyright 2010 - 2014, Cake Development Corporation (http://cakedc.com) * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +$this->element("Risto.layout_modal_edit"); ?> -
    -

    - -

    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($user[$model]['username'], array('action' => 'view', $user[$model]['id'])); ?> - Html->link(__d('users', 'View'), array('action' => 'view', $user[$model]['id'])); ?> -
    - element('Users.pagination'); ?> +
    + Form->create('User'); + ?> +
    + Form->input('txt_search', array('label' => false, 'placeholder' => 'Escribe aquí datos del usuario buscado para realizar una busqueda.'));?> +
    +
    + Form->submit('Buscar', array('class' => 'btn btn-block btn-primary'));?> +
    + +
    + + action == 'index_deleted') { + echo $this->Html->link('Ver Listado de Usuarios', array('action'=>'index'), array('class'=>'btn btn-default btn-block')); + } else { + echo $this->Html->link('Ver Usuarios Borrados', array('action'=>'index_deleted'), array('class'=>'btn btn-default btn-block')); + } + ?> +
    + Form->end();?> +
    + + + + element('Users.listado_usuarios', array('adminPanel' => true)); ?> +
    -element('Users.Users/sidebar'); ?> diff --git a/View/Users/index_for_tenant.ctp b/View/Users/index_for_tenant.ctp new file mode 100644 index 000000000..b251c81ba --- /dev/null +++ b/View/Users/index_for_tenant.ctp @@ -0,0 +1,26 @@ +element("Risto.layout_modal_edit", array('title' => 'Vinculación de Usuario con tu Comercio')); + + +?> +
    +
    + Html->link(__('Crear nuevo %s', __('Usuario')), array('plugin'=>'mt_sites', 'controller'=> 'site_users', 'action'=>'add'), array('class'=>'btn btn-success btn-lg btn-add')); ?> +
    + +

    +
    + + +element('Users.listado_usuarios'); ?> + +
    diff --git a/View/Users/login.ctp b/View/Users/login.ctp index f6fde0dcc..13f8c9b6b 100644 --- a/View/Users/login.ctp +++ b/View/Users/login.ctp @@ -9,25 +9,54 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ ?> -
    -

    - Session->flash('auth');?> -
    + + +
    + +
    + +

    o con cuenta PaxaPos

    + element('Users.boxlogin'); ?> + +
    + element("Users.Users/register");?> +
    +
    -element('Users.Users/sidebar'); ?> +append('script'); +?> + + +Html->script('Risto.simple_captcha'); + + + +?> + +end(); +?> \ No newline at end of file diff --git a/View/Users/my_edit.ctp b/View/Users/my_edit.ctp new file mode 100644 index 000000000..ddd5f8103 --- /dev/null +++ b/View/Users/my_edit.ctp @@ -0,0 +1,78 @@ + +
    + Form->create($model); ?> + Form->input('id') ?> +
    + +

    + Html->link(__d('users', 'Change your password'), array('action' => 'change_password')); ?> +

    +

    + Form->input('username') ?> +

    +

    + Form->input('email') ?> +

    +
    + Form->end(array('class' => 'btn btn-primary', 'label' => 'Guardar')); ?> + + + + +

    Redes Sociales Vinculadas

    + + + request->is('mobile')) { ?> +

    Vincular cuentas Sociales

    +
    + element('Users.box_oauth_login');?> +
    + +
    + + + append("script");?> + + end()?> + + + + append("script");?> + + end()?> + \ No newline at end of file diff --git a/View/Users/register.ctp b/View/Users/register.ctp new file mode 100644 index 000000000..be4c459c9 --- /dev/null +++ b/View/Users/register.ctp @@ -0,0 +1 @@ +element("Users.Users/register");?> \ No newline at end of file diff --git a/View/Users/tenant_login.ctp b/View/Users/tenant_login.ctp new file mode 100644 index 000000000..afd3acd7c --- /dev/null +++ b/View/Users/tenant_login.ctp @@ -0,0 +1,45 @@ + +

    +
    +
    + + + + + + + +
    +
    + + + diff --git a/View/Users/wishlist.ctp b/View/Users/wishlist.ctp new file mode 100644 index 000000000..b2c748846 --- /dev/null +++ b/View/Users/wishlist.ctp @@ -0,0 +1,29 @@ +
    + +

    Wishlist

    + +

    Estimado usuario,
    + Gracias por tu interés en nuestro software. Actualmente nos encontramos en pleno crecimiento y, aunque no podemos ofrecerte acceso + inmediato, registraremos tu solicitud en nuestra lista de usuarios interesados. A medida que expandimos nuestro servicio para + atender a más clientes, te contactaremos en el futuro para brindarte la oportunidad de utilizar PaxaPos en tu comercio. + Apreciamos tu paciencia y esperamos poder satisfacer tus necesidades en un futuro cercano. +

    + + + Form->create("Wishlist", ['url' => ['plugin'=>'users', 'controller' => 'users', 'action'=>'wishlist']]);?> + Form->input('name', array('label' => 'Nombre y Apellido', 'required' => true));?> + Form->input('email', array('type'=>'email', 'label' => 'Email', 'required' => true));?> + Form->input('business', array('label' => 'Nombre del negocio', 'required' => true));?> + Form->input('phone', array('label' => 'Teléfono (opcional)'));?> + Form->input('razon_social', array('label' => 'Razón Social (opcional)'));?> + Form->input('cuit', array('label' => 'CUIT (opcional)'));?> + Form->input('address', array('label' => 'Dirección (opcional)'));?> + Form->input('zip', array('label' => 'Código postal (opcional)'));?> + Form->input('city', array('label' => 'Ciudad (opcional)'));?> + Form->input('country', array('label' => 'País (opcional)'));?> + Form->input('website', array('label' => 'Sitio web (opcional)'));?> + Form->input('comments', array('type'=>'textarea','label' => 'Comentarios (opcional)'));?> + Form->submit('Enviar', array('class'=>'btn btn-primary btn-block'));?> + Form->end();?> + +
    \ No newline at end of file diff --git a/composer.json b/composer.json index 994be689f..3e78ac5d1 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "cakedc/users", + "name": "ristorantino/users", "description": "Users Plugin for CakePHP", "type": "cakephp-plugin", "keywords": ["cakephp","users","auth"], diff --git a/webroot/js/box_oauth_login.js b/webroot/js/box_oauth_login.js new file mode 100644 index 000000000..d2478af14 --- /dev/null +++ b/webroot/js/box_oauth_login.js @@ -0,0 +1,62 @@ +window.fbAsyncInit = function() { + FB.init({ + appId : Risto.APPID, + xfbml : true, + version : 'v2.10' + }); + //FB.AppEvents.logPageView(); + + urlVerificarUsuario = Risto.URLVERIFICARUSUARIO; + + function sendAjax(url, data, fnDone){ + $.ajax(urlVerificarUsuario, { + type:"POST", + data: data + }) + .done(fnDone) + .error(function(rta){ + alert("Ha ocurrido un error, porfavor, intentalo de nuevo o contacta con soporte@paxapos.com"); + }); + } + + function registrarUsuario() { + FB.api('/me?fields=first_name, last_name, picture, email, gender, link', function(response) { + + sendAjax(urlVerificarUsuario, response, alDone); + + function alDone(rta){ + location.href = "/"; + } + }); + } + + function cuandoSeLoguea(response) { + if (response.status === 'connected') { + sendAjax(urlVerificarUsuario, response, alDone); + } else { + alert("error al loguearse: no has iniciado sesión en Facebook"); + } + + function alDone(rta){ + if (rta && rta.hasOwnProperty("user") && rta.user ) { + location.href = "/"; + } else { + registrarUsuario(); + } + } + } + + + $('.fb-login').on('click', function(){ + FB.login(cuandoSeLoguea,{scope: ['public_profile', 'email']}); + }); + + }; // fin fbAsyncInit + + (function(d, s, id){ + var js, fjs = d.getElementsByTagName(s)[0]; + if (d.getElementById(id)) {return;} + js = d.createElement(s); js.id = id; + js.src = "//connect.facebook.net/es_LA/sdk.js"; + fjs.parentNode.insertBefore(js, fjs); + }(document, 'script', 'facebook-jssdk')); \ No newline at end of file diff --git a/webroot/js/pin_keyboard.js b/webroot/js/pin_keyboard.js new file mode 100644 index 000000000..a84091be3 --- /dev/null +++ b/webroot/js/pin_keyboard.js @@ -0,0 +1,39 @@ +let Keyboard = window.SimpleKeyboard.default; + +let myKeyboard = new Keyboard({ + onChange: input => onChange(input), + 'layout': { + 'default': [ + '1 2 3 4', + '5 6 7 8', + '9 0 {bksp}', + //'0 {bksp}' + ], + /*'default': [ + '` 1 2 3 4 5 6 7 8 9 0 - = {bksp}', + '{tab} q w e r t y u i o p [ ] \\', + '{lock} a s d f g h j k l ; \' {enter}', + '{shift} z x c v b n m , . / {shift}', + '.com @ {space}' + ],*/ + }, + 'maxlength': { + 'pin': 1, + } +}); + +function onChange(input) { + var cantInputsPin = 4; + for(var key = 1; cantInputsPin >= key; key++) { + if($("#pin"+key).val().length === 0) { + //si el length del value del pin es 0, le agregamos el input que clickeamos en el keyboard on-screen. + $("#pin"+key).val(input); + if(key === 4) { + //si estamos en el pin 4, enviamos el formulario despues de ingresar el ultimo número. + $("#pinForm").submit(); + } + break; + } + } + myKeyboard.clearInput(); +} \ No newline at end of file diff --git a/webroot/js/pin_login.js b/webroot/js/pin_login.js new file mode 100644 index 000000000..d73114afc --- /dev/null +++ b/webroot/js/pin_login.js @@ -0,0 +1,34 @@ +var $p1 = $("#pin1"); +var $p2 = $("#pin2"); +var $p3 = $("#pin3"); +var $p4 = $("#pin4"); +var $form = $("#pinForm"); + +function apretarYseguir( $current ) { + $current.on('keyup', function(e) { + if (e.keyCode==8) { + // back space + this.value=""; + var $prev = $current.prev("input"); + if ( $prev.length ) { + $prev.focus(); + } + } else { + var $next = $current.next("input"); + if ( $next.length ) { + apretarYseguir($next) + } else { + $form.submit(); + } + } + } ).focus(); +} + +apretarYseguir($p1); + +function ponerPin() { + $(".pin").val(""); + $p1.focus(); +}; +ponerPin(); +$(".pin").on('click', ponerPin );