Exemplo n.º 1
0
 public function myProfileAction()
 {
     $usersNs = new Zend_Session_Namespace("members");
     $model = new Application_Model_User();
     $user = $model->find($usersNs->userId);
     if (false === $user) {
         $this->_flashMessenger->addMessage(array('error' => 'Invalid request!'));
         $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/employee/dashboard'));
     }
     $form = new Application_Form_User();
     $elements = $form->getElements();
     foreach ($elements as $element) {
         if ($element->getId() != "profilePicture" && $element->getId() != "submit") {
             $form->removeElement($element->getId());
         }
     }
     $this->view->form = $form;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $options = $request->getPost();
         if ($form->isValid($options)) {
             $user->uploadProfilePicture($usersNs->userId, $options);
             $this->_flashMessenger->addMessage(array('success' => 'Profile picture has been uploaded successfully!'));
             $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/employee/my-profile'));
         } else {
             $this->_flashMessenger->addMessage(array('error' => 'Unable to upload the profile picture!'));
             $form->reset();
         }
     }
     $this->view->user = $user;
 }
Exemplo n.º 2
0
 public function indexAction()
 {
     $userForm = new Application_Form_User();
     if ($this->getRequest()->isPost()) {
         if ($userForm->isValid($_POST)) {
             $user = new Application_Model_User();
             $this->userRepository->populate($user, $userForm->getValues());
             $this->userRepository->create($user);
             $this->userRepository->flush();
             $userForm->reset();
         }
     }
     $this->view->users = $this->userRepository->findAll();
     $this->view->userForm = $userForm;
 }
Exemplo n.º 3
0
 /**
  * Método utilizado para editar Users, testando a existência de uma requisão do tipo POST.
  * Seus valores são resgatados validados e atualizados no banco de dados.
  * @param int $id
  * @method updateAction
  * @access public
  * @return resource
  */
 public function updateAction()
 {
     $form = new Application_Form_User();
     $form->setAction('/user/update');
     $users = new Application_Model_User();
     if ($this->_request->isPost()) {
         if ($form->isValid($this->_request->getPost())) {
             $values = $form->getValues();
             $users->update($values, 'id = ' . $values['id']);
             $this->_redirect('/user/retrieve');
         }
     } else {
         $id = $this->_getParam('id');
         $user = $users->fetchRow("id ={$id}")->toArray();
         $form->populate($user);
     }
     $this->view->form = $form;
 }
Exemplo n.º 4
0
 public function init()
 {
     parent::init();
     $this->addAttribs(array('class' => 'seotoaster-signup', 'id' => 'seotoaster-signup-form'));
     $this->removeElement('roleId');
     $saveButton = $this->getElement('saveUser');
     $this->removeElement('saveUser');
     $this->removeElement('gplusProfile');
     $this->addElement(new Zend_Form_Element_Captcha('verification', array('label' => "Please verify you're a human", 'captcha' => array('captcha' => 'Image', 'font' => 'system/fonts/Alcohole.ttf', 'imgDir' => 'tmp', 'imgUrl' => 'tmp', 'dotNoiseLevel' => 0, 'lineNoiseLevel' => 0, 'wordLen' => 5, 'timeout' => 300))));
     $this->getElement('email')->addValidator(new Zend_Validate_Db_NoRecordExists(array('table' => 'user', 'field' => 'email')));
     $this->addElement($saveButton->setLabel('Sign Up'));
     $this->_initDecorators();
 }
