Beispiel #1
0
 protected function fixfuckupaction()
 {
     $sql = 'SELECT id_contact from smsqueque where created_at::date = \'2011-01-31\'  and send = true and content not ilike \'%01.02%\';';
     $model = new User();
     $i = $model->getAdapter()->query($sql);
     $items = $i->fetchAll();
     foreach ($items as $item) {
     }
 }
 public function confirmAction()
 {
     $guid = $this->getRequest()->getParam(User::COL_GUID);
     $userTable = new User();
     $dbAdapter = $userTable->getAdapter();
     $result = $userTable->update(array(User::COL_ACTIVE => 1, User::COL_GUID => null), $dbAdapter->quoteInto(User::COL_GUID . '=?', $guid));
     if ($result == 1) {
         $this->view->message = 'User confirmed!';
     } else {
         $this->view->message = 'User not confirmed!';
     }
 }
    /**
     * Deleta um registro e redireciona para 'users/list'
     * Caso não seja informado nenhum ID pela url,
     * o usuário será redirecionado para 'users'
     *
     * @return void
     */
    public function deleteAction()
    {
        // verificamos se realmente foi informado algum ID
        if ( $this->_hasParam('id') == false )
        {
            $this->_redirect('users');
        }
 
        $id = (int) $this->_getParam('id');
        $where = $this->_model->getAdapter()->quoteInto('id = ?', $id);
        $this->_model->delete($where);
        $this->_redirect('users/list');
    } 
Beispiel #4
0
 protected function updateWsClientaction()
 {
     $sql = 'SELECT id,login,first_name,surname,email from "user" where ws_client_id is null';
     $model = new User();
     $u = $model->getAdapter()->query($sql);
     $users = $u->fetchAll();
     foreach ($users as $user) {
         $values = array();
         $clientModel = new Wsclient();
         $clientData = array('client_name' => $user['login'], 'pm_name' => $user['first_name'] . ' ' . $user['surname'], 'pm_email' => $user['email'], 'ip_address' => array());
         $newClient = $clientModel->createRow($clientData);
         $values['ws_client_id'] = $newClient->save();
         $row = $model->findOne($user['id']);
         $row->setFromArray($values);
         $row->save();
     }
 }
Beispiel #5
0
 public function updateAction()
 {
     $userTable = new User();
     if ($this->getRequest()->isPost()) {
         if ($this->form->isValid($this->getRequest()->getParams())) {
             $data = array(User::COL_CITY => $this->form->getValue(User::COL_CITY), User::COL_USERNAME => $this->form->getValue(User::COL_USERNAME), User::COL_EMAIL => $this->form->getValue(User::COL_USERNAME), User::COL_COUNTRY => $this->form->getValue(User::COL_COUNTRY), User::COL_FAX => $this->form->getValue(User::COL_FAX), User::COL_FIRSTNAME => $this->form->getValue(User::COL_FIRSTNAME), User::COL_LASTNAME => $this->form->getValue(User::COL_LASTNAME), User::COL_INSTITUTION => $this->form->getValue(User::COL_INSTITUTION), User::COL_PHONE => $this->form->getValue(User::COL_PHONE), User::COL_ACTIVE => $this->form->getValue(User::COL_ACTIVE), User::COL_ROLE => $this->form->getValue(User::COL_ROLE), User::COL_STREET => $this->form->getValue(User::COL_STREET));
             $updateResult = 0;
             try {
                 $updateResult = @$userTable->update($data, $userTable->getAdapter()->quoteInto(User::COL_ID . "=?", $this->form->getValue(User::COL_ID)));
             } catch (Exception $e) {
                 if ($updateResult == 0) {
                     $this->view->message = 'Please try another username!';
                 }
             }
         }
     } else {
         $userResult = $userTable->find($this->getRequest()->getParam(User::COL_ID))->current();
         $this->form->populate($userResult->toArray());
     }
 }
