Allow users to override the timezone and the language

This commit is contained in:
Frederic Guillot
2015-01-04 22:34:59 -05:00
parent d1d04d6fee
commit 99d27e0ce4
33 changed files with 163 additions and 55 deletions

View File

@@ -33,7 +33,7 @@ class Database extends Base
$user = $this->db->table(User::TABLE)->eq('username', $username)->eq('is_ldap_user', 0)->findOne();
if ($user && password_verify($password, $user['password'])) {
$this->user->updateSession($user);
$this->userSession->refresh($user);
$this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id']));
return true;
}

View File

@@ -35,7 +35,7 @@ class GitHub extends Base
$user = $this->user->getByGitHubId($github_id);
if ($user) {
$this->user->updateSession($user);
$this->userSession->refresh($user);
$this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id']));
return true;
}

View File

@@ -36,7 +36,7 @@ class Google extends Base
$user = $this->user->getByGoogleId($google_id);
if ($user) {
$this->user->updateSession($user);
$this->userSession->refresh($user);
$this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id']));
return true;
}

View File

@@ -54,7 +54,7 @@ class Ldap extends Base
}
// We open the session
$this->user->updateSession($user);
$this->userSession->refresh($user);
$this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id']));
return true;

View File

@@ -101,7 +101,7 @@ class RememberMe extends Base
);
// Create the session
$this->user->updateSession($this->user->getById($record['user_id']));
$this->userSession->refresh($this->user->getById($record['user_id']));
$this->container['dispatcher']->dispatch(
'auth.success',

View File

@@ -37,7 +37,7 @@ class ReverseProxy extends Base
$user = $this->user->getByUsername($login);
}
$this->user->updateSession($user);
$this->userSession->refresh($user);
$this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id']));
return true;

View File

@@ -16,6 +16,7 @@ use Symfony\Component\Console\Command\Command;
* @property \Model\ProjectPermission $projectPermission
* @property \Model\ProjectAnalytic $projectAnalytic
* @property \Model\ProjectDailySummary $projectDailySummary
* @property \Model\SubtaskExport $subtaskExport
* @property \Model\Task $task
* @property \Model\TaskExport $taskExport
* @property \Model\TaskFinder $taskFinder

View File

@@ -151,6 +151,8 @@ class User extends Base
public function create(array $values = array(), array $errors = array())
{
$this->response->html($this->template->layout('user/new', array(
'timezones' => $this->config->getTimezones(true),
'languages' => $this->config->getLanguages(true),
'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()),
'projects' => $this->project->getList(),
'errors' => $errors,
@@ -194,6 +196,8 @@ class User extends Base
$this->response->html($this->layout('user/show', array(
'projects' => $this->projectPermission->getAllowedProjects($user['id']),
'user' => $user,
'timezones' => $this->config->getTimezones(true),
'languages' => $this->config->getLanguages(true),
)));
}
@@ -358,6 +362,8 @@ class User extends Base
'errors' => $errors,
'projects' => $this->projectPermission->filterProjects($this->project->getList(), $user['id']),
'user' => $user,
'timezones' => $this->config->getTimezones(true),
'languages' => $this->config->getLanguages(true),
)));
}

View File

@@ -181,5 +181,8 @@ class Translator
if (file_exists($filename)) {
self::$locales = require $filename;
}
else {
self::$locales = array();
}
}
}

View File

