From 5fb1bd01ffc434545eff8afa855d1eb3d0213f94 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 8 Dec 2016 10:45:24 +0100 Subject: [PATCH] Save the timezone on login again Signed-off-by: Joas Schilling --- core/Controller/LoginController.php | 9 ++++++++- core/js/visitortimezone.js | 2 +- core/templates/login.php | 3 ++- tests/Core/Controller/LoginControllerTest.php | 14 +++++++++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php index dbc1f3157fd..d6012d9aa72 100644 --- a/core/Controller/LoginController.php +++ b/core/Controller/LoginController.php @@ -195,9 +195,11 @@ class LoginController extends Controller { * @param string $user * @param string $password * @param string $redirect_url + * @param string $timezone + * @param string $timezone_offset * @return RedirectResponse */ - public function tryLogin($user, $password, $redirect_url) { + public function tryLogin($user, $password, $redirect_url, $timezone = '', $timezone_offset = '') { $currentDelay = $this->throttler->getDelay($this->request->getRemoteAddress()); $this->throttler->sleepDelay($this->request->getRemoteAddress()); @@ -237,6 +239,11 @@ class LoginController extends Controller { $this->userSession->login($user, $password); $this->userSession->createSessionToken($this->request, $loginResult->getUID(), $user, $password); + if ($timezone_offset !== '') { + $this->config->setUserValue($loginResult->getUID(), 'core', 'timezone', $timezone); + $this->session->set('timezone', $timezone_offset); + } + if ($this->twoFactorManager->isTwoFactorAuthenticated($loginResult)) { $this->twoFactorManager->prepareTwoFactorLogin($loginResult); if (!is_null($redirect_url)) { diff --git a/core/js/visitortimezone.js b/core/js/visitortimezone.js index e6e99ee7e20..e984c90a894 100644 --- a/core/js/visitortimezone.js +++ b/core/js/visitortimezone.js @@ -1,6 +1,6 @@ /* global jstz */ $(document).ready(function () { - $('#timezone-offset').val((-new Date().getTimezoneOffset() / 60)); + $('#timezone_offset').val((-new Date().getTimezoneOffset() / 60)); $('#timezone').val(jstz.determine().name()); // only enable the submit button once we are sure that the timezone is set diff --git a/core/templates/login.php b/core/templates/login.php index c5453c34497..9311c39b8dc 100644 --- a/core/templates/login.php +++ b/core/templates/login.php @@ -75,7 +75,8 @@ script('core', [ - + + diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index 8eaa7c9843b..3686002d451 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -330,6 +330,12 @@ class LoginControllerTest extends TestCase { public function testLoginWithValidCredentials() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ $user = $this->getMockBuilder('\OCP\IUser')->getMock(); + $user->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('uid')); + $user->expects($this->any()) + ->method('getLastLogin') + ->willReturn(123456); $password = 'secret'; $indexPageUrl = \OC_Util::getDefaultPageUrl(); @@ -363,9 +369,15 @@ class LoginControllerTest extends TestCase { ->method('isTwoFactorAuthenticated') ->with($user) ->will($this->returnValue(false)); + $this->config->expects($this->once()) + ->method('setUserValue') + ->with('uid', 'core', 'timezone', 'Europe/Berlin'); + $this->session->expects($this->once()) + ->method('set') + ->with('timezone', '1'); $expected = new \OCP\AppFramework\Http\RedirectResponse($indexPageUrl); - $this->assertEquals($expected, $this->loginController->tryLogin($user, $password, null)); + $this->assertEquals($expected, $this->loginController->tryLogin($user, $password, null, 'Europe/Berlin', '1')); } public function testLoginWithoutPassedCsrfCheckAndNotLoggedIn() {