Browse Source

Save the timezone on login again

Signed-off-by: Joas Schilling <coding@schilljs.com>
tags/v11.0RC2
Joas Schilling 7 years ago
parent
commit
924358ef96
No account linked to committer's email address

+ 8
- 1
core/Controller/LoginController.php View File

@@ -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);


+ 1
- 1
core/js/visitortimezone.js View File

@@ -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

+ 1
- 1
core/templates/login.php View File

@@ -80,7 +80,7 @@ script('core', [
<?php endif; ?>
</div>

<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>

+ 14
- 1
tests/Core/Controller/LoginControllerTest.php View File

@@ -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() {

Loading…
Cancel
Save