Development

/plugins/sfGuardPlugin/branches/1.3/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php

You must first sign up to be able to contribute.

root/plugins/sfGuardPlugin/branches/1.3/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php

Revision 32962, 2.4 kB (checked in by fabien, 9 months ago)

[sfGuardPlugin] fixed incorrect use of the 401 status code (closes #4474, #4557)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
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  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  *
13  * @package    symfony
14  * @subpackage plugin
15  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
16  * @version    SVN: $Id$
17  */
18 class BasesfGuardAuthActions extends sfActions
19 {
20   public function executeSignin($request)
21   {
22     $user = $this->getUser();
23     if ($user->isAuthenticated())
24     {
25       return $this->redirect('@homepage');
26     }
27
28     if ($request->isXmlHttpRequest())
29     {
30       $this->getResponse()->setHeaderOnly(true);
31       $this->getResponse()->setStatusCode(401);
32
33       return sfView::NONE;
34     }
35
36     $class = sfConfig::get('app_sf_guard_plugin_signin_form', 'sfGuardFormSignin');
37     $this->form = new $class();
38
39     if ($request->isMethod('post'))
40     {
41       $this->form->bind($request->getParameter('signin'));
42       if ($this->form->isValid())
43       {
44         $values = $this->form->getValues();
45         $this->getUser()->signin($values['user'], array_key_exists('remember', $values) ? $values['remember'] : false);
46
47         // always redirect to a URL set in app.yml
48         // or to the referer
49         // or to the homepage
50         $signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $user->getReferer('@homepage'));
51
52         return $this->redirect($signinUrl);
53       }
54     }
55     else
56     {
57       // if we have been forwarded, then the referer is the current URL
58       // if not, this is the referer of the current request
59       $user->setReferer($this->getContext()->getActionStack()->getSize() > 1 ? $request->getUri() : $request->getReferer());
60
61       $module = sfConfig::get('sf_login_module');
62       if ($this->getModuleName() != $module)
63       {
64         return $this->redirect($module.'/'.sfConfig::get('sf_login_action'));
65       }
66     }
67   }
68
69   public function executeSignout($request)
70   {
71     $this->getUser()->signOut();
72
73     $signoutUrl = sfConfig::get('app_sf_guard_plugin_success_signout_url', $request->getReferer());
74
75     $this->redirect('' != $signoutUrl ? $signoutUrl : '@homepage');
76   }
77
78   public function executeSecure()
79   {
80     $this->getResponse()->setStatusCode(403);
81   }
82
83   public function executePassword()
84   {
85     throw new sfException('This method is not yet implemented.');
86   }
87 }
88
Note: See TracBrowser for help on using the browser.