diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-09-23 13:45:21 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-09-23 13:45:21 +0200 |
commit | c587a4aaa212a48aca0b34fc2f9625774e02c472 (patch) | |
tree | 125b5ba8c98d5137e63e71c003135a9b338586d9 /lib | |
parent | a062db4fd02feb1a0eff48eb130da7cc48c49899 (diff) | |
parent | 814114ab8eda5d383f4c620f3854cfefcdb6895d (diff) | |
download | nextcloud-server-c587a4aaa212a48aca0b34fc2f9625774e02c472.tar.gz nextcloud-server-c587a4aaa212a48aca0b34fc2f9625774e02c472.zip |
Merge pull request #11222 from owncloud/store-users-timezone-master
send browsers timezone back tp the server on login
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 16 | ||||
-rwxr-xr-x | lib/private/util.php | 24 | ||||
-rw-r--r-- | lib/public/util.php | 6 |
3 files changed, 29 insertions, 17 deletions
diff --git a/lib/base.php b/lib/base.php index fc2bdddb440..7d735f523f4 100644 --- a/lib/base.php +++ b/lib/base.php @@ -913,7 +913,7 @@ class OC { } /** - * Tries to login a user using the formbased authentication + * Tries to login a user using the form based authentication * @return bool|void */ protected static function tryFormLogin() { @@ -928,20 +928,22 @@ class OC { OC_User::setupBackends(); if (OC_User::login($_POST["user"], $_POST["password"])) { + $userId = OC_User::getUser(); + // setting up the time zone if (isset($_POST['timezone-offset'])) { self::$server->getSession()->set('timezone', $_POST['timezone-offset']); + self::$server->getConfig()->setUserValue($userId, 'core', 'timezone', $_POST['timezone']); } - $userid = OC_User::getUser(); - self::cleanupLoginTokens($userid); + self::cleanupLoginTokens($userId); if (!empty($_POST["remember_login"])) { if (defined("DEBUG") && DEBUG) { - OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG); + self::$server->getLogger()->debug('Setting remember login to cookie', array('app' => 'core')); } $token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(32); - OC_Preferences::setValue($userid, 'login_token', $token, time()); - OC_User::setMagicInCookie($userid, $token); + self::$server->getConfig()->setUserValue($userId, 'login_token', $token, time()); + OC_User::setMagicInCookie($userId, $token); } else { OC_User::unsetMagicInCookie(); } @@ -950,8 +952,6 @@ class OC { } return true; } - - } if (!function_exists('get_temp_dir')) { diff --git a/lib/private/util.php b/lib/private/util.php index 18857139791..5a310273258 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -381,16 +381,26 @@ class OC_Util { * * @param int $timestamp * @param bool $dateOnly option to omit time from the result + * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to * @return string timestamp * @description adjust to clients timezone if we know it */ - public static function formatDate( $timestamp, $dateOnly = false) { - if(\OC::$server->getSession()->exists('timezone')) { - $systemTimeZone = intval(date('O')); - $systemTimeZone = (round($systemTimeZone / 100, 0) * 60) + ($systemTimeZone % 100); - $clientTimeZone = \OC::$server->getSession()->get('timezone') * 60; - $offset = $clientTimeZone - $systemTimeZone; - $timestamp = $timestamp + $offset * 60; + public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) { + if (is_null($timeZone)) { + if (\OC::$server->getSession()->exists('timezone')) { + $systemTimeZone = intval(date('O')); + $systemTimeZone = (round($systemTimeZone / 100, 0) * 60) + ($systemTimeZone % 100); + $clientTimeZone = \OC::$server->getSession()->get('timezone') * 60; + $offset = $clientTimeZone - $systemTimeZone; + $timestamp = $timestamp + $offset * 60; + } + } else { + if (!$timeZone instanceof DateTimeZone) { + $timeZone = new DateTimeZone($timeZone); + } + $dt = new DateTime("@$timestamp"); + $offset = $timeZone->getOffset($dt); + $timestamp += $offset; } $l = \OC::$server->getL10N('lib'); return $l->l($dateOnly ? 'date' : 'datetime', $timestamp); diff --git a/lib/public/util.php b/lib/public/util.php index 244c11ba2cc..35847fce38a 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -29,6 +29,7 @@ // use OCP namespace for all classes that are considered public. // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; +use DateTimeZone; /** * This class provides different helper functions to make the life of a developer easier @@ -167,10 +168,11 @@ class Util { * formats a timestamp in the "right" way * @param int $timestamp $timestamp * @param bool $dateOnly option to omit time from the result + * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to * @return string timestamp */ - public static function formatDate( $timestamp, $dateOnly=false) { - return(\OC_Util::formatDate( $timestamp, $dateOnly )); + public static function formatDate($timestamp, $dateOnly=false, $timeZone = null) { + return(\OC_Util::formatDate($timestamp, $dateOnly, $timeZone)); } /** |