Exemplo n.º 5
0
 public function addAction()
 {
     $form = new Application_Form_User();
     $form->envoyer->setLabel('Ajouter');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $users = new Application_Model_DbTable_Users();
             /* 
              * Test supplémentaire
              */
             $erreur = false;
             /* Vérification que le username n'existe pas */
             $where = "username = '******'username') . "'";
             $sel = $users->fetchAll($where);
             if ($sel->count() > 1) {
                 /* Erreur le login existe déjà */
                 $this->_flashMessage('Login existe déjà');
                 $erreur = TRUE;
             }
             /* Vérification de la zone role */
             $role = $form->getValue('role');
             if ($role == '') {
                 $role == 'user';
             } else {
                 if (strpos('admistrator,user', $role) === FALSE) {
                     $this->_flashMessage('pb role');
                     $erreur = TRUE;
                 }
             }
             if ($erreur) {
                 $form->populate($formData);
             } else {
                 $newUser = $users->fetchNew();
                 $newUser->username = $form->getValue('username');
                 $newUser->password = $form->getValue('password');
                 $newUser->role = $form->getValue('role');
                 $newUser->token = $form->getValue('token');
                 $newUser->date_created = new Zend_Db_Expr('NOW()');
                 Zend_Debug::dump($newUser);
                 $id = $newUser->save();
                 $this->_helper->redirector('index');
             }
         } else {
             $form->populate($formData);
         }
     }
 }
    /**
     * Exibe o form para edição de usuário.
     *
     * Exibe o form para editar o usuário a partir do ID passado pela URL
     * Se o usuário não existir é exibo uma mensagem de erro e não apresentamos
     * o form.
     *
     * @return void|false
     */
    public function editAction()
    {
        $id      = (int) $this->_getParam('id');
        $result  = $this->_model->find($id);
        $data    = $result->current();

        if ( null === $data )
        {
            $this->view->message = "Usuário não encontrado!";
            return false;
        }

        $form = new Application_Form_User();
        $form->setAsEditForm($data);

        if ( $this->_request->isPost() )
        {
            $data = array(
                'name'  => $this->_request->getPost('name'),
                'email' => $this->_request->getPost('email')
            );

            if ( $form->isValid($data) )
            {
                $this->_model->update($data, "id = $id");
                $this->_redirect('/users');
            }
        }

        $this->view->form = $form; 
    }
Exemplo n.º 7
0
 /**
  * Action save.
  *
  * @return void
  */
 public function saveAction()
 {
     $messages = array();
     $isValidEmail = true;
     $session = new Zend_Session_Namespace('data');
     $form = new Application_Form_User();
     $table = new Tri_Db_Table('user');
     $data = $this->_getAllParams();
     if ($data['email'] && (!isset($data['id']) || !$data['id'])) {
         $row = $table->fetchRow(array('email = ?' => $data['email']));
         if ($row) {
             $isValidEmail = false;
             $messages[] = 'Email existing';
         }
     }
     if (!isset($data['id']) || !$data['id']) {
         $form->getElement('password')->setAllowEmpty(false);
     }
     if ($form->isValid($data) && $isValidEmail) {
         if (!$form->image->receive()) {
             $messages[] = 'Image fail';
         }
         $data = $form->getValues();
         if (!$form->image->getValue()) {
             unset($data['image']);
         }
         if (!$data['password']) {
             unset($data['password']);
         }
         if (isset($data['id']) && $data['id'] && Zend_Auth::getInstance()->hasIdentity()) {
             $row = $table->find($data['id'])->current();
             $row->setFromArray($data);
             $id = $row->save();
         } else {
             unset($data['id']);
             $row = $table->createRow($data);
             $id = $row->save();
             $session->attempt = 0;
             $data['password'] = $this->_getParam('password');
             $this->view->data = $data;
             $mail = new Zend_Mail(APP_CHARSET);
             $mail->setBodyHtml($this->view->render('user/welcome.phtml'));
             $mail->setSubject($this->view->translate('Welcome'));
             $mail->addTo($data['email'], $data['name']);
             $mail->send();
             $result = $this->login($data['email'], $data['password']);
             if ($result->isValid()) {
                 if ($session->url) {
                     $this->_helper->_flashMessenger->addMessage('Success');
                     $url = $session->url;
                     $session->url = null;
                     $this->_redirect($url);
                 }
             }
         }
         $this->_helper->_flashMessenger->addMessage('Success');
         $identity = Zend_Auth::getInstance()->getIdentity();
         if ($identity->id == $id) {
             $this->_redirect('user/edit');
         }
         if ($identity->role == 'institution') {
             $this->_redirect('user');
         }
         $this->_redirect('dashboard');
     }
     $messages[] = 'Error';
     $this->view->messages = $messages;
     $this->view->form = $form;
     $this->render('form');
 }
