/**
  * 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();
 }
Esempio n. 2
0
 public function executeDeleteAccount(sfWebRequest $request)
 {
     $user = PcUserPeer::getLoggedInUser();
     $this->form = new DeleteAccountForm();
     $reasons = $this->form->getReasons();
     $fields = array();
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('deleteAccount'));
         if ($this->form->isValid()) {
             $fields = $request->getParameter('deleteAccount');
             $message = $reasons[$fields['reason']] . "\n XX \n" . $fields['info'];
             $to = sfConfig::get('app_emailAddress_contact');
             // we need to add a 'random' code otherwise GMail groups all of them together
             $subject = 'Account deletion ' . date('YmdHis');
             PcUtils::sendEmail($to, $subject, $message, $to, PcUserPeer::getLoggedInUser()->getEmail());
             $emailAddressForDeletedAccounts = 'deleted_' . PcUtils::generateRandomString(32) . '@plancake.com';
             $user->setEmail($emailAddressForDeletedAccounts)->save();
             sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent('userSetEmail', 'user.set_email', array('user' => $user)));
             CustomAuth::logout($this->getUser());
             $this->redirect(sfContext::getInstance()->getController()->genUrl('@homepage'));
         }
     }
     $this->user = $user;
 }
Esempio n. 3
0
 public function executePasswordReset(sfWebRequest $request)
 {
     $token = '';
     if ($request->getParameter('t')) {
         $token = $request->getParameter('t');
     } else {
         $param = $request->getParameter('passwordReset');
         $token = $param['t'];
     }
     $token = trim($token);
     // if the user is authenticated, they shouldn't get here
     PcUtils::redirectLoggedInUser($this->getUser(), $this);
     // Check the token is valid
     $c = new Criteria();
     $c->add(PcPasswordResetTokenPeer::TOKEN, $token, Criteria::EQUAL);
     $entry = PcPasswordResetTokenPeer::doSelectOne($c);
     if (!is_object($entry)) {
         // the token is not valid
         PcWatchdog::alert('Invalid Password Reset Token', 'This is the token ' . $token);
         $this->forward('customAuth', 'passwordResetInvalidToken');
     }
     $this->form = new PasswordResetForm(array('t' => $token));
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('passwordReset'));
         if ($this->form->isValid()) {
             $fields = $request->getParameter('passwordReset');
             $user = CustomAuth::resetPassword($token, $fields['password1']);
             $this->redirect('/' . sfConfig::get('app_accountApp_frontController'));
         }
     }
 }
* Licensed under the AGPL version 3 license.                                         *                                                       *
* Danyuki Software Limited is registered in England and Wales (Company No. 07554549) *
**************************************************************************************
* Plancake is distributed in the hope that it will be useful,                        *
* but WITHOUT ANY WARRANTY; without even the implied warranty of                     *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                      *
* GNU Affero General Public License for more details.                                *
*                                                                                    *
* You should have received a copy of the GNU Affero General Public License           *
* along with this program.  If not, see <http://www.gnu.org/licenses/>.              *
*                                                                                    *
**************************************************************************************/
require_once dirname(__FILE__) . '/../../config/ProjectConfiguration.class.php';
$configuration = ProjectConfiguration::getApplicationConfiguration('account', 'prod', false);
$context = sfContext::createInstance($configuration);
$consumer = new PlancakeOpenIdConsumer(PlancakeOpenIdConsumer::PROVIDER_GOOGLE, 'http://www.plancake.com/openIdEndpoints/googleReceiveLogin.php', PlancakeOpenIdConsumer::MODE_LOGIN);
$consumer->receive($data);
$email = $data['http://axschema.org/contact/email'][0];
if (PcUserPeer::emailExist($email)) {
    $userToLogin = PcUserPeer::retrieveByEmailAddress($email);
    CustomAuth::login($context->getUser(), $userToLogin, false, false);
    if (PcUtils::isMobileBrowser()) {
        $redirectUrl = 'https://' . sfConfig::get('app_site_url') . "/account.php/mobile";
    } else {
        $redirectUrl = 'http://' . sfConfig::get('app_site_url') . "/account.php";
    }
} else {
    $encodedEmail = urlencode($email);
    $redirectUrl = 'http://' . sfConfig::get('app_site_url') . "/openIdWrongLogin?input_email={$encodedEmail}";
}
header("Location: {$redirectUrl}");