Skip to content

Commit 3b51795

Browse files
authored
Merge pull request #56421 from nextcloud/backport/56343/stable31
[stable31] Add rememberme checkbox
2 parents c2d06d3 + e093212 commit 3b51795

File tree

10 files changed

+113
-62
lines changed

10 files changed

+113
-62
lines changed

build/integration/features/bootstrap/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function aNewBrowserSessionIsStarted($remember = false) {
220220
'form_params' => [
221221
'user' => 'user0',
222222
'password' => '123456',
223-
'remember_login' => $remember ? '1' : '0',
223+
'rememberme' => $remember ? '1' : '0',
224224
'requesttoken' => $this->requestToken,
225225
],
226226
'cookies' => $this->cookieJar,

core/Controller/LoginController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ public function showLoginForm(?string $user = null, ?string $redirect_url = null
141141
$this->config->getSystemValue('login_form_autocomplete', true) === true
142142
);
143143

144+
$this->initialState->provideInitialState(
145+
'loginCanRememberme',
146+
$this->config->getSystemValueInt('remember_login_cookie_lifetime', 60 * 60 * 24 * 15) > 0
147+
);
148+
144149
if (!empty($redirect_url)) {
145150
[$url, ] = explode('?', $redirect_url);
146151
if ($url !== $this->urlGenerator->linkToRoute('core.login.logout')) {
@@ -285,6 +290,7 @@ public function tryLogin(
285290
ITrustedDomainHelper $trustedDomainHelper,
286291
string $user = '',
287292
string $password = '',
293+
bool $rememberme = false,
288294
?string $redirect_url = null,
289295
string $timezone = '',
290296
string $timezone_offset = '',
@@ -337,9 +343,10 @@ public function tryLogin(
337343
$this->request,
338344
$user,
339345
$password,
346+
$rememberme,
340347
$redirect_url,
341348
$timezone,
342-
$timezone_offset
349+
$timezone_offset,
343350
);
344351
$result = $loginChain->process($data);
345352
if (!$result->isSuccess()) {

core/src/components/login/LoginForm.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@
7474
data-login-form-input-password
7575
required />
7676

77+
<NcCheckboxRadioSwitch v-if="remembermeAllowed"
78+
id="rememberme"
79+
ref="rememberme"
80+
name="rememberme"
81+
value="1"
82+
:checked.sync="rememberme"
83+
data-login-form-input-rememberme>
84+
{{ t('core', 'Remember me') }}
85+
</NcCheckboxRadioSwitch>
86+
7787
<LoginButton data-login-form-submit :loading="loading" />
7888

7989
<input v-if="redirectUrl"
@@ -103,6 +113,7 @@ import { translate as t } from '@nextcloud/l10n'
103113
import { generateUrl, imagePath } from '@nextcloud/router'
104114
import debounce from 'debounce'
105115
116+
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
106117
import NcPasswordField from '@nextcloud/vue/dist/Components/NcPasswordField.js'
107118
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
108119
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
@@ -115,6 +126,7 @@ export default {
115126
116127
components: {
117128
LoginButton,
129+
NcCheckboxRadioSwitch,
118130
NcPasswordField,
119131
NcTextField,
120132
NcNoteCard,
@@ -147,6 +159,10 @@ export default {
147159
type: Boolean,
148160
default: true,
149161
},
162+
remembermeAllowed: {
163+
type: Boolean,
164+
default: true,
165+
},
150166
directLogin: {
151167
type: Boolean,
152168
default: false,
@@ -180,6 +196,7 @@ export default {
180196
loading: false,
181197
user: '',
182198
password: '',
199+
rememberme: ['1'],
183200
}
184201
},
185202

core/src/views/Login.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
:errors="errors"
1616
:throttle-delay="throttleDelay"
1717
:auto-complete-allowed="autoCompleteAllowed"
18+
:rememberme-allowed="remembermeAllowed"
1819
:email-states="emailStates"
1920
@submit="loading = true" />
2021
<a v-if="canResetPassword && resetPasswordLink !== ''"
@@ -149,6 +150,7 @@ export default {
149150
canResetPassword: loadState('core', 'loginCanResetPassword', false),
150151
resetPasswordLink: loadState('core', 'loginResetPasswordLink', ''),
151152
autoCompleteAllowed: loadState('core', 'loginAutocomplete', true),
153+
remembermeAllowed: loadState('core', 'loginCanRememberme', true),
152154
resetPasswordTarget: loadState('core', 'resetPasswordTarget', ''),
153155
resetPasswordUser: loadState('core', 'resetPasswordUser', ''),
154156
directLogin: query.direct === '1',

dist/core-login.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-login.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/private/Authentication/Login/CreateSessionTokenCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ public function __construct(IConfig $config,
2626
}
2727

2828
public function process(LoginData $loginData): LoginResult {
29-
$tokenType = IToken::REMEMBER;
3029
if ($this->config->getSystemValueInt('remember_login_cookie_lifetime', 60 * 60 * 24 * 15) === 0) {
3130
$loginData->setRememberLogin(false);
31+
}
32+
if ($loginData->isRememberLogin()) {
33+
$tokenType = IToken::REMEMBER;
34+
} else {
3235
$tokenType = IToken::DO_NOT_REMEMBER;
3336
}
3437

lib/private/Authentication/Login/LoginData.php

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,25 @@
66
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
77
* SPDX-License-Identifier: AGPL-3.0-or-later
88
*/
9+
910
namespace OC\Authentication\Login;
1011

1112
use OCP\IRequest;
1213
use OCP\IUser;
1314

1415
class LoginData {
15-
/** @var IRequest */
16-
private $request;
17-
18-
/** @var string */
19-
private $username;
20-
21-
/** @var string */
22-
private $password;
23-
24-
/** @var string */
25-
private $redirectUrl;
26-
27-
/** @var string */
28-
private $timeZone;
29-
30-
/** @var string */
31-
private $timeZoneOffset;
32-
3316
/** @var IUser|false|null */
3417
private $user = null;
3518

36-
/** @var bool */
37-
private $rememberLogin = true;
38-
39-
public function __construct(IRequest $request,
40-
string $username,
41-
?string $password,
42-
?string $redirectUrl = null,
43-
string $timeZone = '',
44-
string $timeZoneOffset = '') {
45-
$this->request = $request;
46-
$this->username = $username;
47-
$this->password = $password;
48-
$this->redirectUrl = $redirectUrl;
49-
$this->timeZone = $timeZone;
50-
$this->timeZoneOffset = $timeZoneOffset;
19+
public function __construct(
20+
private IRequest $request,
21+
private string $username,
22+
private ?string $password,
23+
private bool $rememberLogin = true,
24+
private ?string $redirectUrl = null,
25+
private string $timeZone = '',
26+
private string $timeZoneOffset = '',
27+
) {
5128
}
5229

5330
public function getRequest(): IRequest {
@@ -81,7 +58,7 @@ public function getTimeZoneOffset(): string {
8158
/**
8259
* @param IUser|false|null $user
8360
*/
84-
public function setUser($user) {
61+
public function setUser($user): void {
8562
$this->user = $user;
8663
}
8764

0 commit comments

Comments
 (0)