Exemplo n.º 8
0
 public function manageAction()
 {
     $userForm = new Application_Form_User();
     $userForm->getElement('password')->setRequired(false);
     if ($this->getRequest()->isPost()) {
         //if we are updating
         $userId = $this->getRequest()->getParam('id');
         if ($userId) {
             $userForm->setId($userId);
         }
         if ($userForm->isValid($this->getRequest()->getParams())) {
             $data = $userForm->getValues();
             $user = new Application_Model_Models_User($data);
             Application_Model_Mappers_UserMapper::getInstance()->save($user);
             $this->_helper->response->success($this->_helper->language->translate('Saved'));
             exit;
         } else {
             $this->_helper->response->fail(Tools_Content_Tools::proccessFormMessages($userForm->getMessages()));
             exit;
         }
     }
     $pnum = (int) filter_var($this->getParam('pnum'), FILTER_SANITIZE_NUMBER_INT);
     $offset = 0;
     if ($pnum) {
         $offset = 10 * ($pnum - 1);
     }
     $select = $this->_zendDbTable->getAdapter()->select()->from('user');
     $by = filter_var($this->getParam('by', 'last_login'), FILTER_SANITIZE_STRING);
     $order = filter_var($this->getParam('order', 'desc'), FILTER_SANITIZE_STRING);
     $searchKey = filter_var($this->getParam('key'), FILTER_SANITIZE_STRING);
     if (!in_array($order, array('asc', 'desc'))) {
         $order = 'desc';
     }
     $select = $select->order($by . ' ' . $order);
     $paginatorOrderLink = '/by/' . $by . '/order/' . $order;
     if (!empty($searchKey)) {
         $select->where('email LIKE ?', '%' . $searchKey . '%')->orWhere('full_name LIKE ?', '%' . $searchKey . '%')->orWhere('role_id LIKE ?', '%' . $searchKey . '%')->orWhere('last_login LIKE ?', '%' . date("Y-m-d", strtotime($searchKey)) . '%')->orWhere('ipaddress LIKE ?', '%' . $searchKey . '%');
         $paginatorOrderLink .= '/key/' . $searchKey;
     }
     $adapter = new Zend_Paginator_Adapter_DbSelect($select);
     $users = $adapter->getItems($offset, 10);
     $userPaginator = new Zend_Paginator($adapter);
     $userPaginator->setCurrentPageNumber($pnum);
     $userPaginator->setItemCountPerPage(10);
     $pager = $this->view->paginationControl($userPaginator, 'Sliding', 'backend/user/pager.phtml', array('urlData' => $this->_websiteUrl . 'backend/backend_user/manage', 'order' => $paginatorOrderLink));
     if ($order === 'desc') {
         $order = 'asc';
     } else {
         $order = 'desc';
     }
     if (!empty($searchKey)) {
         $this->view->orderParam = $order . '/key/' . $searchKey;
     } else {
         $this->view->orderParam = $order;
     }
     $this->view->by = $by;
     $this->view->order = $order;
     $this->view->key = $searchKey;
     $this->view->pager = $pager;
     $this->view->users = $users;
     $this->view->helpSection = 'users';
     $this->view->userForm = $userForm;
 }
Exemplo n.º 9
0
 public function editEmployeeAction()
 {
     $id = $this->_getParam('id');
     $this->view->user_id = $id;
     $model1 = new Application_Model_User();
     $model = $model1->find($id);
     if (false === $model) {
         $this->_flashMessenger->addMessage(array('error' => 'Invalid request! Please try again.'));
         $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/hr/employees'));
     }
     $options['firstName'] = $model->getFirstName();
     $options['middleName'] = $model->getMiddleName();
     $options['lastName'] = $model->getLastName();
     $options['email'] = $model->getEmail();
     $options['dob'] = $model->getDob();
     $options['doj'] = $model->getDoj();
     $options['pan'] = $model->getPan();
     $options['employeeCode'] = $model->getEmployeeCode();
     $options['contactNo'] = $model->getContactNo();
     $options['extensionNo'] = $model->getExtensionNo();
     $options['skype'] = $model->getSkype();
     $options['sex'] = $model->getSex();
     $options['mobile'] = $model->getMobile();
     $options['fatherName'] = $model->getFatherName();
     $options['marriageAnniversary'] = $model->getMarriageAnniversary();
     $options['designationId'] = $model->getDesignationId();
     $options['departmentId'] = $model->getDepartmentId();
     $options['userLevelId'] = $model->getUserLevelId();
     $options['correspondenceAddress'] = $model->getCorrespondenceAddress();
     $this->view->username = $model->getUsername();
     $request = $this->getRequest();
     $form = new Application_Form_User();
     //remove fields do not need to display in Edit
     //$form->removeElement('employeeCode');
     //$form->getElement('employeeCode')->setAttrib("readonly", "true");
     $form->removeElement('username');
     $form->removeElement('password');
     $form->removeElement('confirmPassword');
     $form->populate($options);
     $options = $request->getPost();
     if ($request->isPost()) {
         /*---- email validation ----*/
         if ($options['email'] != $model->getEmail()) {
             $form->getElement('email')->addValidators(array(array('Db_NoRecordExists', false, array('table' => 'user', 'field' => 'email', 'messages' => 'Email already exists, Please choose another email address.'))));
         }
         if ($options['employeeCode'] == $model->getEmployeeCode()) {
             $form->getElement('employeeCode')->removeValidator("Db_NoRecordExists");
         }
         /*-------------------------*/
         if ($form->isValid($options)) {
             $model->setOptions($options);
             $model->save();
             /*---------  Upload image START -------------------------*/
             $model->uploadProfilePicture($id, $options);
             /*---------  Upload image END -------------------------*/
             $this->_flashMessenger->addMessage(array('success' => 'Employee information has been updated successfully!'));
             $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/hr/edit-employee/id/' . $id));
         } else {
             $this->_flashMessenger->addMessage(array('error' => 'Unable to save the data. Please provide valid inputs and try again.'));
             $form->reset();
             $form->populate($options);
         }
     }
     $this->view->profile_image = $model->getProfileImage();
     $this->view->form = $form;
 }
