Save the timezone on login again
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
d9655a1f6d
commit
5fb1bd01ff
|
@ -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)) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue