mirror of
https://github.com/flarum/core.git
synced 2025-07-27 11:40:24 +02:00
Remember checkbox (#1075)
* Add session option to Rememberer class * Update session login function to allow send additional data * Add Remember me checkbox * Cleanup login modal
This commit is contained in:
committed by
Toby Zerner
parent
7af4b8d45f
commit
06c32b668d
6
js/admin/dist/app.js
vendored
6
js/admin/dist/app.js
vendored
@@ -22552,13 +22552,13 @@ System.register('flarum/Session', [], function (_export, _context) {
|
|||||||
|
|
||||||
babelHelpers.createClass(Session, [{
|
babelHelpers.createClass(Session, [{
|
||||||
key: 'login',
|
key: 'login',
|
||||||
value: function login(identification, password) {
|
value: function login(data) {
|
||||||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||||
|
|
||||||
return app.request(babelHelpers.extends({
|
return app.request(babelHelpers.extends({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: app.forum.attribute('baseUrl') + '/login',
|
url: app.forum.attribute('baseUrl') + '/login',
|
||||||
data: { identification: identification, password: password }
|
data: data
|
||||||
}, options));
|
}, options));
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
42
js/forum/dist/app.js
vendored
42
js/forum/dist/app.js
vendored
@@ -22983,6 +22983,12 @@ System.register('flarum/components/ForgotPasswordModal', ['flarum/components/Mod
|
|||||||
onchange: m.withAttr('value', this.email),
|
onchange: m.withAttr('value', this.email),
|
||||||
disabled: this.loading })
|
disabled: this.loading })
|
||||||
),
|
),
|
||||||
|
m(
|
||||||
|
'label',
|
||||||
|
{ className: 'checkbox' },
|
||||||
|
m('input', { name: 'remember', type: 'checkbox', bidi: this.remember, disabled: this.loading }),
|
||||||
|
app.translator.trans('core.forum.log_in.remember_me_text')
|
||||||
|
),
|
||||||
m(
|
m(
|
||||||
'div',
|
'div',
|
||||||
{ className: 'Form-group' },
|
{ className: 'Form-group' },
|
||||||
@@ -23876,11 +23882,11 @@ System.register('flarum/components/LogInModal', ['flarum/components/Modal', 'fla
|
|||||||
babelHelpers.get(LogInModal.prototype.__proto__ || Object.getPrototypeOf(LogInModal.prototype), 'init', this).call(this);
|
babelHelpers.get(LogInModal.prototype.__proto__ || Object.getPrototypeOf(LogInModal.prototype), 'init', this).call(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value of the email input.
|
* The value of the identification input.
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
*/
|
*/
|
||||||
this.email = m.prop(this.props.email || '');
|
this.identification = m.prop(this.props.identification || '');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value of the password input.
|
* The value of the password input.
|
||||||
@@ -23888,6 +23894,13 @@ System.register('flarum/components/LogInModal', ['flarum/components/Modal', 'fla
|
|||||||
* @type {Function}
|
* @type {Function}
|
||||||
*/
|
*/
|
||||||
this.password = m.prop(this.props.password || '');
|
this.password = m.prop(this.props.password || '');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value of the remember me input.
|
||||||
|
*
|
||||||
|
* @type {Function}
|
||||||
|
*/
|
||||||
|
this.remember = m.prop(this.props.remember && true);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'className',
|
key: 'className',
|
||||||
@@ -23912,8 +23925,8 @@ System.register('flarum/components/LogInModal', ['flarum/components/Modal', 'fla
|
|||||||
m(
|
m(
|
||||||
'div',
|
'div',
|
||||||
{ className: 'Form-group' },
|
{ className: 'Form-group' },
|
||||||
m('input', { className: 'FormControl', name: 'email', type: 'text', placeholder: extractText(app.translator.trans('core.forum.log_in.username_or_email_placeholder')),
|
m('input', { className: 'FormControl', name: 'identification', type: 'text', placeholder: extractText(app.translator.trans('core.forum.log_in.username_or_email_placeholder')),
|
||||||
bidi: this.email,
|
bidi: this.identification,
|
||||||
disabled: this.loading })
|
disabled: this.loading })
|
||||||
),
|
),
|
||||||
m(
|
m(
|
||||||
@@ -23956,7 +23969,7 @@ System.register('flarum/components/LogInModal', ['flarum/components/Modal', 'fla
|
|||||||
}, {
|
}, {
|
||||||
key: 'forgotPassword',
|
key: 'forgotPassword',
|
||||||
value: function forgotPassword() {
|
value: function forgotPassword() {
|
||||||
var email = this.email();
|
var email = this.identification();
|
||||||
var props = email.indexOf('@') !== -1 ? { email: email } : undefined;
|
var props = email.indexOf('@') !== -1 ? { email: email } : undefined;
|
||||||
|
|
||||||
app.modal.show(new ForgotPasswordModal(props));
|
app.modal.show(new ForgotPasswordModal(props));
|
||||||
@@ -23965,15 +23978,15 @@ System.register('flarum/components/LogInModal', ['flarum/components/Modal', 'fla
|
|||||||
key: 'signUp',
|
key: 'signUp',
|
||||||
value: function signUp() {
|
value: function signUp() {
|
||||||
var props = { password: this.password() };
|
var props = { password: this.password() };
|
||||||
var email = this.email();
|
var identification = this.identification();
|
||||||
props[email.indexOf('@') !== -1 ? 'email' : 'username'] = email;
|
props[identification.indexOf('@') !== -1 ? 'email' : 'username'] = identification;
|
||||||
|
|
||||||
app.modal.show(new SignUpModal(props));
|
app.modal.show(new SignUpModal(props));
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'onready',
|
key: 'onready',
|
||||||
value: function onready() {
|
value: function onready() {
|
||||||
this.$('[name=' + (this.email() ? 'password' : 'email') + ']').select();
|
this.$('[name=' + (this.identification() ? 'password' : 'identification') + ']').select();
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'onsubmit',
|
key: 'onsubmit',
|
||||||
@@ -23982,10 +23995,11 @@ System.register('flarum/components/LogInModal', ['flarum/components/Modal', 'fla
|
|||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
var email = this.email();
|
var identification = this.identification();
|
||||||
var password = this.password();
|
var password = this.password();
|
||||||
|
var remember = this.remember();
|
||||||
|
|
||||||
app.session.login(email, password, { errorHandler: this.onerror.bind(this) }).then(function () {
|
app.session.login({ identification: identification, password: password, remember: remember }, { errorHandler: this.onerror.bind(this) }).then(function () {
|
||||||
return window.location.reload();
|
return window.location.reload();
|
||||||
}, this.loaded.bind(this));
|
}, this.loaded.bind(this));
|
||||||
}
|
}
|
||||||
@@ -27947,7 +27961,7 @@ System.register('flarum/components/SignUpModal', ['flarum/components/Modal', 'fl
|
|||||||
key: 'logIn',
|
key: 'logIn',
|
||||||
value: function logIn() {
|
value: function logIn() {
|
||||||
var props = {
|
var props = {
|
||||||
email: this.email() || this.username(),
|
identification: this.email() || this.username(),
|
||||||
password: this.password()
|
password: this.password()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -30494,13 +30508,13 @@ System.register('flarum/Session', [], function (_export, _context) {
|
|||||||
|
|
||||||
babelHelpers.createClass(Session, [{
|
babelHelpers.createClass(Session, [{
|
||||||
key: 'login',
|
key: 'login',
|
||||||
value: function login(identification, password) {
|
value: function login(data) {
|
||||||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||||
|
|
||||||
return app.request(babelHelpers.extends({
|
return app.request(babelHelpers.extends({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: app.forum.attribute('baseUrl') + '/login',
|
url: app.forum.attribute('baseUrl') + '/login',
|
||||||
data: { identification: identification, password: password }
|
data: data
|
||||||
}, options));
|
}, options));
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
@@ -11,7 +11,7 @@ import extractText from 'flarum/utils/extractText';
|
|||||||
*
|
*
|
||||||
* ### Props
|
* ### Props
|
||||||
*
|
*
|
||||||
* - `email`
|
* - `identification`
|
||||||
* - `password`
|
* - `password`
|
||||||
*/
|
*/
|
||||||
export default class LogInModal extends Modal {
|
export default class LogInModal extends Modal {
|
||||||
@@ -19,11 +19,11 @@ export default class LogInModal extends Modal {
|
|||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value of the email input.
|
* The value of the identification input.
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
*/
|
*/
|
||||||
this.email = m.prop(this.props.email || '');
|
this.identification = m.prop(this.props.identification || '');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value of the password input.
|
* The value of the password input.
|
||||||
@@ -31,6 +31,13 @@ export default class LogInModal extends Modal {
|
|||||||
* @type {Function}
|
* @type {Function}
|
||||||
*/
|
*/
|
||||||
this.password = m.prop(this.props.password || '');
|
this.password = m.prop(this.props.password || '');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value of the remember me input.
|
||||||
|
*
|
||||||
|
* @type {Function}
|
||||||
|
*/
|
||||||
|
this.remember = m.prop(this.props.remember && true);
|
||||||
}
|
}
|
||||||
|
|
||||||
className() {
|
className() {
|
||||||
@@ -48,8 +55,8 @@ export default class LogInModal extends Modal {
|
|||||||
|
|
||||||
<div className="Form Form--centered">
|
<div className="Form Form--centered">
|
||||||
<div className="Form-group">
|
<div className="Form-group">
|
||||||
<input className="FormControl" name="email" type="text" placeholder={extractText(app.translator.trans('core.forum.log_in.username_or_email_placeholder'))}
|
<input className="FormControl" name="identification" type="text" placeholder={extractText(app.translator.trans('core.forum.log_in.username_or_email_placeholder'))}
|
||||||
bidi={this.email}
|
bidi={this.identification}
|
||||||
disabled={this.loading} />
|
disabled={this.loading} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -59,6 +66,11 @@ export default class LogInModal extends Modal {
|
|||||||
disabled={this.loading} />
|
disabled={this.loading} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<label className="checkbox">
|
||||||
|
<input name="remember" type="checkbox" bidi={this.remember} disabled={this.loading} />
|
||||||
|
{app.translator.trans('core.forum.log_in.remember_me_label')}
|
||||||
|
</label>
|
||||||
|
|
||||||
<div className="Form-group">
|
<div className="Form-group">
|
||||||
{Button.component({
|
{Button.component({
|
||||||
className: 'Button Button--primary Button--block',
|
className: 'Button Button--primary Button--block',
|
||||||
@@ -90,7 +102,7 @@ export default class LogInModal extends Modal {
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
forgotPassword() {
|
forgotPassword() {
|
||||||
const email = this.email();
|
const email = this.identification();
|
||||||
const props = email.indexOf('@') !== -1 ? {email} : undefined;
|
const props = email.indexOf('@') !== -1 ? {email} : undefined;
|
||||||
|
|
||||||
app.modal.show(new ForgotPasswordModal(props));
|
app.modal.show(new ForgotPasswordModal(props));
|
||||||
@@ -104,14 +116,14 @@ export default class LogInModal extends Modal {
|
|||||||
*/
|
*/
|
||||||
signUp() {
|
signUp() {
|
||||||
const props = {password: this.password()};
|
const props = {password: this.password()};
|
||||||
const email = this.email();
|
const identification = this.identification();
|
||||||
props[email.indexOf('@') !== -1 ? 'email' : 'username'] = email;
|
props[identification.indexOf('@') !== -1 ? 'email' : 'username'] = identification;
|
||||||
|
|
||||||
app.modal.show(new SignUpModal(props));
|
app.modal.show(new SignUpModal(props));
|
||||||
}
|
}
|
||||||
|
|
||||||
onready() {
|
onready() {
|
||||||
this.$('[name=' + (this.email() ? 'password' : 'email') + ']').select();
|
this.$('[name=' + (this.identification() ? 'password' : 'identification') + ']').select();
|
||||||
}
|
}
|
||||||
|
|
||||||
onsubmit(e) {
|
onsubmit(e) {
|
||||||
@@ -119,10 +131,12 @@ export default class LogInModal extends Modal {
|
|||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
const email = this.email();
|
const identification = this.identification();
|
||||||
const password = this.password();
|
const password = this.password();
|
||||||
|
const remember = this.remember();
|
||||||
|
|
||||||
app.session.login(email, password, {errorHandler: this.onerror.bind(this)}).then(
|
app.session.login({identification, password, remember}, {errorHandler: this.onerror.bind(this)})
|
||||||
|
.then(
|
||||||
() => window.location.reload(),
|
() => window.location.reload(),
|
||||||
this.loaded.bind(this)
|
this.loaded.bind(this)
|
||||||
);
|
);
|
||||||
|
@@ -116,7 +116,7 @@ export default class SignUpModal extends Modal {
|
|||||||
*/
|
*/
|
||||||
logIn() {
|
logIn() {
|
||||||
const props = {
|
const props = {
|
||||||
email: this.email() || this.username(),
|
identification: this.email() || this.username(),
|
||||||
password: this.password()
|
password: this.password()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -30,11 +30,11 @@ export default class Session {
|
|||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
login(identification, password, options = {}) {
|
login(data, options = {}) {
|
||||||
return app.request(Object.assign({
|
return app.request(Object.assign({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: app.forum.attribute('baseUrl') + '/login',
|
url: app.forum.attribute('baseUrl') + '/login',
|
||||||
data: {identification, password}
|
data
|
||||||
}, options));
|
}, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -66,7 +66,8 @@ class LogInController implements ControllerInterface
|
|||||||
public function handle(Request $request)
|
public function handle(Request $request)
|
||||||
{
|
{
|
||||||
$actor = $request->getAttribute('actor');
|
$actor = $request->getAttribute('actor');
|
||||||
$params = array_only($request->getParsedBody(), ['identification', 'password']);
|
$body = $request->getParsedBody();
|
||||||
|
$params = array_only($body, ['identification', 'password']);
|
||||||
|
|
||||||
$response = $this->apiClient->send(TokenController::class, $actor, [], $params);
|
$response = $this->apiClient->send(TokenController::class, $actor, [], $params);
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ class LogInController implements ControllerInterface
|
|||||||
|
|
||||||
event(new UserLoggedIn($this->users->findOrFail($data->userId), $token));
|
event(new UserLoggedIn($this->users->findOrFail($data->userId), $token));
|
||||||
|
|
||||||
$response = $this->rememberer->remember($response, $token);
|
$response = $this->rememberer->remember($response, $token, ! array_get($body, 'remember'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
@@ -19,17 +19,20 @@ class Rememberer
|
|||||||
{
|
{
|
||||||
protected $cookieName = 'flarum_remember';
|
protected $cookieName = 'flarum_remember';
|
||||||
|
|
||||||
public function remember(ResponseInterface $response, AccessToken $token)
|
public function remember(ResponseInterface $response, AccessToken $token, $session = false)
|
||||||
{
|
{
|
||||||
$token->lifetime = 60 * 60 * 24 * 14;
|
$cookie = $this->createCookie()->withValue($token->id);
|
||||||
|
|
||||||
|
if (! $session) {
|
||||||
|
$lifetime = 60 * 60 * 24 * 14;
|
||||||
|
|
||||||
|
$token->lifetime = $lifetime;
|
||||||
$token->save();
|
$token->save();
|
||||||
|
|
||||||
return FigResponseCookies::set(
|
$cookie = $cookie->withMaxAge($lifetime);
|
||||||
$response,
|
}
|
||||||
$this->createCookie()
|
|
||||||
->withValue($token->id)
|
return FigResponseCookies::set($response, $cookie);
|
||||||
->withMaxAge(14 * 24 * 60 * 60)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rememberUser(ResponseInterface $response, $userId)
|
public function rememberUser(ResponseInterface $response, $userId)
|
||||||
|
Reference in New Issue
Block a user