/** * Executes the filter chain. * * @param sfFilterChain $filterChain */ public function execute($filterChain) { $cookieName = sfConfig::get('app_doAuth_remember_cookie_name', 'doRemember'); if ($this->isFirstCall() && $this->context->getUser()->isAnonymous() && ($cookie = $this->context->getRequest()->getCookie($cookieName))) { $value = unserialize(base64_decode($cookie)); $user = Doctrine::getTable('User')->createQuery('u')->where('u.username = ?', $value[0])->fetchOne(); if ($user) { if ($value[2] == doAuthTools::rememberHash($user)) { $this->context->getUser()->signIn($q->fetchOne()); } } } $filterChain->execute(); }
public function executeResetPassword(sfWebRequest $request) { // i like how it is made in sfGuardUser: =) // throw new sfException('This method is not yet implemented.'); if ($request->hasParameter('user')) { $user = Doctrine::getTable('User')->createQuery()->find($request->getParameter('user')); $this->forward404Unless($user); if ($request->getParameter('code') != doAuthTools::passwordResetCode($user)) { $this->getUser()->setFlash('error', 'Password reset code is invalid'); $this->forward404(); } $password = doAuthTools::generatePassword(); doAuthMailer::sendNewPassword($this, $user, $password); $user->setPassword($password); $user->save(); $this->getUser()->setFlash('notice', 'We have sent a new password on your email'); $this->redirect(sfConfig::get('app_doAuth_reset_password_url', '@homepage')); } $this->form = new ResetPasswordForm(); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('reset_password')); if ($this->form->isValid()) { doAuthMailer::sendPasswordRequest($this, $user); $this->getUser()->setFlash('notice', 'You have requested a new password. Please, check your email and follow the instructions.'); $this->redirect(sfConfig::get('app_doAuth_reset_password_url', '@homepage')); } } }
public static function sendPasswordRequest(userActions $controller, User $user) { $subject = sfConfig::get('sf_i18n') ? $controller->getContext()->getI18N()->__('Password reset') : 'Password reset'; $code = doAuthTools::passwordResetCode($user); $controller->getMailer()->composeAndSend(sfConfig::get('app_doAuth_email_from', 'mailer@' . $controller->getRequest()->getHost()), array($user->getEmail() => $user->getUsername()), $subject, $controller->getPartial(sfConfig::get('app_doAuth_email_module', $controller->getModuleName()) . '/mail_reset_password', array('user' => $user, 'code' => $code)), 'text/plain'); }
public function executeResetPassword(sfWebRequest $request) { if ($request->hasParameter('user')) { $user = Doctrine::getTable('User')->find($request->getParameter('user')); $this->forward404Unless($user); if ($request->getParameter('code') != doAuthTools::passwordResetCode($user)) { $this->getUser()->setFlash('error', $this->getContext()->getI18N()->__('Password reset code is invalid')); $this->forward404(); } $password = doAuthTools::generatePassword(); doAuthMailer::sendNewPassword($this, $user, $password); $user->setPassword($password); $user->save(); $this->getUser()->setFlash('notice', $this->getContext()->getI18N()->__('We have sent a new password on your email')); $this->redirect(sfConfig::get('app_doAuth_reset_password_url', '@signin')); } $this->form = new ResetPasswordForm(); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('reset_password')); if ($this->form->isValid()) { $user = Doctrine::getTable('User')->findOneByEmail($this->form->getValue('email')); doAuthMailer::sendPasswordRequest($this, $user); $this->getUser()->setFlash('notice', $this->getContext()->getI18N()->__('You have requested a new password. Please, check your email and follow the instructions.')); $this->redirect(sfConfig::get('app_doAuth_reset_password_url', '@signin')); } } }
/** * Signs in the user on the application. * * @param doAuthUser $user The doAuthUser id * @param boolean $remember Whether or not to remember the user * @param Doctrine_Connection $con A Doctrine_Connection object */ public function signIn($user, $remember = false, $con = null) { // we remove a non-user storage $this->getAttributeHolder()->removeNamespace('doPreUser'); // signin $this->setAttribute('user_id', $user->getId(), 'doUser'); $this->setAuthenticated(true); // save last login $user->setLastLogin(date('Y-m-d H:i:s')); $user->save($con); // remember? if ($remember) { // save to cookie $hash = base64_encode(serialize(array($user->getUsername(), md5(rand()), doAuthTools::rememberHash($user)))); $context = sfContext::getInstance(); $expiration_age = sfConfig::get('app_doAuth_remember_key_expiration_age', 356 * 24 * 3600); // make key as a cookie $remember_cookie = sfConfig::get('app_doAuth_remember_cookie_name', 'doRemember'); sfContext::getInstance()->getResponse()->setCookie($remember_cookie, $hash, time() + $expiration_age); } $this->dispatcher->notify(new sfEvent($this, 'user.signed_in')); }