/** * Executes link action * * @param sfRequest $request A request object */ public function executeLink($request) { $this->redirectUnless(opConfig::get('enable_friend_link'), '@error'); $this->redirectIf($this->relation->isAccessBlocked(), '@error'); if ($this->relation->isFriend()) { $this->getUser()->setFlash('error', 'This member already belongs to %my_friend%.'); $this->getUser()->setFlash('error_params', array('%my_friend%' => Doctrine::getTable('SnsTerm')->get('my_friend')->pluralize())); $this->redirect('member/profile?id=' . $this->id); } if ($this->relation->isFriendPreFrom()) { $this->getUser()->setFlash('error', '%Friend% request is already sent.'); $this->redirect('member/profile?id=' . $this->id); } $this->form = new FriendLinkForm(); if ($request->isMethod(sfWebRequest::POST)) { $this->form->bind($request->getParameter('friend_link')); if ($this->form->isValid()) { $this->getUser()->setFlash('notice', 'You have requested %friend% link.'); $this->redirectToHomeIfIdIsNotValid(); $this->relation->setFriendPre(); $this->dispatcher->notify(new sfEvent($this, 'op_action.post_execute_' . $this->moduleName . '_' . $this->actionName, array('moduleName' => $this->moduleName, 'actionName' => $this->actionName, 'actionInstance' => $this, 'result' => sfView::SUCCESS))); $this->redirect('member/profile?id=' . $this->id); } } $this->member = Doctrine::getTable('Member')->find($this->id); return sfView::INPUT; }
/** * Executes feedback action * */ public function executeFeedback(sfRequest $request) { $section = $request->getParameter('section', false); $this->form = new aFeedbackForm($section); $this->feedbackSubmittedBy = false; $this->failed = false; sfContext::getInstance()->getConfiguration()->loadHelpers(array('Tag', 'Url')); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('feedback'), $request->getFiles('feedback')); // $this->form->bind(array_merge($request->getParameter('feedback'), array('captcha' => $request->getParameter('captcha'))), $request->getFiles('feedback')); if ($this->form->isValid()) { $feedback = $this->form->getValues(); $feedback['browser'] = $_SERVER['HTTP_USER_AGENT']; try { aZendSearch::registerZend(); $mail = new Zend_Mail(); $mail->setBodyText($this->getPartial('feedbackEmailText', array('feedback' => $feedback)))->setFrom($feedback['email'], $feedback['name'])->addTo(sfConfig::get('app_aFeedback_email_auto'))->setSubject($this->form->getValue('subject', 'New aBugReport submission')); if ($screenshot = $this->form->getValue('screenshot')) { $mail->createAttachment(file_get_contents($screenshot->getTempName()), $screenshot->getType()); } $mail->send(); // A new form for a new submission $this->form = new aFeedbackForm(); } catch (Exception $e) { $this->logMessage('Request email failed: ' . $e->getMessage(), 'err'); $this->failed = true; return 'Success'; } $this->getUser()->setFlash('reportSubmittedBy', $feedback['name']); $this->redirect($feedback['section']); } } }
/** * Executes configUID action * * @param sfRequest $request A request object */ public function executeConfigUID($request) { $option = array('member' => $this->getUser()->getMember()); $this->passwordForm = new sfOpenPNEPasswordForm(array(), $option); $mobileUid = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId('mobile_uid', $this->getUser()->getMemberId()); $this->isSetMobileUid = !is_null($mobileUid); $this->isDeletableUid = (int) opConfig::get('retrieve_uid') < 2 && $this->isSetMobileUid; if ($request->isMethod('post')) { $this->passwordForm->bind($request->getParameter('password')); if ($this->passwordForm->isValid()) { if ($request->hasParameter('update')) { $memberConfig = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId('mobile_uid', $this->getUser()->getMemberId()); if (!$memberConfig) { $memberConfig = new MemberConfig(); $memberConfig->setMember($this->getUser()->getMember()); $memberConfig->setName('mobile_uid'); } $memberConfig->setValue($request->getMobileUID()); $memberConfig->save(); $this->getUser()->setFlash('notice', 'Your mobile UID was set successfully.'); $this->redirect('member/configUID'); } elseif ($request->hasParameter('delete') && $this->isDeletableUid) { $mobileUid->delete(); $this->getUser()->setFlash('notice', 'Your mobile UID was deleted successfully.'); $this->redirect('member/configUID'); } } } return sfView::SUCCESS; }
/** * Executes login action * * * @param sfRequest $request A request object */ public function executeLogin($request) { $this->form = new LoginForm(); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('login')); if ($this->form->isValid()) { $this->redirect('@homepage'); } } }
public function executeApply(sfRequest $request) { //If user is logged in, we're forwarding him to settings page from apply $this->forwardIf($this->getUser()->isAuthenticated(), 'sfApply', 'settings'); // we're getting default or customized applyForm for the task if (!($this->form = $this->newForm('applyForm')) instanceof sfGuardUserProfileForm) { // if the form isn't instance of sfApplyApplyForm, we don't accept it throw new InvalidArgumentException('The custom apply form should be instance of sfApplyApplyForm'); } //Code below is used when user is sending his application! if ($request->isMethod('post')) { //gathering form request in one array $formValues = $request->getParameter($this->form->getName()); if (sfConfig::get('app_recaptcha_enabled')) { $captcha = array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field')); //Adding captcha to form array $formValues = array_merge($formValues, array('captcha' => $captcha)); } //binding request form parameters with form $this->form->bind($formValues, $request->getFiles($this->form->getName())); if ($this->form->isValid()) { $guid = "n" . self::createGuid(); $this->form->getObject()->setValidate($guid); $date = new DateTime(); $this->form->getObject()->setValidateAt($date->format('Y-m-d H:i:s')); $this->form->save(); $confirmation = sfConfig::get('app_sfForkedApply_confirmation'); if ($confirmation['apply']) { try { //Extracting object and sending creating verification mail $profile = $this->form->getObject(); $this->sendVerificationMail($profile); return 'After'; } catch (Exception $e) { //Cleaning after possible exception thrown in ::sendVerificationMail() method $profile = $this->form->getObject(); $user = $profile->getUser(); $profile->delete(); $user->delete(); //We rethrow exception for the dev environment. This catch //catches other than mailer exception, i18n as well. So developer //now knows what he's up to. if (sfContext::getInstance()->getConfiguration()->getEnvironment() === 'dev') { throw $e; } return 'MailerError'; } } else { $this->activateUser($this->form->getObject()->getUser()); $this->getUser()->setFlash('notice', "<h3>Поздравляем с успешной регистрацией!</h3>\n\n <p>Теперь Вы можете пользоваться всеми возможностями сервиса:</p>\n <ul>\n <li>Добавлять новые места</li>\n <li>Добавлять отчеты</li>\n <li>Добавлять события</li>\n <li>Открывать обсуждения</li>\n <li>Голосовать комментировать и все подряд</li>\n <li>Заводить друзей</li>\n <li>И многое другое...</li>\n </ul>"); return $this->redirect('@homepage'); } } } }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex($request) { $this->form = new reCaptchaForm(); if ($request->isMethod('post')) { $requestData = array('challenge' => $this->getRequestParameter('recaptcha_challenge_field'), 'response' => $this->getRequestParameter('recaptcha_response_field')); $this->form->bind($requestData); if ($this->form->isValid()) { // captcha is valid } } }
/** * * @param sfRequest $request */ public function execute($request) { $this->setForm(new BeaconRegistrationForm()); if ($request->isMethod('post')) { $this->form->bind($request->getParameter($this->form->getName())); if ($this->form->isValid()) { $result = $this->form->save(); $this->getUser()->setFlash($result['messageType'], $result['message']); } } }
/** * Executes deleteLeaveType action * * @param sfRequest $request A request object */ public function execute($request) { if ($request->isMethod('post')) { if (count($request->getParameter('chkSelectRow')) == 0) { $this->getUser()->setFlash('notice', __(TopLevelMessages::SELECT_RECORDS)); } else { $leaveTypeService = $this->getLeaveTypeService(); $leaveTypeIds = $request->getParameter('chkSelectRow'); $leaveTypeService->deleteLeaveType($leaveTypeIds); $this->getUser()->setFlash('success', __(TopLevelMessages::DELETE_SUCCESS)); } $this->redirect('leave/leaveTypeList'); } }
/** * Executes this action * * @param sfRequest $request A request object */ public function execute($request) { $this->getUser()->setAuthenticated(false); $this->form = new opAdminLoginForm(); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('admin_user')); if ($this->form->isValid()) { $this->getUser()->login($this->form->getValue('adminUser')->getId()); $this->redirect('default/top'); } return sfView::ERROR; } return sfView::SUCCESS; }
/** * Executes deleteLeaveType action * * @param sfRequest $request A request object */ public function execute($request) { $this->leaveTypePermissions = $this->getDataGroupPermissions('leave_types'); if ($request->isMethod('post')) { if (count($request->getParameter('chkSelectRow')) == 0) { $this->getUser()->setFlash('notice', __(TopLevelMessages::SELECT_RECORDS)); } else { if ($this->leaveTypePermissions->canDelete()) { $form = new DefaultListForm(array(), array(), true); $form->bind($request->getParameter($form->getName())); if ($form->isValid()) { $leaveTypeService = $this->getLeaveTypeService(); $leaveTypeIds = $request->getParameter('chkSelectRow'); $leaveTypeService->deleteLeaveType($leaveTypeIds); $this->getUser()->setFlash('success', __(TopLevelMessages::DELETE_SUCCESS)); } } } $this->redirect('leave/leaveTypeList'); } }
/** * Авторизация пользователя */ public function executeLogin(sfRequest $request) { $this->setLayout("layout"); $user = $this->getUser(); if ($user->isAuthenticated()) { return $this->redirect('@homepage'); } // Запрос на авторизацию if ($request->isMethod('post')) { $this->form = new myAuthForm(); $params = $request->getPostParameters(); $this->form->bind($params['auth']); if ($this->form->isValid()) { $values = $this->form->getValues(); $remember = array_key_exists('remember', $values) ? $values['remember'] : false; $user->signIn($this->form->getUser(), $remember); return $this->redirect('@homepage'); } // Форвард из других контроллеров } else { $this->form = new myAuthForm(); } return sfView::SUCCESS; }
/** * Авторизация пользователя / сообщение о неавторизованности */ public function executeLogin(sfRequest $request) { $this->setLayout("layout"); $user = $this->getUser(); if (!$user->isAuthenticated()) { if ($request->isMethod('post')) { $form = new myAuthForm(); $form->bind($request->getPostParameters()); if ($form->isValid()) { $userRecord = $form->getUser(); } else { return $this->raiseError($form->getErrorSchema()); } } else { return $this->raiseError('Authentification required'); } $user->signIn($userRecord); } if (!$this->checkSubscription()) { $user->signOut(); return $this->raiseError('Payment required', 402); } return sfView::SUCCESS; }
/** * Executes dropMember action * * @param sfRequest $request A request object */ public function executeDropMember($request) { $this->redirectUnless($this->isAdmin || $this->isSubAdmin, '@error'); $member = Doctrine::getTable('Member')->find($request->getParameter('member_id')); $this->forward404Unless($member); $isCommunityMember = Doctrine::getTable('CommunityMember')->isMember($member->getId(), $this->id); $this->redirectUnless($isCommunityMember, '@error'); $isAdmin = Doctrine::getTable('CommunityMember')->isAdmin($member->getId(), $this->id); $isSubAdmin = Doctrine::getTable('CommunityMember')->isSubAdmin($member->getId(), $this->id); $this->redirectIf($isAdmin || $isSubAdmin, '@error'); if ($request->isMethod(sfWebRequest::POST)) { $request->checkCSRFProtection(); Doctrine::getTable('CommunityMember')->quit($member->getId(), $this->id); $this->redirect('@community_memberManage?id=' . $this->id); } $this->member = $member; $this->community = Doctrine::getTable('Community')->find($this->id); return sfView::INPUT; }
/** * Executes apply action * * @param sfRequest $request A request object */ public function executeApply(sfRequest $request) { $this->form = $this->newForm('sfApplyApplyForm'); if ($request->isMethod('post')) { $parameter = $request->getParameter('sfApplyApply'); $this->form->bind($request->getParameter('sfApplyApply')); if ($this->form->isValid()) { $guid = "n" . self::createGuid(); $this->form->setValidate($guid); $this->form->save(); // Generate unique token based on random time list($usec, $sec) = explode(" ", microtime()); $rand_num = substr(sha1((int) ($usec * 1000000 * ($sec / 1000000))), 0, 20); // Retrieve current user $user = $this->form->getObject(); $now = date("Y-m-d H:i:s"); // Create new entry into sfGuardUserProfile table $profileObject = new sfGuardUserProfile(); $profileObject->setUserId($user->getId()); $profileObject->setToken($rand_num); $profileObject->setSecurityLevel(sfConfig::get('app_security_level_new_user')); $userPermission = Doctrine_Core::getTable("sfGuardPermission")->findOneByName(sfConfig::get('app_permission_new_user')); if (empty($userPermission)) { return; } // Create new entry into sfGuardUserPermission table $permissionObject = new sfGuardUserPermission(); $permissionObject->setUserId($user->getId()); $permissionObject->setPermissionId($userPermission->getId()); $permissionObject->setCreatedAt($now); $permissionObject->setUpdatedAt($now); $userGroup = Doctrine_Core::getTable("sfGuardGroup")->findOneByName(sfConfig::get('app_project_group')); if (empty($userGroup)) { return; } // Create new entry into sfGuardUserGroup table $groupObject = new sfGuardUserGroup(); $groupObject->setUserId($user->getId()); $groupObject->setGroupId($userGroup->getId()); $groupObject->setCreatedAt($now); $groupObject->setUpdatedAt($now); try { // Send mail $this->sendVerificationMail($user); // Save tables entries $profileObject->save(); $permissionObject->save(); $groupObject->save(); return 'After'; } catch (Exception $e) { $groupObject->delete(); $permissionObject->delete(); $profileObject->delete(); $user->delete(); throw $e; // You could re-throw $e here if you want to // make it available for debugging purposes return 'MailerError'; } } } }
/** * Executes configImage action * * @param sfRequest $request A request object */ public function executeConfigImage($request) { $options = array('member' => $this->getUser()->getMember()); $this->form = new MemberImageForm(array(), $options); if ($request->isMethod(sfWebRequest::POST)) { try { if (!$this->form->bindAndSave($request->getParameter('member_image'), $request->getFiles('member_image'))) { $errors = $this->form->getErrorSchema()->getErrors(); if (isset($errors['file'])) { $error = $errors['file']; $i18n = $this->getContext()->getI18N(); $this->getUser()->setFlash('error', $i18n->__($error->getMessageFormat(), $error->getArguments())); } } } catch (opRuntimeException $e) { $this->getUser()->setFlash('error', $e->getMessage()); } $this->redirect('@member_config_image'); } }
/** * Executes delete action * * @param sfRequest $request A request object */ public function executeDelete($request) { switch ($request->getParameter('target')) { case 'friend': $fromId = $this->id; $toId = $this->getUser()->getMemberId(); break; case 'my': default: $fromId = $this->getUser()->getMemberId(); $toId = $this->id; break; } $this->introFriend = Doctrine::getTable('IntroFriend')->getByFromAndTo($fromId, $toId); $this->forward404Unless($this->introFriend); // return uri switch ($request->getParameter('from')) { case 'list': $this->uri = $this->getController()->genUrl('@obj_introfriend?id='.$toId); break; case 'manage': default: $this->uri = $this->getController()->genUrl('@friend_manage'); } // delete if ($request->isMethod('post')) { $request->checkCSRFProtection(); $this->introFriend->delete(); $this->getUser()->setFlash('notice', 'The introductory essay was deleted.'); $this->redirect($this->uri); } }
public function executeSettings(sfRequest $request) { // sfApplySettingsForm inherits from sfApplyApplyForm, which // inherits from sfGuardUserForm while disallowing the standard // sfGuardUser fields except for first name and last name. // That minimizes the amount of duplication of effort. If you want, you can use a different // form class. I suggest inheriting from sfApplySettingsForm and // making further changes after calling parent::configure() from // your own configure() method. if (!$this->getUser()->isAuthenticated()) { return $this->redirect('@homepage'); } $this->form = $this->newForm('sfApplySettingsForm', $this->getUser()->getGuardUser()); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('sfApplySettings')); if ($this->form->isValid()) { $this->form->save(); return $this->redirect('@homepage'); } } }
public function executeEditEmail(sfRequest $request) { $this->forward404Unless(sfConfig::get('app_sfForkedApply_mail_editable')); if (!($this->form = $this->newForm('editEmailForm')) instanceof sfApplyEditEmailForm) { // if the form isn't instance of sfApplySettingsForm, we don't accept it throw new InvalidArgumentException(sfContext::getInstance()->getI18N()->__('The custom %action% form should be instance of %form%', array('%action%' => 'editEmail', '%form%' => 'sfApplyEditEmailForm'), 'sfForkedApply')); } if ($request->isMethod('post')) { $this->form->bind($request->getParameter($this->form->getName())); if ($this->form->isValid()) { $profile = $this->getUser()->getGuardUser()->getProfile(); $confirmation = sfConfig::get('app_sfForkedApply_confirmation'); if ($confirmation['email']) { $profile->setEmailNew($this->form->getValue('email')); $profile->setValidate('e' . self::createGuid()); $date = new DateTime(); $profile->setValidateAt($date->format('Y-m-d H:i:s')); $profile->save(); $this->mail(array('subject' => sfConfig::get('app_sfForkedApply_apply_subject', sfConfig::get('app_sfApplyPlugin_apply_subject', sfContext::getInstance()->getI18N()->__("Please verify your email on %1%", array('%1%' => $this->getRequest()->getHost()), 'sfForkedApply'))), 'fullname' => $profile->getFullname(), 'email' => $profile->getUser()->getEmailAddress(), 'parameters' => array('username' => $profile->getUser()->getUsername(), 'validate' => $profile->getValidate(), 'oldmail' => $profile->getUser()->getEmailAddress(), 'newmail' => $profile->getEmailNew()), 'text' => 'sfApply/sendValidateEmailText', 'html' => 'sfApply/sendValidateEmail')); $this->getUser()->setFlash('sf_forked_apply', sfContext::getInstance()->getI18N()->__('To complete email change, follow a link included in a confirmation email we have sent to your old email address: %OLDEMAIL%.', array('%OLDEMAIL%' => $profile->getUser()->getEmailAddress()), 'sfForkedApply')); } else { $profile->getUser()->setEmailAddress($this->form->getValue('email')); $profile->save(); $this->getUser()->setFlash('sf_forked_apply', sfContext::getInstance()->getI18N()->__('Your email has been changed.', array(), 'sfForkedApply')); } return $this->redirect('@settings'); } } }
public function executeResetRequest(sfRequest $request) { $user = $this->getUser(); if ($user->isAuthenticated()) { $guardUser = $this->getUser()->getGuardUser(); $this->forward404Unless($guardUser); return $this->resetRequestBody($guardUser); } else { $this->form = $this->newForm('sfApplyResetRequestForm'); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('sfApplyResetRequest')); if ($this->form->isValid()) { // The form matches unverified users, but retrieveByUsername does not, so // use an explicit query. We'll special-case the unverified users in // resetRequestBody $username_or_email = $this->form->getValue('username_or_email'); if (strpos($username_or_email, '@') !== false) { $user = Doctrine::getTable('sfGuardUser')->createQuery('u')->where('u.email_address = ?', $username_or_email)->fetchOne(); } else { $user = Doctrine::getTable('sfGuardUser')->createQuery('u')->where('username = ?', $username_or_email)->fetchOne(); } return $this->resetRequestBody($user); } } } }
/** * Executes unlink action * * @param sfRequest $request A request object */ public function executeUnlink($request) { $this->redirectToHomeIfIdIsNotValid(); if (!$this->relation->isFriend()) { $this->getUser()->setFlash('error', 'This member is not your %friend%.'); $this->redirect('friend/manage'); } if ($request->isMethod(sfWebRequest::POST)) { $request->checkCSRFProtection(); $this->relation->removeFriend(); $this->redirect('friend/manage'); } $this->member = Doctrine::getTable('Member')->find($this->id); return sfView::INPUT; }
/** * Executes delete action * * @param sfRequest $request A request object */ public function executeDelete($request) { if (1 == $this->getUser()->getMemberId()) { return sfView::ERROR; } $this->form = new sfOpenPNEPasswordForm(array(), array('member' => $this->getUser()->getMember())); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('password')); if ($this->form->isValid()) { $member = $this->getUser()->getMember(); $this->getUser()->getMember()->delete(); $this->sendDeleteAccountMail($member); $this->getUser()->setFlash('notice', '退会が完了しました'); $this->getUser()->logout(); $this->redirect('member/login'); } } return sfView::INPUT; }
public function executeUploadImages(sfRequest $request) { // Belongs at the beginning, not the end $this->forward404Unless(aMediaTools::userHasUploadPrivilege()); $this->form = new aMediaUploadImagesForm(); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('a_media_items'), $request->getFiles('a_media_items')); if ($this->form->isValid()) { $request->setParameter('first_pass', true); $active = array(); // Saving embedded forms is weird. We can get the form objects // via getEmbeddedForms(), but those objects were never really // bound, so getValue will fail on them. We have to look at the // values array of the parent form instead. The widgets and // validators of the embedded forms are rolled into it. // See: // http://thatsquality.com/articles/can-the-symfony-forms-framework-be-domesticated-a-simple-todo-list for ($i = 0; $i < aMediaTools::getOption('batch_max'); $i++) { $values = $this->form->getValues(); if ($values["item-{$i}"]['file']) { $active[] = $i; } else { // So the editImagesForm validator won't complain about these $items = $request->getParameter("a_media_items"); unset($items["item-{$i}"]); $request->setParameter("a_media_items", $items); } } $request->setParameter('active', implode(",", $active)); // We'd like to just do this... // $this->forward('aMedia', 'editImages'); // But we need to break out of the iframe, and // modern browsers ignore Window-target: _top which // would otherwise be perfect for this. // Fortunately, the persistent file upload widget can tolerate // a GET-method redirect very nicely as long as we pass the // persistids. So we make the current parameters available // to a template that breaks out of the iframe via // JavaScript and passes the prameters on. $this->parameters = $request->getParameterHolder('a_media_items')->getAll(); // If I don't do this I just get redirected back to myself unset($this->parameters['module']); unset($this->parameters['action']); return 'Redirect'; } } }
public function executeSettings(sfRequest $request) { // sfApplySettingsForm inherits from sfApplyApplyForm, which // inherits from sfGuardUserProfile. That minimizes the amount // of duplication of effort. If you want, you can use a different // form class. I suggest inheriting from sfApplySettingsForm and // making further changes after calling parent::configure() from // your own configure() method. $profile = $this->getUser()->getProfile(); $this->form = $this->newForm('sfApplySettingsForm', $profile); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('sfApplySettings'), $request->getFiles('sfApplySettings')); if ($this->form->isValid()) { $this->form->save(); return $this->redirect('people/show?username=' . $this->getUser()->getUsername()); } } }
/** * Executes deleteOption action * * @param sfRequest $request A request object */ public function executeDeleteOption($request) { $this->profileOption = Doctrine::getTable('ProfileOption')->find($request->getParameter('id')); $this->forward404Unless($this->profileOption); if ($request->isMethod('post')) { $request->checkCSRFProtection(); $this->profileOption->delete(); } $this->redirect('profile/list'); }