Files
grzanieplus.pl/plugins/sfGuardPlugin/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php
2025-03-12 17:06:23 +01:00

120 lines
3.0 KiB
PHP

<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package symfony
* @subpackage plugin
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: BasesfGuardAuthActions.class.php 4 2008-09-24 08:40:58Z marek $
*/
class BasesfGuardAuthActions extends stActions
{
public function executeSignin()
{
$user = $this->getUser();
if ($this->getRequest()->getMethod() == sfRequest::POST)
{
$referer = $user->getAttribute('referer', $this->getRequest()->getReferer());
$user->getAttributeHolder()->remove('referer');
$signin_url = sfConfig::get('app_sf_guard_plugin_success_signin_url', $referer);
$this->redirect('' != $signin_url ? $signin_url : '@homepage');
}
elseif ($user->isAuthenticated())
{
$this->redirect('@homepage');
}
else
{
if ($this->getRequest()->isXmlHttpRequest())
{
$this->getResponse()->setHeaderOnly(true);
$this->getResponse()->setStatusCode(401);
return sfView::NONE;
}
if (!$user->hasAttribute('referer'))
{
$user->setAttribute('referer', $this->getRequest()->getUri());
}
if ($this->getModuleName() != ($module = sfConfig::get('sf_login_module')))
{
return $this->redirect($module.'/'.sfConfig::get('sf_login_action'));
}
$this->getResponse()->setStatusCode(401);
}
}
public function executeSignout()
{
$this->getUser()->signOut();
//$signout_url = sfConfig::get('app_sf_guard_plugin_success_signout_url', $this->getRequest()->getReferer());
$this->redirect('@homepage');
}
public function executeSecure()
{
$this->getResponse()->setStatusCode(403);
}
public function executePassword()
{
throw new sfException('This method is not yet implemented.');
}
public function validateSignin()
{
$request = $this->getRequest();
$ok = !$request->hasErrors();
if (!$request->isXmlHttpRequest() && !$request->hasParameter('remind[email]') && $request->getMethod() == sfRequest::POST)
{
if (!$this->getRequestParameter('username'))
{
$request->setError('username', 'Proszę podać nazwę użytkownika');
$ok = false;
}
if (!$this->getRequestParameter('password'))
{
$request->setError('password', 'Proszę podać hasło');
$ok = false;
}
}
return $ok;
}
public function handleErrorSignin()
{
$user = $this->getUser();
if (!$user->hasAttribute('referer'))
{
$user->setAttribute('referer', $this->getRequest()->getReferer());
}
$module = sfConfig::get('sf_login_module');
if ($this->getModuleName() != $module)
{
$this->forward(sfConfig::get('sf_login_module'), sfConfig::get('sf_login_action'));
}
return sfView::SUCCESS;
}
}