Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ffaaa 163 switch user profile #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions i18n/sf_guard.fr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@
<source>New Password for %name%</source>
<target>Nouveau mot de passe pour %name%</target>
</trans-unit>
<trans-unit>
<source>The username and/or password is invalid.</source>
<target>L'identifiant et/ou le mot de passe est invalide.</target>
</trans-unit>
<trans-unit>
<source>Remember</source>
<target>Se souvenir</target>
</trans-unit>
</body>
</file>
</xliff>
117 changes: 66 additions & 51 deletions modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,81 @@
*/
class BasesfGuardAuthActions extends sfActions
{
public function executeSignin($request)
{
$user = $this->getUser();
if ($user->isAuthenticated())
public function executeSignin($request)
{
return $this->redirect('@homepage');
}
$user = $this->getUser();
if ($user->isAuthenticated()) {
return $this->redirect('@homepage');
}

$class = sfConfig::get('app_sf_guard_plugin_signin_form', 'sfGuardFormSignin');
$this->form = new $class();

if ($request->isMethod('post')) {
$this->form->bind($request->getParameter($this->form->getName()));
if ($this->form->isValid()) {
$values = $this->form->getValues();
$this->getUser()->signin($values['user'], array_key_exists('remember', $values) ? $values['remember'] : false);

// always redirect to a URL set in app.yml
// or to the referer
// or to the homepage
$signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $user->getReferer($request->getReferer()));

return $this->redirect('' != $signinUrl ? $signinUrl : '@homepage');
}
} else {
if ($request->isXmlHttpRequest()) {
$this->getResponse()->setHeaderOnly(true);
$this->getResponse()->setStatusCode(401);

return sfView::NONE;
}

// if we have been forwarded, then the referer is the current URL
// if not, this is the referer of the current request
$user->setReferer($this->getContext()->getActionStack()->getSize() > 1 ? $request->getUri() : $request->getReferer());

$class = sfConfig::get('app_sf_guard_plugin_signin_form', 'sfGuardFormSignin');
$this->form = new $class();
$module = sfConfig::get('sf_login_module');
if ($this->getModuleName() != $module) {
return $this->redirect($module . '/' . sfConfig::get('sf_login_action'));
}
}
}

if ($request->isMethod('post'))
public function executeSignout($request)
{
$this->form->bind($request->getParameter($this->form->getName()));
if ($this->form->isValid())
{
$values = $this->form->getValues();
$this->getUser()->signin($values['user'], array_key_exists('remember', $values) ? $values['remember'] : false);

// always redirect to a URL set in app.yml
// or to the referer
// or to the homepage
$signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $user->getReferer($request->getReferer()));

return $this->redirect('' != $signinUrl ? $signinUrl : '@homepage');
}
$this->getUser()->signOut();

$signoutUrl = sfConfig::get('app_sf_guard_plugin_success_signout_url', $request->getReferer());

$this->redirect('' != $signoutUrl ? $signoutUrl : '@homepage');
}
else

public function executeSecure($request)
{
if ($request->isXmlHttpRequest())
{
$this->getResponse()->setHeaderOnly(true);
$this->getResponse()->setStatusCode(401);

return sfView::NONE;
}

// if we have been forwarded, then the referer is the current URL
// if not, this is the referer of the current request
$user->setReferer($this->getContext()->getActionStack()->getSize() > 1 ? $request->getUri() : $request->getReferer());

$module = sfConfig::get('sf_login_module');
if ($this->getModuleName() != $module)
{
return $this->redirect($module.'/'.sfConfig::get('sf_login_action'));
}
$this->getResponse()->setStatusCode(403);
}
}

public function executeSignout($request)
{
$this->getUser()->signOut();
public function executeSwitchProfile($request)
{
$this->form = new HevaSwitchProfileForm();

if ($request->isMethod('post')) {
$this->form->bind($request->getParameter($this->form->getName()));
if ($this->form->isValid()) {
$profileId = $this->form->getValue('switchProfile');
$profile = Doctrine_Core::getTable("HevaGuardUserProfile")->findById($profileId)->getFirst();

$signoutUrl = sfConfig::get('app_sf_guard_plugin_success_signout_url', $request->getReferer());
if ($profile == null) {
$this->getUser()->setFlash('error', "Impossible de se connecter à l'association " . $profile->getAssociation()->getName());
return $this->redirect('@selectProfile');
}

$this->redirect('' != $signoutUrl ? $signoutUrl : '@homepage');
}
$this->getContext()->getUser()->setAttribute('active_profile', $profile);
return $this->redirect('@homepage');

public function executeSecure($request)
{
$this->getResponse()->setStatusCode(403);
}
}
}
}
}