Beispiel #6
0
 public function searchAction()
 {
     //display only active users with their assigned expertise
     $request = $this->getRequest();
     $params = $this->namespace->searchParams;
     $formValues = $this->namespace->formValues;
     $userTable = new User();
     $valueTable1 = new ValueList();
     $valueTable2 = new ValueList();
     $select = $userTable->getAdapter()->select();
     $tableAdapter = $userTable->getAdapter();
     $select->from(array('user' => $userTable->getTableName()));
     //XXX remove leftJoin, only Alpha
     $select->joinLeft(array('val1' => ValueList::TABLE_NAME), 'user.' . User::COL_INSTITUTION . '=' . 'val1.' . ValueList::COL_ID, array('Institution' => ValueList::COL_NAME));
     $select->joinLeft(array('val2' => ValueList::TABLE_NAME), 'user.' . User::COL_COUNTRY . '=' . 'val2.' . ValueList::COL_ID, array('Country' => ValueList::COL_NAME));
     $select->joinLeft(array('userHasExpe' => UserHasExpertise::TABLE_NAME), 'user.' . User::COL_ID . '=' . 'userHasExpe.' . UserHasExpertise::COL_USER_ID, array('expertiseId' => UserHasExpertise::COL_EXPE_ID));
     $select->joinLeft(array('expe' => Expertise::TABLE_NAME), 'userHasExpe.' . UserHasExpertise::COL_EXPE_ID . '=' . 'expe.' . Expertise::COL_ID, array('eSpec' => Expertise::COL_SPECIES, 'eArea' => Expertise::COL_AREA, 'eSubj' => Expertise::COL_SUBJECT));
     $select->where('user.' . User::COL_ACTIVE . ' = ?', 1);
     //echo $select.'<br>';
     //list details
     //handle multi select/multi checkbox values
     //concatenate strings and decorate with HTML tags for list presentation
     if ($params['listDetails'] == 1) {
         $rowSet = $tableAdapter->fetchAll($select);
         if (count($rowSet) > 0) {
             $userHasExpAsArray = array();
             foreach ($rowSet as $row) {
                 if (!isset($userHasExpAsArray[$row[User::COL_ID]])) {
                     $userHasExpAsArray[$row[User::COL_ID]] = '';
                 }
                 if ($row['expertiseId'] != NULL) {
                     //$attrConcat = '<td>'.$row['eSpec'].','.$row['eArea'].','.$row['eSubj'].'</td>';
                     $attrConcat = '<li>' . $row['eSpec'] . ',' . $row['eArea'] . ',' . $row['eSubj'] . '</li>';
                     $userHasExpAsArray[$row[User::COL_ID]] = $userHasExpAsArray[$row[User::COL_ID]] . $attrConcat;
                 }
             }
             foreach ($userHasExpAsArray as &$expList) {
                 //$expList = "<table border = 'solid'><tr>".$expList.'</tr></table>';
                 $expList = '<ul>' . $expList . '</ul>';
             }
             $this->view->userHasExpAsArray = $userHasExpAsArray;
         }
     }
     //handle AND/OR search
     if ($params['kind'] == 'and') {
         foreach ($formValues as $key => $value) {
             if ($key != null && $value != null && $key != 'kind' && $key != 'submit' && $key != 'listDetails') {
                 if ($key == UserHasExpertise::COL_EXPE_ID) {
                     //$tableRow = $tableAdapter->quoteIdentifier($key);
                     $partStatement = $tableAdapter->quoteInto('userHasExpe.' . UserHasExpertise::COL_EXPE_ID . ' = ?', $value);
                     $select->where($partStatement);
                 } elseif ($key == User::COL_COUNTRY || $key == User::COL_INSTITUTION) {
                     $tableRow = $tableAdapter->quoteIdentifier($key);
                     $partStatement = $tableAdapter->quoteInto($tableRow . ' = ?', $value);
                     $select->where($partStatement);
                 } else {
                     $tableRow = $tableAdapter->quoteIdentifier($key);
                     $partStatement = $tableAdapter->quoteInto($tableRow . ' LIKE ?', '%' . $value . '%');
                     $select->where($partStatement);
                 }
             }
         }
     }
     if ($params['kind'] == 'or') {
         $orWhere = '';
         foreach ($formValues as $key => $value) {
             if ($key != null && $value != null && $key != 'kind' && $key != 'submit' && $key != 'listDetails') {
                 if ($key == UserHasExpertise::COL_EXPE_ID) {
                     //$tableRow = $tableAdapter->quoteIdentifier($key);
                     $partStatement = $tableAdapter->quoteInto('userHasExpe.' . UserHasExpertise::COL_EXPE_ID . ' = ?', $value);
                 } elseif ($key == User::COL_COUNTRY || $key == User::COL_INSTITUTION) {
                     $tableRow = $tableAdapter->quoteIdentifier($key);
                     $partStatement = $tableAdapter->quoteInto($tableRow . ' = ?', $value);
                 } else {
                     $tableRow = $tableAdapter->quoteIdentifier($key);
                     $partStatement = $tableAdapter->quoteInto($tableRow . ' LIKE ?', '%' . $value . '%');
                 }
                 //append the where to the "where or where" container
                 if (isset($partStatement)) {
                     if ($orWhere == '') {
                         $orWhere = $partStatement;
                     } else {
                         $orWhere = $orWhere . ' OR ' . $partStatement;
                     }
                 }
                 unset($partStatement);
             }
         }
         //finally append the where to the select(whole metadata)
         if ($orWhere != '') {
             $select->where($orWhere);
         }
     }
     //filter double datasets caused by multiple meta data
     $select->group('user.' . User::COL_ID);
     //for setting ws-manager filter low user roles
     if ($this->defaultNamespace->callingAction == 'workshop/edit/update') {
         $select->where('(user.' . User::COL_ROLE . ' = ?', 'ws-manager');
         $select->orWhere('user.' . User::COL_ROLE . ' = ?)', 'admin');
     }
     //echo $select;
     //get already assigned datasets for setting disabled in view
     if ($this->defaultNamespace->callingAction == 'ce/editparticipants/index') {
         $ceId = $this->defaultNamespace->callingActionId;
         $part = new Participant();
         $rowSet = $part->fetchAll(Participant::COL_CE_ID . '=' . $ceId);
         if (count($rowSet) > 0) {
             $participants = array();
             foreach ($rowSet as $row) {
                 $participants[$row[Participant::COL_USER_ID]] = TRUE;
             }
             $this->view->participants = $participants;
         }
     }
     /**
      * Pagination control
      */
     $paginator = new Ble422_Paginator_Extended($select, $this->getRequest());
     $paginator->setHeader(array(array('raw' => User::COL_USERNAME, 'name' => 'Username'), array('raw' => User::COL_ROLE, 'name' => 'User role'), array('raw' => User::COL_FIRSTNAME, 'name' => 'First name'), array('raw' => User::COL_LASTNAME, 'name' => 'Last name'), array('raw' => User::COL_EMAIL, 'name' => 'E-mail'), array('raw' => 'Institution', 'name' => 'Institution'), array('raw' => User::COL_STREET, 'name' => 'Street'), array('raw' => User::COL_CITY, 'name' => 'City'), array('raw' => 'Country', 'name' => 'Country')));
     $paginator->setCurrentPageNumber($this->getRequest()->getParam('page'))->setItemCountPerPage(1000)->setPageRange(10)->orderBy($this->getRequest()->getParam('orderBy'));
     //$this->_getParam('pageRange'));
     Zend_View_Helper_PaginationControl::setDefaultViewPartial('partials/list_pagination_control.phtml');
     $this->view->paginator = $paginator;
     // TODO im Plugin in die registry setzen, leichterer Aufruf
     // Get user_role
     $auth = Zend_Auth::getInstance();
     $storage = $auth->getStorage();
     $constUserRole = User::COL_ROLE;
     $userRole = $storage->read()->{$constUserRole};
     $this->view->userRole = $userRole;
     $this->view->callingAction = $this->defaultNamespace->callingAction;
     $this->view->callingActionId = $this->defaultNamespace->callingActionId;
     //		}
 }
 public function myresetpasswordAction()
 {
     //check GUID param with database
     //remove all elements, only password and repeat stays
     $this->form = new User_Form_Edit();
     $elems = $this->form->getElements();
     foreach ($elems as $elem) {
         if (!($elem->getName() == User::COL_PASSWORD || $elem->getName() == User_Form_Edit::PASSWORD_CLONE || $elem->getName() == 'submit' || $elem->getName() == User::COL_GUID)) {
             $this->form->removeElement($elem->getName());
         }
     }
     if ($this->getRequest()->isPost()) {
         if ($this->form->isValid($this->getRequest()->getParams())) {
             //update password
             $pass = $this->form->getValue(User::COL_PASSWORD);
             if ($pass != $this->getRequest()->getParam(User_Form_Edit::PASSWORD_CLONE)) {
                 $element = $this->form->getElement(User_Form_Edit::PASSWORD_CLONE);
                 $element->addError("Error: Your password and the repeating don't match.");
                 $this->form->markAsError();
                 return $this->render('form');
             }
             /*
             credit: http://www.geekzilla.co.uk/view8AD536EF-BC0D-427F-9F15-3A1BC663848E.htm
             Author  	: Paul Hayman
             Published 	: 14 June 2006
             */
             $regexStringGuid = "^(\\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\\}{0,1})\$^";
             $vali = new Zend_Validate_Regex($regexStringGuid);
             $userGuid = $this->getRequest()->getParam(User::COL_GUID);
             if ($vali->isValid($userGuid)) {
                 $user = new User();
                 $select = $user->select();
                 $where = $user->getAdapter()->quoteInto(User::COL_GUID . ' = ?', $userGuid, 'string');
                 $select->where($where);
                 $rowset = $user->fetchAll($select);
                 if ($rowset->count() == 1) {
                     $data = array(User::COL_PASSWORD => "{SHA}" . base64_encode(pack("H*", sha1($pass))), User::COL_GUID => null);
                     try {
                         $user->update($data, $where);
                     } catch (Exception $e) {
                         throw new Exception('Error: Password was not changed' . $e->getMessage());
                     }
                 } else {
                     //no or too much users with this GUID!
                     //TODO log in IDS?
                 }
             } else {
                 //param != GUID
                 //TODO log in IDS?
             }
             $this->view->message = 'password was changed';
             $this->render('message');
         } else {
             //not valid
             $this->render('form');
         }
     } else {
         //not post
         $userGuid = $this->getRequest()->getParam(User::COL_GUID);
         $this->form->setValues(array(User::COL_GUID => $userGuid));
         $this->view->form = $this->form;
         $this->render('form');
     }
 }
