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 $user
|
||||||
* @param string $password
|
* @param string $password
|
||||||
* @param string $redirect_url
|
* @param string $redirect_url
|
||||||
|
* @param string $timezone
|
||||||
|
* @param string $timezone_offset
|
||||||
* @return RedirectResponse
|
* @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());
|
$currentDelay = $this->throttler->getDelay($this->request->getRemoteAddress());
|
||||||
$this->throttler->sleepDelay($this->request->getRemoteAddress());
|
$this->throttler->sleepDelay($this->request->getRemoteAddress());
|
||||||
|
|
||||||
|
@ -237,6 +239,11 @@ class LoginController extends Controller {
|
||||||
$this->userSession->login($user, $password);
|
$this->userSession->login($user, $password);
|
||||||
$this->userSession->createSessionToken($this->request, $loginResult->getUID(), $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)) {
|
if ($this->twoFactorManager->isTwoFactorAuthenticated($loginResult)) {
|
||||||
$this->twoFactorManager->prepareTwoFactorLogin($loginResult);
|
$this->twoFactorManager->prepareTwoFactorLogin($loginResult);
|
||||||
if (!is_null($redirect_url)) {
|
if (!is_null($redirect_url)) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* global jstz */
|
/* global jstz */
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('#timezone-offset').val((-new Date().getTimezoneOffset() / 60));
|
$('#timezone_offset').val((-new Date().getTimezoneOffset() / 60));
|
||||||
$('#timezone').val(jstz.determine().name());
|
$('#timezone').val(jstz.determine().name());
|
||||||
|
|
||||||
// only enable the submit button once we are sure that the timezone is set
|
// 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>
|
<label for="remember_login"><?php p($l->t('Stay logged in')); ?></label>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?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="timezone" id="timezone"/>
|
||||||
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>">
|
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>">
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
|
@ -330,6 +330,12 @@ class LoginControllerTest extends TestCase {
|
||||||
public function testLoginWithValidCredentials() {
|
public function testLoginWithValidCredentials() {
|
||||||
/** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */
|
/** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */
|
||||||
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
|
$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';
|
$password = 'secret';
|
||||||
$indexPageUrl = \OC_Util::getDefaultPageUrl();
|
$indexPageUrl = \OC_Util::getDefaultPageUrl();
|
||||||
|
|
||||||
|
@ -363,9 +369,15 @@ class LoginControllerTest extends TestCase {
|
||||||
->method('isTwoFactorAuthenticated')
|
->method('isTwoFactorAuthenticated')
|
||||||
->with($user)
|
->with($user)
|
||||||
->will($this->returnValue(false));
|
->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);
|
$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() {
|
public function testLoginWithoutPassedCsrfCheckAndNotLoggedIn() {
|
||||||
|
|
Loading…
Reference in New Issue