Added administrator preferred locale (see issue #183)

This commit is contained in:
Franck Allimant
2014-01-27 14:29:37 +01:00
parent a27c913f70
commit c5cc6aae76
16 changed files with 256 additions and 50 deletions

View File

@@ -66,6 +66,7 @@ class AdministratorController extends AbstractCrudController
$event->setLastname($formData['lastname']);
$event->setPassword($formData['password']);
$event->setProfile($formData['profile'] ? : null);
$event->setLocale($formData['locale']);
return $event;
}
@@ -80,6 +81,7 @@ class AdministratorController extends AbstractCrudController
$event->setLastname($formData['lastname']);
$event->setPassword($formData['password']);
$event->setProfile($formData['profile'] ? : null);
$event->setLocale($formData['locale']);
return $event;
}
@@ -108,6 +110,7 @@ class AdministratorController extends AbstractCrudController
'lastname' => $object->getLastname(),
'login' => $object->getLogin(),
'profile' => $object->getProfileId(),
'locale' => $object->getLocale()
);
// Setup the object form

View File

@@ -26,8 +26,11 @@ namespace Thelia\Controller\Admin;
use Thelia\Form\AdminLogin;
use Thelia\Core\Security\Authentication\AdminUsernamePasswordFormAuthenticator;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Admin;
use Thelia\Model\AdminLog;
use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Model\Lang;
use Thelia\Model\LangQuery;
use Thelia\Tools\URL;
use Thelia\Tools\Redirect;
use Thelia\Core\Event\TheliaEvents;
@@ -56,8 +59,11 @@ class SessionController extends BaseAdminController
// Update the cookie
$this->createAdminRememberMeCookie($user);
$this->applyUserLocale($user);
// Render the home page
return $this->render("home");
} catch (TokenAuthenticationException $ex) {
$this->adminLogAppend("admin", "LOGIN", "Token based authentication failed.");
@@ -69,6 +75,18 @@ class SessionController extends BaseAdminController
return $this->render("login");
}
protected function applyUserLocale(Admin $user) {
// Set the current language according to Admin locale preference
$locale = $user->getLocale();
if (null === $lang = LangQuery::create()->findOneByLocale($locale)) {
$lang = Lang::getDefaultLanguage();
}
$this->getSession()->setLang($lang);
}
public function checkLogoutAction()
{
$this->dispatch(TheliaEvents::ADMIN_LOGOUT);
@@ -102,6 +120,8 @@ class SessionController extends BaseAdminController
// Log authentication success
AdminLog::append("admin", "LOGIN", "Authentication successful", $request, $user, false);
$this->applyUserLocale($user);
/**
* FIXME: we have tou find a way to send cookie
*/