Exemplo n.º 10
0
 public function loginAction()
 {
     $user_form = new Application_Form_User();
     $user_form->removeElement("userName");
     $user_form->removeElement("gender");
     $user_form->removeElement("country");
     $user_form->removeElement("profilePicture");
     $user_form->removeElement("signature");
     $user_form->getElement("email")->removeValidator("Zend_Validate_Db_NoRecordExists");
     $this->view->form = $user_form;
     if ($this->_request->isPost()) {
         if ($user_form->isValid($this->getRequest()->getParams())) {
             $email = $user_form->getValue("email");
             $password = $user_form->getValue("password");
             $db = Zend_Db_Table::getDefaultAdapter();
             $auth = new Zend_Auth_Adapter_DbTable($db, 'user', 'email', 'password', 'ban');
             $auth->setIdentity($email);
             $auth->setCredential(md5($password));
             $row = $auth->authenticate();
             if ($row->isValid()) {
                 $autho = Zend_Auth::getInstance();
                 $storage = $autho->getStorage();
                 //info=$autho ->getidentity
                 $storage->write($auth->getResultRowObject(array("id", "userName", "type", "profilePicture", "signature", "ban")));
                 //info-arrow id
                 if ($storage->read()->ban == "off") {
                     $this->view->message = "valid user";
                     $info = $autho->getIdentity();
                     $this->redirect("user/home");
                 } else {
                     $this->view->message = "You are banned";
                 }
             } else {
                 $this->view->message = "not valid user";
             }
         }
     }
 }
Exemplo n.º 11
0
    public function userfunctionAction()
    {
        //$db	= Zend_Db_Table_Abstract::getDefaultAdapter();
        $userForm = new Application_Form_User($_POST);
        if ($this->getRequest()->isPost()) {
            $this->request = $this->getRequest();
            if (isset($_POST['resetHighscore']) && $userForm->isValid($_POST)) {
                $db = Zend_Registry::get('dbc');
                $db->query('SET NAMES utf8;');
                /*
                 $adapter = new Zend_Auth_Adapter_DbTable(
                 		$db,
                 		'users',
                 		'name',
                 		'password'
                 );
                 
                $adapter->setIdentity($registerForm->getValue('username'));
                $adapter->setCredential($registerForm->getValue('passwor2'));
                 
                $result = $adapter->authenticate($adapter);
                 
                if (User nicht vorhanden) {
                */
                //$values = $userForm->getValues();
                $session = new Zend_Session_Namespace('loggedin');
                //$session->loggedin_id;
                $db->query('SET NAMES utf8;');
                $stmt = $db->prepare('DELETE		FROM	highscore
		
		                     		WHERE 		user_id = "' . $session->loggedin_id . '"');
                $stmt->execute();
                $success = 1;
                $this->view->success = $success;
                //$this->redirect('index');
            }
        }
        $request = $this->getRequest();
        if ($this->getRequest()->isPost()) {
            $this->request = $this->getRequest();
            if (isset($_POST['deleteAccount']) && $userForm->isValid($this->request->getPost())) {
                $db = Zend_Registry::get('dbc');
                $db->query('SET NAMES utf8;');
                if (!is_null($db)) {
                    $session = new Zend_Session_Namespace('loggedin');
                    $stmt2 = $db->prepare('	
									DELETE		FROM
												highscore
									WHERE 		user_id = "' . $session->loggedin_id . '"
									');
                    $stmt2->execute();
                    $stmt = $db->prepare('DELETE		FROM
		                                		users
					
		                     		WHERE 		user_id = "' . $session->loggedin_id . '"
									');
                    $stmt->execute();
                    Zend_Session::destroy(true);
                    $this->redirect('index');
                    //FEEBEELEES
                }
            }
        }
        $this->view->userForm = $userForm;
    }