/** * Sends new password to the requester * Can retrieve via Username or MemberId * @param sfWebRequest $request */ public function executeSendPassword(sfWebRequest $request) { if ($request->isMethod('post')) { $request->checkCSRFProtection(); $username = $request->getParameter('username'); $member_id = $request->getParameter('member_id'); if (strlen($username) > 0 || strlen($member_id) > 0) { $person = null; if ($member_id) { $member = MemberPeer::retrieveByPK($member_id); if ($member instanceof Member) { $person = $member->getPerson(); } } elseif ($username) { $person = PersonPeer::getByUsername($username); } if ($person instanceof Person) { # create token for password request $pr = new PasswordRequest(); $pr->setPerson($person); $pr->setEmail($person->getEmail()); $pr->save(); if ($person->getEmail()) { # send email via component $this->getComponent('mail', 'sendPassword', array('person' => $person, 'token' => $pr->getToken())); $this->getUser()->setFlash('success', 'Your password request has been successfully sent to your email!'); } else { $this->getUser()->setFlash('success', 'This user doesn\'t have proper email address!'); } # redirect to login $this->redirect('secure/login'); } $this->error_msg = 'Sorry! We haven\'t found any matching record!'; } else { $this->error_msg = 'Please type your username OR member id!'; } } $this->executeForgotPassword($request); $this->setTemplate('forgotPassword'); }
/** * 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 PasswordRequest $value A PasswordRequest object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(PasswordRequest $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
/** * @fn request_password * @short Action method to send a new password to a registered user. */ function request_password() { if (!Antispam::check_math()) { $this->flash(Antispam::random_comment(), 'error'); $this->redirect_to(array('action' => 'lost_password')); } $user_factory = new User(); $users = $user_factory->find_all(array('where_clause' => "`email` = '{$_POST['email']}'", 'limit' => 1)); if (count($users) > 0) { $user = $users[0]; $request = new PasswordRequest(); $request->user_id = $user->id; $request->created_at = date("Y-m-d H:i:s"); $request->hash = md5($request->created_at . $request->user_id . 'Questa non la sai'); $request->save(); $this->redirect_to(array('action' => 'request_sent')); } $this->flash(l('No such user'), 'error'); $this->redirect_to(array('action' => 'lost_password')); }