@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -453,7 +453,7 @@ return array(
'Notifications:' => 'Notificaciones:',
// 'Notifications' => '',
'Group:' => 'Grupo:',
'Regular user' => 'Usuario regular:',
'Regular user' => 'Usuario regular',
'Account type:' => 'Tipo de Cuenta:',
'Edit profile' => 'Editar perfil',
'Change password' => 'Cambiar contraseña',
@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -644,4 +644,7 @@ return array(
'Subtasks exportation for "%s"' => 'Exportation des sous-tâches pour le projet « %s »',
'Task Title' => 'Titre de la tâche',
'Untitled' => 'Sans nom',
'Application default' => 'Valeur par défaut de l\'application',
'Language:' => 'Langue :',
'Timezone:' => 'Fuseau horaire :',
);

View File

@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -644,4 +644,7 @@ return array(
// 'Subtasks exportation for "%s"' => '',
// 'Task Title' => '',
// 'Untitled' => '',
// 'Application default' => '',
// 'Language:' => '',
// 'Timezone:' => '',
);

View File

@@ -25,24 +25,32 @@ class Config extends Base
* Get available timezones
*
* @access public
* @param boolean $prepend Prepend a default value
* @return array
*/
public function getTimezones()
public function getTimezones($prepend = false)
{
$timezones = timezone_identifiers_list();
return array_combine(array_values($timezones), $timezones);
$listing = array_combine(array_values($timezones), $timezones);
if ($prepend) {
return array('' => t('Application default')) + $listing;
}
return $listing;
}
/**
* Get available languages
*
* @access public
* @param boolean $prepend Prepend a default value
* @return array
*/
public function getLanguages()
public function getLanguages($prepend = false)
{
// Sorted by value
return array(
$languages = array(
'da_DK' => 'Dansk',
'de_DE' => 'Deutsch',
'en_US' => 'English',
@@ -59,6 +67,12 @@ class Config extends Base
'ja_JP' => '日本語',
'th_TH' => 'ไทย',
);
if ($prepend) {
return array('' => t('Application default')) + $languages;
}
return $languages;
}
/**
@@ -138,10 +152,11 @@ class Config extends Base
*/
public function setupTranslations()
{
$language = $this->get('application_language', 'en_US');
if ($language !== 'en_US') {
Translator::load($language);
if ($this->userSession->isLogged() && ! empty($this->session['user']['language'])) {
Translator::load($this->session['user']['language']);
}
else {
Translator::load($this->get('application_language', 'en_US'));
}
}
@@ -152,7 +167,12 @@ class Config extends Base
*/
public function setupTimezone()
{
date_default_timezone_set($this->get('application_timezone', 'UTC'));
if ($this->userSession->isLogged() && ! empty($this->session['user']['timezone'])) {
date_default_timezone_set($this->session['user']['timezone']);
}
else {
date_default_timezone_set($this->get('application_timezone', 'UTC'));
}
}
/**

View File

@@ -254,7 +254,7 @@ class User extends Base
// If the user is connected refresh his session
if (Session::isOpen() && $this->userSession->getId() == $values['id']) {
$this->updateSession();
$this->userSession->refresh();
}
return $result;
@@ -294,30 +294,6 @@ class User extends Base
});
}
/**
* Update user session information
*
* @access public
* @param array $user User data
*/
public function updateSession(array $user = array())
{
if (empty($user)) {
$user = $this->getById($this->userSession->getId());
}
if (isset($user['password'])) {
unset($user['password']);
}
$user['id'] = (int) $user['id'];
$user['default_project_id'] = (int) $user['default_project_id'];
$user['is_admin'] = (bool) $user['is_admin'];
$user['is_ldap_user'] = (bool) $user['is_ldap_user'];
$this->session['user'] = $user;
}
/**
* Common validation rules
*

View File

@@ -2,6 +2,8 @@
namespace Model;
use Core\Translator;
/**
* User Session
*
@@ -10,6 +12,30 @@ namespace Model;
*/
class UserSession extends Base
{
/**
* Update user session information
*
* @access public
* @param array $user User data
*/
public function refresh(array $user = array())
{
if (empty($user)) {
$user = $this->user->getById($this->userSession->getId());
}
if (isset($user['password'])) {
unset($user['password']);
}
$user['id'] = (int) $user['id'];
$user['default_project_id'] = (int) $user['default_project_id'];
$user['is_admin'] = (bool) $user['is_admin'];
$user['is_ldap_user'] = (bool) $user['is_ldap_user'];
$this->session['user'] = $user;
}
/**
* Return true if the logged user is admin
*

View File

@@ -5,7 +5,13 @@ namespace Schema;
use PDO;
use Core\Security;
const VERSION = 40;
const VERSION = 41;
function version_41($pdo)
{
$pdo->exec('ALTER TABLE users ADD COLUMN timezone VARCHAR(50)');
$pdo->exec('ALTER TABLE users ADD COLUMN language CHAR(5)');
}
function version_40($pdo)
{

View File

@@ -5,7 +5,13 @@ namespace Schema;
use PDO;
use Core\Security;
const VERSION = 21;
const VERSION = 22;
function version_22($pdo)
{
$pdo->exec('ALTER TABLE users ADD COLUMN timezone VARCHAR(50)');
$pdo->exec('ALTER TABLE users ADD COLUMN language CHAR(5)');
}
function version_21($pdo)
{

View File

@@ -5,7 +5,13 @@ namespace Schema;
use Core\Security;
use PDO;
const VERSION = 39;
const VERSION = 40;
function version_40($pdo)
{
$pdo->exec('ALTER TABLE users ADD COLUMN timezone TEXT');
$pdo->exec('ALTER TABLE users ADD COLUMN language TEXT');
}
function version_39($pdo)
{

View File

@@ -20,6 +20,12 @@
<?= $this->formLabel(t('Default project'), 'default_project_id') ?>
<?= $this->formSelect('default_project_id', $projects, $values, $errors) ?><br/>
<?= $this->formLabel(t('Timezone'), 'timezone') ?>
<?= $this->formSelect('timezone', $timezones, $values, $errors) ?><br/>
<?= $this->formLabel(t('Language'), 'language') ?>
<?= $this->formSelect('language', $languages, $values, $errors) ?><br/>
<?php if ($this->userSession->isAdmin()): ?>
<?= $this->formCheckbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1 ? true : false) ?><br/>
<?php endif ?>

View File

@@ -27,6 +27,12 @@
<?= $this->formLabel(t('Default project'), 'default_project_id') ?>
<?= $this->formSelect('default_project_id', $projects, $values, $errors) ?><br/>
<?= $this->formLabel(t('Timezone'), 'timezone') ?>
<?= $this->formSelect('timezone', $timezones, $values, $errors) ?><br/>
<?= $this->formLabel(t('Language'), 'language') ?>
<?= $this->formSelect('language', $languages, $values, $errors) ?><br/>
<?= $this->formCheckbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1 ? true : false) ?>
<div class="form-actions">

View File

@@ -3,9 +3,11 @@
</div>
<ul class="listing">
<li><?= t('Username:') ?> <strong><?= $this->e($user['username']) ?></strong></li>
<li><?= t('Name:') ?> <strong><?= $this->e($user['name']) ?></strong></li>
<li><?= t('Email:') ?> <strong><?= $this->e($user['email']) ?></strong></li>
<li><?= t('Default project:') ?> <strong><?= (isset($user['default_project_id']) && isset($projects[$user['default_project_id']])) ? $this->e($projects[$user['default_project_id']]) : t('None'); ?></strong></li>
<li><?= t('Name:') ?> <strong><?= $this->e($user['name']) ?: t('None') ?></strong></li>
<li><?= t('Email:') ?> <strong><?= $this->e($user['email']) ?: t('None') ?></strong></li>
<li><?= t('Default project:') ?> <strong><?= (isset($user['default_project_id']) && isset($projects[$user['default_project_id']])) ? $this->e($projects[$user['default_project_id']]) : t('None') ?></strong></li>
<li><?= t('Timezone:') ?> <strong><?= $this->inList($user['timezone'], $timezones) ?></strong></li>
<li><?= t('Language:') ?> <strong><?= $this->inList($user['language'], $languages) ?></strong></li>
<li><?= t('Notifications:') ?> <strong><?= $user['notifications_enabled'] == 1 ? t('Enabled') : t('Disabled') ?></strong></li>
<li><?= t('Group:') ?> <strong><?= $user['is_admin'] ? t('Administrator') : t('Regular user') ?></strong></li>
<li><?= t('Account type:') ?> <strong><?= $user['is_ldap_user'] ? t('Remote') : t('Local') ?></strong></li>