diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2016-12-09 12:40:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-09 12:40:38 +0300 |
commit | 29bb1cedc616b3fac110a11faded8a6d053c383c (patch) | |
tree | f335e4c2569a30afdb283959be9fe5d9aa5d36cf | |
parent | d379adb9f8c41b30f0d07efff3d7305770edd803 (diff) | |
parent | 5fb1bd01ffc434545eff8afa855d1eb3d0213f94 (diff) |
Merge pull request #2562 from nextcloud/backport-2561-save-timezone-on-login
[stable10] Save the timezone on login again
-rw-r--r-- | core/Controller/LoginController.php | 9 | ||||
-rw-r--r-- | core/js/visitortimezone.js | 2 | ||||
-rw-r--r-- | core/templates/login.php | 3 | ||||
-rw-r--r-- | 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', [ <label for="remember_login"><?php p($l->t('Stay logged in')); ?></label> </div> <?php endif; ?> - <input type="hidden" name="timezone-offset" id="timezone-offset"/> + + <input type="hidden" name="timezone_offset" id="timezone_offset"/> <input type="hidden" name="timezone" id="timezone"/> <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>"> </fieldset> 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() { |