/** * Sets a single PcPasswordResetToken object as related to this object by a one-to-one relationship. * * @param PcPasswordResetToken $l PcPasswordResetToken * @return PcUser The current object (for fluent API support) * @throws PropelException */ public function setPcPasswordResetToken(PcPasswordResetToken $v) { $this->singlePcPasswordResetToken = $v; // Make sure that that the passed-in PcPasswordResetToken isn't already associated with this object if ($v->getPcUser() === null) { $v->setPcUser($this); } return $this; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param PcPasswordResetToken $value A PcPasswordResetToken object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(PcPasswordResetToken $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getUserId(); } // if key === null self::$instances[$key] = $obj; } }
/** * Sends an email to reset the password. * At this point we should be already sure the email address is valid * * @param string $email - the email address */ public static function sendPasswordForgotten($email) { $requestingUser = PcUserPeer::getUserByEmail($email); if (!is_object($requestingUser)) { throw new Exception('Couldn\'t send the password forgotten email. Problems while creating the user object.'); } // I need to use a token $token = ''; $c = new Criteria(); $c->add(PcPasswordResetTokenPeer::USER_ID, $requestingUser->getId(), Criteria::EQUAL); $tokenEntry = PcPasswordResetTokenPeer::doSelectOne($c); if (is_object($tokenEntry)) { $token = $tokenEntry->getToken(); } else { $secret = sfConfig::get('app_forgottenPassword_secret'); // token doesn't need to be 32-char long. It is better to keep it short // so there will be less chance the email client will break the link into 2 lines $token = substr(md5($requestingUser->getId() . $secret . time()), 0, 14); $tokenEntry = new PcPasswordResetToken(); $tokenEntry->setUserId($requestingUser->getId()); $tokenEntry->setToken($token); $tokenEntry->save(); } // now we can send the email $link = sfContext::getInstance()->getController()->genUrl('@password-reset?t=' . $token, true); $from = sfConfig::get('app_emailAddress_contact'); $subject = __('WEBSITE_FORGOTTEN_PSW_EMAIL_SUBJECT'); $body = sprintf(__('WEBSITE_FORGOTTEN_PSW_EMAIL_BODY'), $link); PcUtils::sendEmail($email, $subject, $body, $from); }