Ticket #2347: sfGuardRememberMeFilter.class.php
| File sfGuardRememberMeFilter.class.php, 1.4 kB (added by edlucas, 1 year ago) |
|---|
| Line | |
|---|---|
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the symfony package. |
| 5 | * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> |
| 6 | * @author Fabien Potencier <fabien.potencier@symfony-project.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | |
| 12 | /** Based on sfGuardBasicSecurityFilter but decoupled from sfBasicSecurityFilter |
| 13 | * so that it can work on paths that are not secure. |
| 14 | * |
| 15 | * Place this filter before the security filter in filters.yml e.g. |
| 16 | * ... |
| 17 | * rememberme: |
| 18 | * class: sfGuardRememberMeFilter |
| 19 | * security: ~ |
| 20 | * ... |
| 21 | * |
| 22 | * @package symfony |
| 23 | * @subpackage plugin |
| 24 | * @author Ed Lucas <elucas@whiteoctober.co.uk> |
| 25 | * @version SVN: $Id$ |
| 26 | */ |
| 27 | class sfGuardRememberMeFilter extends sfFilter |
| 28 | { |
| 29 | public function execute ($filterChain) |
| 30 | { |
| 31 | if ($this->isFirstCall() and !$this->getContext()->getUser()->isAuthenticated()) |
| 32 | { |
| 33 | if ($cookie = $this->getContext()->getRequest()->getCookie(sfConfig::get('app_sf_guard_plugin_remember_cookie_name', 'sfRemember'))) |
| 34 | { |
| 35 | $c = new Criteria(); |
| 36 | $c->add(sfGuardRememberKeyPeer::REMEMBER_KEY, $cookie); |
| 37 | $rk = sfGuardRememberKeyPeer::doSelectOne($c); |
| 38 | if ($rk && $rk->getSfGuardUser()) |
| 39 | { |
| 40 | $this->getContext()->getUser()->signIn($rk->getSfGuardUser()); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | $filterChain->execute(); |
| 46 | } |
| 47 | } |
| 48 |