function getSfGuardUser() { if (!$this->sf_guard_user) { $this->sf_guard_user = sfGuardUserPeer::retrieveByPK($this->sf_guard_user_id); } return $this->sf_guard_user; }
protected function doClean($values) { $username = isset($values[$this->getOption('username_field')]) ? $values[$this->getOption('username_field')] : ''; $password = isset($values[$this->getOption('password_field')]) ? $values[$this->getOption('password_field')] : ''; $remember = isset($values[$this->getOption('rememeber_checkbox')]) ? $values[$this->getOption('rememeber_checkbox')] : ''; $session_user = sfContext::getInstance()->getUser(); // user exists? if ($user = sfGuardUserPeer::retrieveByUsername($username)) { // password is ok? if ($user->checkPassword($password)) { /* Added for sfGuardSecurity */ $this->checkForceRedirectPasswordChange($user); $session_user->setAttribute('sf_guard_secure_plugin_login_failure_detected', 0); /* end */ return array_merge($values, array('user' => $user)); } } if ($this->getOption('check_login_failure')) { /* Added for sfGuardSecurity */ sfGuardLoginFailure::trackFailure($username); $this->checkSecurityAttack($username); /* end */ } if ($this->getOption('throw_global_error')) { throw new sfValidatorError($this, 'invalid'); } throw new sfValidatorErrorSchema($this, array($this->getOption('username_field') => new sfValidatorError($this, 'invalid'))); }
/** * @depends testNotifierExists * @depends testConcreteNotificationExists */ public function testNotify() { /* @var $user sfGuardUser */ $user = sfGuardUserPeer::retrieveByUsername('Username'); $this->assertInstanceOf('sfGuardUser', $user); /* @var $type NotificationType */ $type = NotificationTypePeer::retrieveByName('SimpleFile'); $this->assertInstanceOf('NotificationType', $type); $criteria = new Criteria(NotificationConfigurationPeer::DATABASE_NAME); $criteria->add(NotificationConfigurationPeer::NAME, 'Sample Configuration for SimpleFile'); $criteria->add(NotificationConfigurationPeer::NOTIFICATION_TYPE_ID, $type->getId()); $criteria->add(NotificationConfigurationPeer::USER_ID, $user->getId()); /* @var $configuration NotificationConfiguration */ $configuration = NotificationConfigurationPeer::doSelectOne($criteria); $this->assertInstanceOf('NotificationConfiguration', $configuration); $this->assertTrue($configuration->hasAttribute('filename')); $notification = new TestConcreteNotification(); $notification->setNotificationConfiguration($configuration); $data = array('Simple array', 'to put into a file.'); $notification->notify($data); $filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'simple_notifications.log'; $content = file($filename); $this->assertEquals($data, unserialize($content[0])); unlink($filename); }
public function executeDelete(sfWebRequest $request) { $request->checkCSRFProtection(); $this->forward404Unless($sfGuardUser = sfGuardUserPeer::retrieveByPk($request->getParameter('id')), sprintf('Object sfGuardUser does not exist (%s).', $request->getParameter('id'))); $sfGuardUser->delete(); $this->redirect('sfguarduser/index'); }
/** * @param sfWebRequest $request * @return void */ public function execute($request) { $this->user = sfGuardUserPeer::retrieveByPK($request->getParameter('id')); $this->forward404Unless($this->user, 'User Not Found'); $this->statusActions = StatusActionPeer::getStatusActionsForBoard($this->user->getId()); $this->commentBoards = CommentPeer::getCommentsForBoard($this->user->getId()); }
/** *Method responsible for showing only piece of advice. It transfers advice and author object * @param sfWebRequest $request */ public function executeShow(sfWebRequest $request) { $myadvice = $this->getRoute()->getObject(); $this->thisauthor = sfGuardUserPeer::getUserBy($myadvice->getUserId()); $this->advice = $myadvice; $this->forward404Unless($this->advice); }
/** * @see sfValidatorBase */ protected function doClean($values) { // only validate if username and password are both present if (isset($values[$this->getOption('username_field')]) && isset($values[$this->getOption('password_field')])) { $username = $values[$this->getOption('username_field')]; $password = $values[$this->getOption('password_field')]; // user exists? if ($user = sfGuardUserPeer::retrieveByUsername($username)) { // password is ok? if ($user->getIsActive()) { if (Configuration::get('ldap_enabled', false)) { if (authLDAP::checkPassword($username, $password)) { return array_merge($values, array('user' => $user)); } } elseif ($user->checkPassword($password)) { return array_merge($values, array('user' => $user)); } } } elseif (Configuration::get('ldap_enabled', false) && Configuration::get('ldap_create_user', false) && authLDAP::checkPassword($username, $password)) { $user = new sfGuardUser(); $user->setUsername($username); $user->save(); $profile = new Profile(); $profile->setSfGuardUserId($user->getId()); $profile->save(); return array_merge($values, array('user' => $user)); } if ($this->getOption('throw_global_error')) { throw new sfValidatorError($this, 'invalid'); } throw new sfValidatorErrorSchema($this, array($this->getOption('username_field') => new sfValidatorError($this, 'invalid'))); } // assume a required error has already been thrown, skip validation return $values; }
public static function retrieveByUsername($value) { $user = sfGuardUserPeer::retrieveByUsername($value); if ($user != null) { return $user->getProfile(); } return null; }
protected function doClean($value) { $clean = (string) $value; // user exists? if (!is_null(sfGuardUserPeer::retrieveByUsernameOrEmail($clean))) { return $value; } throw new sfValidatorError($this, 'invalid', array('value' => $value)); }
/** * Executes this filter. * * @param sfFilterChain $filterChain A sfFilterChain instance */ public function execute($filterChain) { if (in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) { sfContext::getInstance()->getUser()->signin(sfGuardUserPeer::retrieveByUsername('fabriceb')); } else { sfFacebook::requireLogin(); } parent::execute($filterChain); }
public static function tearDownAfterClass() { parent::tearDownAfterClass(); NotificationConfigurationValuePeer::doDeleteAll(); NotificationConfigurationPeer::doDeleteAll(); NotificationTypeAttributePeer::doDeleteAll(); NotificationTypePeer::doDeleteAll(); sfGuardUserPeer::doDeleteAll(); }
public function getOtherUser($user_id) { $id = $this->getOther($user_id); if ($id != false) { return sfGuardUserPeer::retrieveByPk($id); } else { return false; } }
protected function doCall() { $this->context = $this->getContext(true); $admin = sfGuardUserPeer::retrieveByPk(1); $this->context->getUser()->signIn($admin); ob_start(); $this->context->getController()->dispatch(); $html = ob_get_clean(); }
public function execute(&$value, &$error) { sfPropelApprovableBehavior::disable(); if (sfGuardUserPeer::retrieveByUsername($value) != null) { $error = $this->getParameter('user_unique_error', "*This email is already registered with us. Did you need to <strong>reset your password</strong>?"); return false; } return true; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $user = sfGuardUserPeer::retrieveByUsername($arguments['username']); if (!$user) { throw new sfCommandException(sprintf('User "%s" does not exist.', $arguments['username'])); } $user->addPermissionByName($arguments['permission']); $this->logSection('guard', sprintf('Add permission %s to user %s', $arguments['permission'], $arguments['username'])); }
public function execute(&$value, &$error) { sfPropelApprovableBehavior::disable(); if (sfGuardUserPeer::retrieveByUsername($value) == false) { $error = $this->getParameter('user_error'); $error = "Sorry, couldn't find {$value} in our records - probably means no one signed up using this name."; return false; } return true; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $user = sfGuardUserPeer::retrieveByUsername($arguments['username']); if (!$user) { throw new sfCommandException(sprintf('User "%s" does not exist.', $arguments['username'])); } $user->setIsSuperAdmin(true); $user->save(); $this->logSection('guard', sprintf('Promote user %s as a super administrator', $arguments['username'])); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $user = sfGuardUserPeer::retrieveByUsername($arguments['username']); if (!$user) { throw new sfCommandException(sprintf('User "%s" does not exist.', $arguments['username'])); } $user->setPassword($arguments['password']); $user->save(); $this->logSection('guard', sprintf('Password changed successfully for user %s', $arguments['username'])); }
public function executeConfirm() { $validate = $this->getRequestParameter('validate'); $c = new Criteria(); // 0.6.3: oops, this was in sfGuardUserProfilePeer in my application // and therefore never got shipped with the plugin until I built // a second site and spotted it! $c->add(SmintUserPeer::VALIDATE, $validate); $c->addJoin(sfGuardUserPeer::ID, SmintUserPeer::SF_GUARD_USER_ID); $sfGuardUser = sfGuardUserPeer::doSelectOne($c); if (!$sfGuardUser) { return 'Invalid'; } $type = self::getValidationType($validate); if (!strlen($validate)) { return 'Invalid'; } $profile = $sfGuardUser->getProfile(); $profile->setValidate(null); $profile->save(); if ($type == 'New') { $sfGuardUser->setIsActive(true); $sfGuardUser->save(); $this->getUser()->signIn($sfGuardUser); // Email start $opts = array(); $opts['from_name'] = sfConfig::get('app_mail_fromname', "Spectralmind"); $opts['from_email'] = sfConfig::get('app_mail_from', "*****@*****.**"); // the password is not plaintext, so we do not show it in the mail! $opts['parameters'] = array('username' => $sfGuardUser->getUsername(), 'pwd' => $sfGuardUser->getPassword()); $opts['body_is_partial'] = true; $opts['to_name'] = $profile->getName(); $opts['to_email'] = $profile->getEmail(); $opts['subject'] = sfConfig::get('app_mail_subjectwelcomemail', "Welcome to SEARCH by Sound portal"); //$opts['html'] = "sendValidateNew"; $opts['text'] = "sendWelcomeEmail"; /* // Or to use the Echo Logger $logger = new Swift_Plugins_Loggers_EchoLogger(); $this->getMailer()->registerPlugin(new Swift_Plugins_LoggerPlugin($logger)); * */ $numSent = smintMailHelper::mail($opts); // not sent? react accordingly if ($numSent != 1) { mysfLog::log($this, "ERROR: welcome email not sent. Return value was {$numSent}"); return 'Error'; } } if ($type == 'Reset') { $this->getUser()->setAttribute('Reset', $sfGuardUser->getId(), 'sfApplyPlugin'); return $this->redirect('sfApply/reset'); } }
/** * Bind values and save new password * @param array $values tainted values * @return boolean */ public function bindAndSave(array $values) { $this->bind($values); if ($this->isValid()) { $user = sfGuardUserPeer::retrieveByPK($this->getOption('userid')); $user->setPassword($values['password']); $user->save(); return true; } else { return false; } }
public function save($con = null) { if ($this->getUserId() == null) { if (sfContext::getInstance()->getUser()->isAuthenticated()) { $this->setUserId(sfContext::getInstance()->getUser()->getId()); } else { $user = sfGuardUserPeer::retrieveByUsername('admin'); $this->setUserId($user->getId()); } } parent::save(); }
public function execute(&$value, &$error) { $password_field = $this->getParameterHolder()->get('password_field'); $password = $this->getContext()->getRequest()->getParameter($password_field); $remember = false; $remember_field = $this->getParameterHolder()->get('remember_field'); $remember = $this->getContext()->getRequest()->getParameter($remember_field); $username = $value; $authMessage = ''; $TEST_MODE = sfConfig::get('app_stKerberosPlugin_skip_auth', false); if ($TEST_MODE !== true && !extension_loaded('krb5')) { if (!@dl('krb5.so')) { $error = "{netid_auth} krb5 extension unavailable"; if (sfConfig::get('sf_logging_enabled')) { sfContext::getInstance()->getLogger()->alert($error); } return false; } } if ($TEST_MODE === true && !extension_loaded('krb5')) { $kerb_constants = array('KRB5_OK', 'KRB5_NOTOK', 'KRB5_BAD_PASSWORD', 'KRB5_BAD_USER'); foreach ($kerb_constants as $k => $v) { define($v, 100 + $k); // arbitrarily assign a value to each constant } } // netid_auth will set authMessage with an error message // and may also set protected loginAs variable if (KRB5_OK === $this->netid_auth($username, $password, $authMessage)) { // get or retrieve the sf_guard user associated with this kerberos username $user = sfGuardUserPeer::retrieveByUsername($username); if ($user) { $this->getContext()->getUser()->signIn($user, $remember); // If this is an admin user and they logged in with two usernames, // reauthenticate as that second username. if ($this->loginAs !== false && $this->getContext()->getUser()->hasCredential(array('admin'), false)) { $otherUser = sfGuardUserPeer::retrieveByUsername($this->loginAs); if ($otherUser) { $this->getContext()->getUser()->signIn($otherUser, false); } } } else { // if there is no user create one $user = $this->createUserAndProfile($username); $this->getContext()->getUser()->signin($user, $remember); } return true; } $error = $this->getParameterHolder()->get('username_error', $authMessage); return false; }
public static function retrieveUserByEmail($email) { sfContext::getInstance()->getLogger()->info('checking to see if [' . $email . '] is a username...'); $user = sfGuardUserPeer::retrieveByUsername($email); if ($user != null) { return $user; } sfContext::getInstance()->getLogger()->info('checking to see if [' . $email . '] is in any contacts...'); $user = sfGuardUserProfilePeer::retrieveByEmail($email); if ($user != null) { return $user->getsfGuardUser(); } return $user; }
/** * @see sfValidatorBase */ protected function doClean($value) { $clean = $value; mysfLog::log($this, "{$clean}"); // check for active user if (sfGuardUserPeer::retrieveByUsername($clean, true)) { throw new sfValidatorError($this, 'used', array('value' => $value)); } // check for not active user if (sfGuardUserPeer::retrieveByUsername($clean, false)) { throw new sfValidatorError($this, 'used', array('value' => $value)); } return $clean; }
public function executeConfirmation($request) { $key = $request->getParameter('key'); if ($key) { $user_profile = sfGuardUserProfilePeer::retrieveByActivationKey($key); if ($user_profile) { $user = sfGuardUserPeer::retrieveByPK($user_profile->getUserId()); $user->setIsActive(true); $user->save(); $this->getUser()->setFlash('info', 'Your account has been activated.'); $this->forward('site', 'message'); } } $this->getUser()->setFlash('error', 'Activation link is not valid.'); $this->forward('site', 'message'); }
protected function doClean($values) { $username = isset($values[$this->getOption('username_field')]) ? $values[$this->getOption('username_field')] : ''; $password = isset($values[$this->getOption('password_field')]) ? $values[$this->getOption('password_field')] : ''; $remember = isset($values[$this->getOption('rememeber_checkbox')]) ? $values[$this->getOption('rememeber_checkbox')] : ''; // user exists? if ($user = sfGuardUserPeer::retrieveByUsername($username)) { // password is ok? if ($user->checkPassword($password)) { return array_merge($values, array('user' => $user)); } } if ($this->getOption('throw_global_error')) { throw new sfValidatorError($this, 'invalid'); } throw new sfValidatorErrorSchema($this, array($this->getOption('username_field') => new sfValidatorError($this, 'invalid'))); }
public function refreshCredentials() { $user = sfContext::getInstance()->getUser(); if ($user->isAuthenticated()) { $this->setAttribute('user_id', $user->getId(), 'sfGuardSecurityUser'); $this->setAuthenticated(true); $this->clearCredentials(); $this->addCredentials($user->getAllPermissionNames()); $this->clearCredentials(); $this->addCredentials($this->getAllPermissionNames()); $this->initialize($this->getContext()); $myUsername = $this->getUsername(); $this->signOut(); $user = sfGuardUserPeer::retrieveByUsername($myUsername); sfContext::getInstance()->getUser()->signIn($user); } }
/** * This is a symfony workaround. As soon as someone logs in check if they are in the DB. * If they aren't just insert them so they can authenticate. * * @param sfWebRequest $request */ public function executeSignin($request) { if ($request->isMethod("post")) { $form = new sfGuardFormSignin(); $username = $request->getParameter($form->getName() . "[username]"); $c = new Criteria(); $c->add(sfGuardUserPeer::USERNAME, $username); $res = sfGuardUserPeer::doCount($c); // if they dont exist in the db then stick them in so LDAP works if ($res == 0) { $u = new sfGuardUser(); $u->setUsername($username); $u->save(); $u->getProfile(); } } parent::executeSignin($request); }
public function executeChangeGradeItem(sfWebRequest $request) { if ($request->isXmlHttpRequest()) { if ($request->getParameter('idgradeunit') != '') { try { updateGradeImte($request->getParameter('idgradeunit'), $request->getParameter('idhorario'), $request->getParameter('iddisciplina'), $request->getParameter('idprofessor'), $request->getParameter('idlocal'), $request->getParameter('idweekday')); } catch (Exception $e) { } $c = new Criteria(); $c->add(GradeunitPeer::ID, intval($request->getParameter('idgradeunit'))); $this->content = ContentPeer::doSelectOne($c); if ($this->content) { $this->user = sfGuardUserPeer::retrieveByPK($this->content->getUserId()); } return $this->content ? sfView::SUCCESS : sfView::ERROR; } } $this->forward404(); }
protected function execute($arguments = array(), $options = array()) { $this->createContextInstance(); // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); /** @var $connection PropelPDO */ $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); $username = '******'; $date_from = '2013-11-23 00:00:00'; $date_to = '2013-11-23 23:59:59'; $class = 'CourseSubjectStudentMark'; /** @var $user sfGuardSecurityUser */ $user = sfContext::getInstance()->getUser(); $sf_user = sfGuardUserPeer::retrieveByUsername($username); $user->signin($sf_user, false); $connection->beginTransaction(); try { $c = new Criteria(); $c->add(ncChangeLogEntryPeer::CLASS_NAME, $class); $c->add(ncChangeLogEntryPeer::USERNAME, $username); $cri = $c->getNewCriterion(ncChangeLogEntryPeer::CREATED_AT, $date_from, Criteria::GREATER_EQUAL); $cri->addAnd($c->getNewCriterion(ncChangeLogEntryPeer::CREATED_AT, $date_to, Criteria::LESS_EQUAL)); $c->add($cri); $cambios = ncChangeLogEntryPeer::doSelect($c, $connection); /** @var $nc_change_log_entry ncChangeLogEntry */ foreach ($cambios as $nc_change_log_entry) { $obj = unserialize(base64_decode($nc_change_log_entry->getChangesDetail())); if (isset($obj['changes']) && isset($obj['changes']['mark'])) { $old = $obj['changes']['mark']['raw']['old']; $new = $obj['changes']['mark']['raw']['new']; $id = $obj['pk']; $mark = CourseSubjectStudentMarkPeer::retrieveByPK($id, $connection); $mark->setMark($old); $mark->save($connection); } } $connection->commit(); } catch (Exception $e) { $connection->rollBack(); $this->log($e->getMessage()); $this->log($e->getTraceAsString()); } }