Merge pull request #2561 from nextcloud/save-timezone-on-login
Save the timezone on login again
This commit is contained in:
commit
e3b2832ee1
4 changed files with 24 additions and 4 deletions
|
@ -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,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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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…
Reference in a new issue