public function authenticateAction() { $authAttempts = new Users_Model_AuthAttempts(); $attempt = $authAttempts->get(); $form = new Users_Form_Login(null, $this->view->base, $attempt && $attempt->surpassedMaxAllowed()); $formData = $this->_request->getPost(); $form->populate($formData); if (!$form->isValid($formData)) { $this->_helper->FlashMessenger->addMessage($this->view->translate('Invalid credentials')); $this->_redirectToNormalConnection(''); } $users = new Users_Model_Users(); $result = $users->authenticate($this->_request->getPost('username'), $this->_config->yubikey->enabled && $this->_config->yubikey->force ? $this->_request->getPost('yubikey') : $this->_request->getPost('password'), false, $this->view); if ($result) { $user = $users->getUser(); if ($attempt) { $attempt = $authAttempts->delete(); } if ($user->role != Users_Model_User::ROLE_ADMIN && $this->underMaintenance) { Zend_Auth::getInstance()->clearIdentity(); return $this->_redirectForMaintenance(true); } } else { if (!$attempt) { $authAttempts->create(); } else { $attempt->addFailure(); $attempt->save(); } $this->_helper->FlashMessenger->addMessage($this->view->translate('Invalid credentials')); } $this->_redirectToNormalConnection(''); }
protected function _validateTargetUser() { if (Zend_Registry::isRegistered('targetUser')) { // used by unit tests to inject the target user $this->targetUser = Zend_Registry::get('targetUser'); } else { $userId = $this->_getParam('userid'); if (is_null($userId)) { $this->targetUser = $this->user; } elseif ($this->_getParam('userid') == 0) { $users = new Users_Model_Users(); $this->targetUser = $users->createRow(); } else { if ($userId != $this->user->id && $this->user->role != Users_Model_User::ROLE_ADMIN) { $this->_helper->FlashMessenger->addMessage($this->view->translate('Error: Invalid user id')); $this->_redirect('profile/edit'); } $users = new Users_Model_Users(); $this->targetUser = $users->getRowInstance($userId); if ($this->_config->ldap->enabled) { $ldap = Monkeys_Ldap::getInstance(); $ldapUserData = $ldap->get("cn={$this->targetUser->username},{$this->_config->ldap->baseDn}"); $this->targetUser->overrideWithLdapData($ldapUserData, true); } } } $this->view->targetUser = $this->targetUser; }
public function sendAction() { $form = new Form_MessageUsers(); $formData = $this->_request->getPost(); $form->populate($formData); if (!$form->isValid($formData)) { return $this->_redirectFaultyForm($form); } $cc = $form->getValue('cc'); $bccArr = array(); if (trim($cc) != '') { $validator = new Zend_Validate_EmailAddress(); $bccArr = explode(',', $cc); for ($i = 0; $i < count($bccArr); $i++) { $bccArr[$i] = trim($bccArr[$i]); if (!$validator->isValid($bccArr[$i])) { foreach ($validator->getMessages() as $messageId => $message) { $form->cc->addError($this->view->translate('CC field must be a comma-separated list of valid E-mails')); return $this->_redirectFaultyForm($form); } } } } $mail = self::getMail($form->getValue('subject'), $this->_getParam('messageType'), $this->_getParam('messageType') == 'plain' ? $form->getValue('bodyPlain') : $form->getValue('bodyHTML')); $mail->setSubject($form->getValue('subject')); if ($this->_getParam('messageType') == 'plain') { $mail->setBodyText($form->getValue('bodyPlain')); } else { $mail->setBodyHtml($form->getValue('bodyHTML')); } $users = new Users_Model_Users(); // here we get the users emails stored in the users table, even if using LDAP, for performance reasons. // Do know however, that a user email is synced with the LDAP repository every time he logs in. foreach ($users->getUsers() as $user) { if ($user->role == Users_Model_User::ROLE_ADMIN) { continue; } $mail->addBcc($user->email); } foreach ($bccArr as $bcc) { $mail->addBcc($bcc); } try { $mail->send(); $this->_helper->FlashMessenger->addMessage($this->view->translate('Message has been sent')); } catch (Zend_Mail_Protocol_Exception $e) { $this->_helper->FlashMessenger->addMessage($this->view->translate('There was an error trying to send the message')); if ($this->_config->logging->level == Zend_Log::DEBUG) { $this->_helper->FlashMessenger->addMessage($e->getMessage()); return $this->_redirectFaultyForm($form); } } $this->_redirect(''); }
public function indexAction() { $this->_helper->viewRenderer->setNeverRender(true); $users = new Users_Model_Users(); switch ($this->_getParam('filter')) { case 'confirmed': $where = "accepted_eula=1 AND role != '" . Users_Model_User::ROLE_ADMIN . "'"; break; case 'unconfirmed': $where = "accepted_eula=0 AND role != '" . Users_Model_User::ROLE_ADMIN . "'"; break; default: $where = false; break; } // This retrieves user data from the users table, even if using LDAP. This means the user's full name // might be out of sync with what it's in LDAP. No biggie since user's names rarely change ;) // However do know that a given user name is synced with LDAP every time he logs in. $usersRows = $users->getUsers($this->_getParam('startIndex'), $this->_getParam('results'), $this->_getParam('sort', 'registration'), $this->_getParam('dir', Users_Model_Users::DIR_DESC), $where, trim($this->_getParam('search'))); $jsonObj = new StdClass(); $jsonObj->recordsReturned = count($usersRows); $jsonObj->totalRecords = $users->getNumUsers($where, trim($this->_getParam('search'))); $jsonObj->totalUsers = $users->getNumUsers(); $jsonObj->totalUnconfirmedUsers = $users->getNumUnconfirmedUsers(); $jsonObj->startIndex = $this->_getParam('startIndex'); $jsonObj->sort = $this->_getParam('sort'); $jsonObj->dir = $this->_getParam('dir'); $jsonObj->records = array(); foreach ($usersRows as $user) { if ($user->role == Users_Model_User::ROLE_ADMIN) { if ($this->_config->ldap->enabled && $user->username != $this->_config->ldap->admin) { // this is the admin created during the installation, that is not used when ldap is enabled continue; } $status = $this->view->translate('admin'); } else { if ($user->accepted_eula) { $status = $this->view->translate('confirmed'); } else { $status = $this->view->translate('unconfirmed'); } } $jsonObjUser = new StdClass(); $jsonObjUser->id = $user->id; $jsonObjUser->name = $user->getFullName(); $jsonObjUser->registration = $user->registration_date; $jsonObjUser->role = $user->role; $jsonObjUser->status = $status; $jsonObjUser->reminders = $user->accepted_eula ? 0 : $user->reminders; $jsonObj->records[] = $jsonObjUser; } echo Zend_Json::encode($jsonObj); }
/** * I need to fill the new profile_id field in the fields_values table, before being able to * add a foreign key to it */ public function proceed() { $fieldsValues = new Model_FieldsValues(); $users = new Users_Model_Users(); foreach ($users->getUsers() as $user) { $profileId = $user->createDefaultProfile($this->_view); foreach ($fieldsValues->getForUser($user) as $fieldValue) { $fieldValue->profile_id = $profileId; $fieldValue->save(); } } $this->_db->query('ALTER TABLE `fields_values` ADD FOREIGN KEY ( `profile_id` ) REFERENCES `profiles` (`id`) ON DELETE CASCADE'); }
public function init() { Zend_Registry::get('logger')->log('Route used: ' . Application::$front->getRouter()->getCurrentRouteName(), Zend_Log::DEBUG); $this->_config = Zend_Registry::get('config'); $this->_settings = new Model_Settings(); if ($this->_request->getModuleName() != 'install' && strtoupper(get_class($this)) != 'ERRORCONTROLLER' && $this->_needsUpgrade()) { $this->_redirect('/install/upgrade'); return; } if (!Zend_Registry::isRegistered('user')) { // guest user $users = new Users_Model_Users(); $user = $users->createRow(); Zend_Registry::set('user', $user); } $this->user = Zend_Registry::get('user'); $this->view->user = $this->user; $this->_validateTargetUser(); $this->_checkMaintenanceMode(); $this->view->controller = $this; $this->view->addHelperPath('libs/Monkeys/View/Helper', 'Monkeys_View_Helper'); $this->view->setUseStreamWrapper(true); $this->_addCustomTemplatePath(); $this->view->addBasePath(APP_DIR . '/views'); $this->_addCustomTemplatePath(); $this->_setBase(); $this->view->numCols = $this->_numCols; $this->view->module = $this->getRequest()->getModuleName(); if ($this->_getParam('subtitle')) { $this->view->pageSubtitle = $this->view->escape($this->_getParam('subtitle')); } if ($this->getRequest()->getParam('next')) { $this->view->nextAction = $this->getRequest()->getParam('next'); } else { $this->view->nextAction = ''; } $this->view->messages = $this->_helper->FlashMessenger->getMessages(); if ($this->getRequest()->isXmlHttpRequest()) { $slowdown = $this->_config->environment->ajax_slowdown; if ($slowdown > 0) { sleep($slowdown); } $this->_helper->layout->disableLayout(); } else { $this->view->version = Application::VERSION; $this->view->loaderCombine = $this->_config->environment->YDN ? 'true' : 'false'; $this->view->loaderBase = $this->_config->environment->YDN ? 'http://yui.yahooapis.com/2.7.0/build/' : $this->view->base . '/javascript/yui/'; } $this->view->min = $this->_config->environment->production ? '-min' : ''; }
public function sendreminderAction() { $this->_helper->viewRenderer->setNeverRender(true); $users = new Users_Model_Users(); foreach ($users->getUnconfirmedUsers($this->_getParam('olderthan')) as $user) { $mail = self::getMail($user, $this->view->translate('Community-ID registration reminder')); try { $mail->send(); $this->_increaseReminderCount($user); } catch (Zend_Mail_Exception $e) { Zend_Registry::get('logger')->log($e->getMessage(), Zend_Log::ERR); if (!$this->_config->environment->production) { // still increase the reminder counter when testing $this->_increaseReminderCount($user); } } } }
public function proceedAction() { // double check upgrade is necessary in case someone access this action directly if (!$this->_needsUpgrade()) { $this->_redirect(''); return; } $form = new Install_Form_UpgradeLogin(); $formData = $this->_request->getPost(); $form->populate($formData); if (!$form->isValid($formData)) { $appSession = Zend_Registry::get('appSession'); $appSession->loginForm = $form; $this->_forward('index'); return; } $users = new Users_Model_Users(); list($super, $mayor, $minor) = explode('.', $this->_getDbVersion()); $greaterThan2 = $super >= 2; $result = $users->authenticate($this->_request->getPost('username'), $this->_request->getPost('password'), false, $this->view, !$greaterThan2); if (!$result) { $this->_helper->FlashMessenger->addMessage($this->view->translate('Invalid credentials')); $this->_redirect('index'); return; } $user = $users->getUser(); if ($user->role != Users_Model_User::ROLE_ADMIN) { Zend_Auth::getInstance()->clearIdentity(); $this->_helper->FlashMessenger->addMessage($this->view->translate('Invalid credentials')); $this->_redirect('index'); return; } $this->_runUpgrades(true); $upgradedVersion = $this->_runUpgrades(false); $this->_helper->FlashMessenger->addMessage($this->view->translate('Upgrade was successful. You are now on version %s', $upgradedVersion)); $missingConfigs = $this->_checkMissingConfigDirectives(); if ($missingConfigs) { $this->_helper->FlashMessenger->addMessage($this->view->translate('WARNING: there are some new configuration settings. To override their default values (as set in config.default.php) add them to your config.php file. The new settings correspond to the following directives: %s.', implode(', ', $missingConfigs))); } // we need to logout user in case the user table changed Zend_Auth::getInstance()->clearIdentity(); Zend_Session::forgetMe(); $this->_redirect('/'); }
public function resetAction() { $users = new Users_Model_Users(); $user = $users->getUserWithToken($this->_getParam('token')); if (!$user) { $this->_helper->FlashMessenger->addMessage($this->view->translate('Wrong Token')); $this->_redirect(''); return; } $newPassword = $user->generateRandomPassword(); $user->setClearPassword($newPassword); // reset token $user->token = Users_Model_User::generateToken(); $user->save(); $file = CommunityID_Resources::getResourcePath('passwordreset2_mail.txt'); $emailTemplate = file_get_contents($file); $emailTemplate = str_replace('{userName}', $user->getFullName(), $emailTemplate); $emailTemplate = str_replace('{password}', $newPassword, $emailTemplate); $this->_sendMail($user->email, $this->view->translate('Community-ID password reset'), $emailTemplate); $this->_helper->FlashMessenger->addMessage($this->view->translate('You\'ll receive your new password via E-mail')); $this->_redirect(''); }
private function _createAdmin(Install_Form_Install $form) { $users = new Users_Model_Users(); $user = $users->createRow(); $user->username = $form->getValue('username'); $user->accepted_eula = 1; $user->registration_date = date('Y-m-d'); $user->openid = ''; $user->setClearPassword($form->getValue('password1')); $user->firstname = 'Admin'; $user->lastname = 'User'; $user->email = $form->getValue('supportemail'); $user->role = Users_Model_User::ROLE_ADMIN; $user->save(); }
public function accepteulaAction() { $users = new Users_Model_Users(); if ($this->_request->getParam('token') == '' || !($user = $users->getUserWithToken($this->_request->getParam('token')))) { $this->_helper->FlashMessenger->addMessage($this->view->translate('Invalid token')); $this->_redirect(''); return; } $user->role = Users_Model_User::ROLE_REGISTERED; $user->accepted_eula = 1; $user->registration_date = date('Y-m-d'); $user->token = ''; if ($this->_config->ldap->enabled) { $ldap = Monkeys_Ldap::getInstance(); $ldap->add($user); // clear unencrypted password $user->setPassword(''); } $user->save(); $auth = Zend_Auth::getInstance(); $auth->getStorage()->write($user); $this->_redirect('/users/profile'); }
public function authenticateAction() { $server = $this->_getOpenIdProvider(); $request = $server->decodeRequest(); $authAttempts = new Users_Model_AuthAttempts(); $attempt = $authAttempts->get(); $form = new Form_OpenidLogin(null, $this->view->base, $attempt && $attempt->surpassedMaxAllowed()); $formData = $this->_request->getPost(); $form->populate($formData); if (!$form->isValid($formData)) { $formErrors = $form->getErrors(); // gotta resort to pass errors as params because we don't use the session here if (@$formErrors['captcha']) { $this->_forward('login', null, null, array('invalidCaptcha' => true)); } else { $this->_forward('login'); } return; } $users = new Users_Model_Users(); $result = $users->authenticate($request->idSelect() ? $form->getValue('openIdIdentity') : $request->identity, $this->_config->yubikey->enabled && $this->_config->yubikey->force ? $form->getValue('yubikey') : $form->getValue('password'), true, $this->view); if ($result) { if ($attempt) { $attempt->delete(); } $sites = new Model_Sites(); $trustRoot = $this->_getTrustRoot($request); if ($sites->isTrusted($users->getUser(), $trustRoot)) { $this->_forward('proceed', null, null, array('allow' => true)); } elseif ($sites->isNeverTrusted($users->getUser(), $trustRoot)) { $this->_forward('proceed', null, null, array('deny' => true)); } else { $this->_forward('trust'); } } else { if (!$attempt) { $authAttempts->create(); } else { $attempt->addFailure(); $attempt->save(); } $this->_forward('login', null, null, array('invalidLogin' => true)); } }