Beispiel #8
0
 public function loginAction()
 {
     $request = $this->getRequest();
     if ($request->isXmlHttpRequest()) {
         $this->_helper->layout()->disableLayout();
         $this->view->block_redirect = '/auth/login/msg/' . $request->getParam('msg', '');
     } else {
         $ip = $this->_helper->currentip();
         $form = new Logic_User_Form_Login();
         $this->view->form = $form;
         $identity = Zend_Auth::getInstance()->getIdentity();
         if (is_null($identity)) {
             $layout = Zend_Layout::getMvcInstance();
             $layout->setLayout('_layouts/login');
         }
         if (null !== ($identity = Zend_Auth::getInstance()->getIdentity())) {
             return $this->_redirect($identity->defaultAction);
         }
         if ($request->getParam('msg', false) == 'blocked') {
             $this->_helper->messenger('error', 'System blocked.');
         }
         if ($request->isPost() and !strstr($_SERVER['SERVER_NAME'], 'szkolenia')) {
             if ($form->isValid($request->getPost())) {
                 $values = $form->getValues();
                 $config = Zend_Registry::get('config');
                 switch ($config['auth']['method']) {
                     case "LDAP":
                     default:
                         $adapter = new Logic_Auth_Adapter_Ldap();
                         break;
                     case "DB":
                         $user = new User();
                         $adapter = new Logic_Auth_Adapter_RemoteUserDbTable($user->getAdapter(), 'user', 'login', 'password', 'MD5(?)');
                         break;
                 }
                 $adapter->setIdentity($values['login'])->setCredential($values['password']);
                 $auth = Zend_Auth::getInstance();
                 $result = $auth->authenticate($adapter);
                 if (!$result->isValid() && $request->getParam('msg', false) != 'blocked') {
                     switch ($result->getCode()) {
                         case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
                         case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
                             $uzytkownik = new Logic_User();
                             $uzytkownik->failedLogin($values['login'], md5($values['password']));
                             $this->_helper->messenger('error', 'Error while logging in. Specified account doesnt exist or account is inactive.');
                             break;
                         default:
                             $this->_helper->messenger('error', 'Error while logging in.');
                             break;
                     }
                 } else {
                     $storage = $auth->getStorage();
                     $storageRow = $auth->getIdentity();
                     $uzytkownik = new Logic_User();
                     $uzytkownik->login($values['login'], md5($values['password']));
                     $uriSessionCheck = new Zend_Session_Namespace('prevUri');
                     if (isset($uriSessionCheck->uri) && $uriSessionCheck->uri != '/' && $uriSessionCheck->uri != '') {
                         $action = $uriSessionCheck->uri;
                         Zend_Session::namespaceUnset('prevUri');
                     } else {
                         $action = $uzytkownik->getDefaultAction();
                         $action = $action ? $action : '/';
                     }
                     $userProfiles = $uzytkownik->getProfiles(Zend_Auth::getInstance()->getIdentity()->id);
                     $userProfile = $userProfiles->current();
                     $action = $userProfile->landing;
                     try {
                         Logic_Client::getInstance();
                     } catch (Exception $exc) {
                         $this->_helper->messenger('info', 'Brak ustawionego Klienta. Niektóre funkcjonalności nie będą dostępne.');
                     }
                     $storageRow->defaultAction = $action;
                     $storage->write($storageRow);
                     Zend_Session::setOptions(array('remember_me_seconds' => 7200));
                     return $this->_redirect($action);
                 }
             }
         }
     }
 }
