public function executeAddEdit(sfWebRequest $request) { $op = $request->getParameter('op'); $contextId = $request->getParameter('id'); $contextName = trim($request->getParameter('name')); $newContext = null; if ($contextName && strpos($contextName, ' ') !== FALSE) { die("ERROR: " . __('ACCOUNT_ERROR_TAG_CANT_HAVE_SPACE')); } $existingContexts = PcUserPeer::getLoggedInUser()->getContextsArray(true); if (count($existingContexts)) { if (in_array(strtolower($contextName), $existingContexts)) { die("ERROR: " . __('ACCOUNT_ERROR_TAG_ALREADY_EXIST')); } } if ($op == 'delete' && $contextId) { $contextToDelete = PcUsersContextsPeer::retrieveByPk($contextId); PcUtils::checkLoggedInUserPermission(PcUserPeer::retrieveByPk($contextToDelete->getUserId())); $contextToDelete->delete(); } else { if ($op == 'edit' && $contextId && $contextName) { $contextToEdit = PcUsersContextsPeer::retrieveByPk($contextId); PcUtils::checkLoggedInUserPermission(PcUserPeer::retrieveByPk($contextToEdit->getUserId())); $contextToEdit->setContext($contextName)->save(); // {{{ // this lines to make sure the list details we sent back via AJAX // are the ones stored in the database $contextToEdit = PcUsersContextsPeer::retrieveByPk($contextId); // }}} } else { if ($op == 'add' && $contextName) { // getting max sortOrder $c = new Criteria(); $c->addDescendingOrderByColumn(PcUsersContextsPeer::SORT_ORDER); $maxSortOrder = PcUsersContextsPeer::doSelectOne($c)->getSortOrder(); $context = new PcUsersContexts(); $context->setContext($contextName)->setPcUser(PcUserPeer::getLoggedInUser())->setSortOrder($maxSortOrder + 1)->save(); // {{{ // this lines to make sure the list details we sent back via AJAX // are the ones stored in the database $newContext = PcUsersContextsPeer::retrieveByPk($context->getId()); // }}} } } } $tag = isset($contextToEdit) && $contextToEdit ? $contextToEdit : $newContext; if ($request->isXmlHttpRequest()) { if ($tag) { $ret = array('id' => $tag->getId(), 'name' => $tag->getContext()); return $this->renderJson($ret); } else { return $this->renderDefault(); } } }
/** * Automatically logs users in who have a valid rememberme cookie * * @param $filterChain */ public function execute($filterChain) { if ($this->getContext()->getUser()->isAuthenticated()) { return $filterChain->execute(); } if ($this->isFirstCall()) { if ($userId = CustomAuth::isRememberMeCookieValid()) { $userToLogin = PcUserPeer::retrieveByPk($userId); CustomAuth::login($this->getContext()->getUser(), $userToLogin, true, true); } } $filterChain->execute(); }
/** * Returns the user who is logged in * N.B.: if there isn't actually any user logged in, it redirects to login page * so you must not use it just to check whether the user is logged in or not. * * @return PcUser */ public static function getLoggedInUser() { if (is_object(self::$loggedInUser)) { return self::$loggedInUser; } $userid = sfContext::getInstance()->getUser()->getAttribute('userid'); if (!$userid) { // header('Location: /login'); self::$loggedInUser = null; } self::$loggedInUser = PcUserPeer::retrieveByPk($userid); return self::$loggedInUser; }
/** * Get the associated PcUser object * * @param PropelPDO Optional Connection object. * @return PcUser The associated PcUser object. * @throws PropelException */ public function getPcUser(PropelPDO $con = null) { if ($this->aPcUser === null && $this->creator_id !== null) { $this->aPcUser = PcUserPeer::retrieveByPk($this->creator_id); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aPcUser->addPcContactNotes($this); */ } return $this->aPcUser; }
/** * Get the associated PcUser object * * @param PropelPDO Optional Connection object. * @return PcUser The associated PcUser object. * @throws PropelException */ public function getPcUser(PropelPDO $con = null) { if ($this->aPcUser === null && $this->user_id !== null) { $this->aPcUser = PcUserPeer::retrieveByPk($this->user_id); // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association. $this->aPcUser->setPcSupporter($this); } return $this->aPcUser; }
/** * @see sfTask */ protected function executeTask($env, $arguments = array(), $options = array()) { /** * Getting the directory where the emails are stored */ $inboxUser = sfConfig::get('app_emailToInbox_inboxUser'); $emailDomain = sfConfig::get('app_emailToInbox_mailServerDomain'); $newEmailPath = $arguments['emailFileAbsolutePath']; // there are some regular Plancake inbox email address that are // use just for spam $spamAccounts = array(); $spamAccounts[] = 'niki_5436'; // this will be interpreted as inbox_niki_5436@plancakebox.com $spamAccounts[] = 'niki.jones_15c522'; $this->log(''); $this->log(''); $this->log("parsing the email at " . $newEmailPath); $mailParser = new PlancakeEmailParser(file_get_contents($newEmailPath)); $plancakeSubjectOK = false; $plancakeRecipientOK = false; $emailTo = array(); $emailSubject = ''; $emailCc = $mailParser->getCc(); try { $emailTo = $mailParser->getTo(); } catch (Exception $e) { $this->handleFault("couldn't retrieve the 'to' header of the email", $newEmailPath); return; } try { $emailSubject = $mailParser->getSubject(); $plancakeSubjectOK = true; $this->log("got the subject of the email: " . $emailSubject); } catch (Exception $e) { $this->handleFault("couldn't retrieve the subject of the email", $newEmailPath); return; } $emailRecipients = array_merge($emailTo, $emailCc); $emailRecipients = implode(', ', $emailRecipients); $deliveredToHeader = $mailParser->getHeader('Delivered-To'); $emailRecipients = $deliveredToHeader . ', ' . $emailRecipients; $this->log("all recipients of the email: " . $emailRecipients); $internalEmail = false; // to flag an email sent to the catchall address $spamEmail = false; if (preg_match('/' . $inboxUser . "@{$emailDomain}/", $emailRecipients, $matches)) { $internalEmail = true; $this->log("discarding the email as it is an internal one"); if (is_file($newEmailPath)) { unlink($newEmailPath); } return; } if (preg_match("/inbox_([^@]+)@{$emailDomain}/i", $emailRecipients, $matches)) { // found Plancake Inbox address! $plancakeInbox = $matches[1]; if (in_array($plancakeInbox, $spamAccounts)) { $spamEmail = true; $this->handleFault("discarding the email because it is from a spammer", $newEmailPath); return; } else { $emailRecipient = 'inbox_' . $plancakeInbox . "@{$emailDomain}"; $plancakeRecipientOK = true; $this->log("got the Plancake recipient of the email: " . $emailRecipient); } } else { $this->handleFault("couldn't find a Plancake recipient for the email", $newEmailPath); return; } /** * Sorting the email into the database */ if ($plancakeRecipientOK && $plancakeSubjectOK) { $this->log('well done. For this email we got both the recipient and the subject. I can now create the task for the user.'); $emailRecipientWithoutDomain = str_replace("@{$emailDomain}", '', $emailRecipient); $c = new Criteria(); $c->add(PcPlancakeEmailAddressPeer::EMAIL, $emailRecipientWithoutDomain, Criteria::EQUAL); $plancakeEmail = PcPlancakeEmailAddressPeer::doSelectOne($c); if (is_object($plancakeEmail)) { // everything's OK $userId = $plancakeEmail->getUserId(); $user = PcUserPeer::retrieveByPk($userId); PcUserPeer::setLoggedInUser($user); // check whether there is a note for the task $note = $this->extractNote($mailParser->getPlainBody()); if (strlen($note)) { $this->log("note: {$note}"); } if (!strlen($emailSubject)) { $emailSubject = 'Something went wrong with a task you sent via email. Please contact us.'; } PcTaskPeer::createOrEdit($emailSubject, $user->getInbox()->getId(), 0, '', false, $note); $this->log('the email has successfully become a task for the user.'); } else { // something wrong $this->handleFault('no email user', $newEmailPath); $this->log('couldn\'t create a task from the email - the Plancake address is not in the system :-(.'); } } else { if ((!$plancakeRecipientOK || !$plancakeSubjectOK) && !$internalEmail && !$spamEmail) { // something wrong $this->handleFault('email parsing', $newEmailPath); $this->log("counldn't find both the recipient and the subject of the email. Nothing to do."); } } $this->log("deleting the email from the hard disk."); if (is_file($newEmailPath)) { unlink($newEmailPath); } $this->log(''); $this->log(''); }
/** * Takes care after the user resets their password succcessfully * * @param string $token * @param string $password - the new password to set (plain password) * @return PcUser - the user who has reset their own password */ public static function resetPassword($token, $password) { $c = new Criteria(); $c->add(PcPasswordResetTokenPeer::TOKEN, $token, Criteria::EQUAL); $tokenEntry = PcPasswordResetTokenPeer::doSelectOne($c); $userId = $tokenEntry->getUserId(); $tokenEntry->delete(); $sfContext = sfContext::getInstance(); $user = PcUserPeer::retrieveByPk($userId); $user->setPassword($password); $user->save(); self::login($sfContext->getUser(), $user); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent('userSetPassword', 'user.set_password', array('user' => $user, 'plainPassword' => $password))); return $user; }