Save the timezone on login again

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2016-12-08 10:45:24 +01:00
parent d9655a1f6d
commit 5fb1bd01ff
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
4 changed files with 24 additions and 4 deletions

View File

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

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

View File

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

View File

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