Skip to content

Commit 1498b5d

Browse files
authored
Merge pull request #56343 from nextcloud/feat/add-rememberme-checkbox
Add rememberme checkbox
2 parents 2d0c5cf + 907fb19 commit 1498b5d

File tree

11 files changed

+101
-60
lines changed

11 files changed

+101
-60
lines changed

core/Controller/LoginController.php

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

146+
$this->initialState->provideInitialState(
147+
'loginCanRememberme',
148+
$this->config->getSystemValueInt('remember_login_cookie_lifetime', 60 * 60 * 24 * 15) > 0
149+
);
150+
146151
if (!empty($redirect_url)) {
147152
[$url, ] = explode('?', $redirect_url);
148153
if ($url !== $this->urlGenerator->linkToRoute('core.login.logout')) {
@@ -287,6 +292,7 @@ public function tryLogin(
287292
ITrustedDomainHelper $trustedDomainHelper,
288293
string $user = '',
289294
string $password = '',
295+
bool $rememberme = false,
290296
?string $redirect_url = null,
291297
string $timezone = '',
292298
string $timezone_offset = '',
@@ -339,9 +345,10 @@ public function tryLogin(
339345
$this->request,
340346
$user,
341347
$password,
348+
$rememberme,
342349
$redirect_url,
343350
$timezone,
344-
$timezone_offset
351+
$timezone_offset,
345352
);
346353
$result = $loginChain->process($data);
347354
if (!$result->isSuccess()) {

core/src/components/login/LoginForm.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@
8484
data-login-form-input-password
8585
required />
8686

87+
<NcCheckboxRadioSwitch
88+
v-if="remembermeAllowed"
89+
id="rememberme"
90+
ref="rememberme"
91+
name="rememberme"
92+
value="1"
93+
:checked.sync="rememberme"
94+
data-login-form-input-rememberme>
95+
{{ t('core', 'Remember me') }}
96+
</NcCheckboxRadioSwitch>
97+
8798
<LoginButton data-login-form-submit :loading="loading" />
8899

89100
<input
@@ -117,6 +128,7 @@ import { loadState } from '@nextcloud/initial-state'
117128
import { translate as t } from '@nextcloud/l10n'
118129
import { generateUrl, imagePath } from '@nextcloud/router'
119130
import debounce from 'debounce'
131+
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
120132
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
121133
import NcPasswordField from '@nextcloud/vue/components/NcPasswordField'
122134
import NcTextField from '@nextcloud/vue/components/NcTextField'
@@ -128,6 +140,7 @@ export default {
128140
129141
components: {
130142
LoginButton,
143+
NcCheckboxRadioSwitch,
131144
NcPasswordField,
132145
NcTextField,
133146
NcNoteCard,
@@ -166,6 +179,11 @@ export default {
166179
default: true,
167180
},
168181
182+
remembermeAllowed: {
183+
type: Boolean,
184+
default: true,
185+
},
186+
169187
directLogin: {
170188
type: Boolean,
171189
default: false,
@@ -200,6 +218,7 @@ export default {
200218
loading: false,
201219
user: props.username,
202220
password: '',
221+
rememberme: ['1'],
203222
visible: false,
204223
}
205224
},

core/src/views/Login.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
:errors="errors"
1717
:throttle-delay="throttleDelay"
1818
:auto-complete-allowed="autoCompleteAllowed"
19+
:rememberme-allowed="remembermeAllowed"
1920
:email-states="emailStates"
2021
@submit="loading = true" />
2122
<NcButton
@@ -148,6 +149,7 @@ export default {
148149
canResetPassword: loadState('core', 'loginCanResetPassword', false),
149150
resetPasswordLink: loadState('core', 'loginResetPasswordLink', ''),
150151
autoCompleteAllowed: loadState('core', 'loginAutocomplete', true),
152+
remembermeAllowed: loadState('core', 'loginCanRememberme', true),
151153
resetPasswordTarget: loadState('core', 'resetPasswordTarget', ''),
152154
resetPasswordUser: loadState('core', 'resetPasswordUser', ''),
153155
directLogin: query.direct === '1',

dist/core-common.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-common.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.

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)