From 924358ef964f56096a03eba443c2bdce81a6f7b6 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 | 2 +- tests/Core/Controller/LoginControllerTest.php | 15 ++++++++++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php index c3ccac37f7..b6add48ef6 100644 --- a/core/Controller/LoginController.php +++ b/core/Controller/LoginController.php @@ -200,9 +200,11 @@ class LoginController extends Controller { * @param string $password * @param string $redirect_url * @param boolean $remember_login + * @param string $timezone + * @param string $timezone_offset * @return RedirectResponse */ - public function tryLogin($user, $password, $redirect_url, $remember_login = false) { + public function tryLogin($user, $password, $redirect_url, $remember_login = false, $timezone = '', $timezone_offset = '') { $currentDelay = $this->throttler->getDelay($this->request->getRemoteAddress()); $this->throttler->sleepDelay($this->request->getRemoteAddress()); @@ -247,6 +249,11 @@ class LoginController extends Controller { $this->session->set('last-password-confirm', $loginResult->getLastLogin()); + 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, $remember_login); diff --git a/core/js/visitortimezone.js b/core/js/visitortimezone.js index e6e99ee7e2..e984c90a89 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 46045f86b5..c200dfe366 100644 --- a/core/templates/login.php +++ b/core/templates/login.php @@ -80,7 +80,7 @@ script('core', [ - + diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index d16b9b114f..600179a1dc 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -337,6 +337,9 @@ class LoginControllerTest extends TestCase { $user->expects($this->any()) ->method('getUID') ->will($this->returnValue('uid')); + $user->expects($this->any()) + ->method('getLastLogin') + ->willReturn(123456); $password = 'secret'; $indexPageUrl = \OC_Util::getDefaultPageUrl(); @@ -373,11 +376,21 @@ class LoginControllerTest extends TestCase { $this->config->expects($this->once()) ->method('deleteUserValue') ->with('uid', 'core', 'lostpassword'); + $this->config->expects($this->once()) + ->method('setUserValue') + ->with('uid', 'core', 'timezone', 'Europe/Berlin'); $this->userSession->expects($this->never()) ->method('createRememberMeToken'); + $this->session->expects($this->exactly(2)) + ->method('set') + ->withConsecutive( + ['last-password-confirm', 123456], + ['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, false, 'Europe/Berlin', '1')); } public function testLoginWithValidCredentialsAndRememberMe() {