Beispiel #9
0
 public function _failedLogin($login)
 {
     $ci = Zend_Controller_Action_HelperBroker::getStaticHelper('Currentip');
     $ip = $ci->getCurrentIp();
     $user = new User();
     $where = $user->getAdapter()->quoteInto('login = ?', $login);
     $u = $user->fetchRow($where);
     if ($u) {
         $row = $user->findOne($u->id);
         $dataRow = $row->toArray();
         if ($dataRow['is_locked'] === false) {
             $oldRow = clone $row;
             $data = array('unsuccessful_logins_number' => ++$dataRow['unsuccessful_logins_number'], 'last_unsuccessful_login_at' => date('c'), 'last_unsuccessful_login_ip' => $ip);
             $unsuccesfulLoginLimit = $this->getFailedLoginLimit();
             if ($dataRow['unsuccessful_logins_number'] >= $unsuccesfulLoginLimit) {
                 $data['is_locked'] = 't';
                 $data['last_lock_at'] = date('c');
                 $data['lock_reason'] = 'Blokada użytkownika po ' . $unsuccesfulLoginLimit . ' nieudanych próbach zalogowania';
             }
             $row->setFromArray($data);
             $row->save();
             $log = Zend_Registry::get('admin_log');
             $log->userlock(array('old' => $oldRow, 'new' => $row));
             $logger = Zend_Registry::get('logger');
             $logger['messages']['User'][$id] = 'Failed to login. Login is locked, unsuccessfull login attempts: ' . $dataRow['unsuccessful_logins_number'];
             Zend_Registry::set('logger', $logger);
         } else {
             $logger = Zend_Registry::get('logger');
             $logger['messages']['User'][$id] = 'Failed to login. Login or password was incorrect.';
             Zend_Registry::set('logger', $logger);
         }
     } else {
         $data['ip'] = $ip;
         $data['created_at'] = date('c');
         $data['login'] = $login;
         $logger = Zend_Registry::get('logger');
         $logger['messages']['User'][$id] = 'Failed to login. Wrong login was entered.';
         Zend_Registry::set('logger', $logger);
     }
 }