mirror of
https://github.com/flarum/core.git
synced 2025-08-11 10:55:47 +02:00
update: SignUpModal
This commit is contained in:
committed by
Franz Liedke
parent
cc91244f1a
commit
edeaa5855c
@@ -1,3 +1,4 @@
|
|||||||
|
import Stream from 'mithril-stream';
|
||||||
import Modal from '../../common/components/Modal';
|
import Modal from '../../common/components/Modal';
|
||||||
import LogInModal from './LogInModal';
|
import LogInModal from './LogInModal';
|
||||||
import Button from '../../common/components/Button';
|
import Button from '../../common/components/Button';
|
||||||
@@ -16,29 +17,27 @@ import ItemList from '../../common/utils/ItemList';
|
|||||||
* - `token` An email token to sign up with.
|
* - `token` An email token to sign up with.
|
||||||
*/
|
*/
|
||||||
export default class SignUpModal extends Modal {
|
export default class SignUpModal extends Modal {
|
||||||
init() {
|
oninit(vnode) {
|
||||||
super.init();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value of the username input.
|
* The value of the username input.
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
*/
|
*/
|
||||||
this.username = m.prop(this.props.username || '');
|
this.username = Stream(vnode.attrs.username || '');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value of the email input.
|
* The value of the email input.
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
*/
|
*/
|
||||||
this.email = m.prop(this.props.email || '');
|
this.email = Stream(vnode.attrs.email || '');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value of the password input.
|
* The value of the password input.
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
*/
|
*/
|
||||||
this.password = m.prop(this.props.password || '');
|
this.password = Stream(vnode.attrs.password || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
className() {
|
className() {
|
||||||
@@ -49,19 +48,19 @@ export default class SignUpModal extends Modal {
|
|||||||
return app.translator.trans('core.forum.sign_up.title');
|
return app.translator.trans('core.forum.sign_up.title');
|
||||||
}
|
}
|
||||||
|
|
||||||
content() {
|
content(attrs) {
|
||||||
return [<div className="Modal-body">{this.body()}</div>, <div className="Modal-footer">{this.footer()}</div>];
|
return [<div className="Modal-body">{this.body(attrs)}</div>, <div className="Modal-footer">{this.footer()}</div>];
|
||||||
}
|
}
|
||||||
|
|
||||||
isProvided(field) {
|
isProvided(field, attrs) {
|
||||||
return this.props.provided && this.props.provided.indexOf(field) !== -1;
|
return attrs.provided && attrs.provided.indexOf(field) !== -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
body() {
|
body(attrs) {
|
||||||
return [this.props.token ? '' : <LogInButtons />, <div className="Form Form--centered">{this.fields().toArray()}</div>];
|
return [attrs.token ? '' : <LogInButtons />, <div className="Form Form--centered">{this.fields(attrs).toArray()}</div>];
|
||||||
}
|
}
|
||||||
|
|
||||||
fields() {
|
fields(attrs) {
|
||||||
const items = new ItemList();
|
const items = new ItemList();
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
@@ -73,8 +72,8 @@ export default class SignUpModal extends Modal {
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder={extractText(app.translator.trans('core.forum.sign_up.username_placeholder'))}
|
placeholder={extractText(app.translator.trans('core.forum.sign_up.username_placeholder'))}
|
||||||
value={this.username()}
|
value={this.username()}
|
||||||
onchange={m.withAttr('value', this.username)}
|
bidi={this.username}
|
||||||
disabled={this.loading || this.isProvided('username')}
|
disabled={this.loading || this.isProvided('username', attrs)}
|
||||||
/>
|
/>
|
||||||
</div>,
|
</div>,
|
||||||
30
|
30
|
||||||
@@ -89,14 +88,14 @@ export default class SignUpModal extends Modal {
|
|||||||
type="email"
|
type="email"
|
||||||
placeholder={extractText(app.translator.trans('core.forum.sign_up.email_placeholder'))}
|
placeholder={extractText(app.translator.trans('core.forum.sign_up.email_placeholder'))}
|
||||||
value={this.email()}
|
value={this.email()}
|
||||||
onchange={m.withAttr('value', this.email)}
|
bidi={this.email}
|
||||||
disabled={this.loading || this.isProvided('email')}
|
disabled={this.loading || this.isProvided('email', attrs)}
|
||||||
/>
|
/>
|
||||||
</div>,
|
</div>,
|
||||||
20
|
20
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!this.props.token) {
|
if (!attrs.token) {
|
||||||
items.add(
|
items.add(
|
||||||
'password',
|
'password',
|
||||||
<div className="Form-group">
|
<div className="Form-group">
|
||||||
@@ -106,7 +105,7 @@ export default class SignUpModal extends Modal {
|
|||||||
type="password"
|
type="password"
|
||||||
placeholder={extractText(app.translator.trans('core.forum.sign_up.password_placeholder'))}
|
placeholder={extractText(app.translator.trans('core.forum.sign_up.password_placeholder'))}
|
||||||
value={this.password()}
|
value={this.password()}
|
||||||
onchange={m.withAttr('value', this.password)}
|
bidi={this.password}
|
||||||
disabled={this.loading}
|
disabled={this.loading}
|
||||||
/>
|
/>
|
||||||
</div>,
|
</div>,
|
||||||
@@ -148,8 +147,8 @@ export default class SignUpModal extends Modal {
|
|||||||
app.modal.show(LogInModal, props);
|
app.modal.show(LogInModal, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
onready() {
|
onready(attrs) {
|
||||||
if (this.props.username && !this.props.email) {
|
if (attrs.username && !attrs.email) {
|
||||||
this.$('[name=email]').select();
|
this.$('[name=email]').select();
|
||||||
} else {
|
} else {
|
||||||
this.$('[name=username]').select();
|
this.$('[name=username]').select();
|
||||||
@@ -161,13 +160,13 @@ export default class SignUpModal extends Modal {
|
|||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
const data = this.submitData();
|
const body = this.submitData(attrs);
|
||||||
|
|
||||||
app
|
app
|
||||||
.request({
|
.request({
|
||||||
url: app.forum.attribute('baseUrl') + '/register',
|
url: app.forum.attribute('baseUrl') + '/register',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data,
|
body,
|
||||||
errorHandler: this.onerror.bind(this),
|
errorHandler: this.onerror.bind(this),
|
||||||
})
|
})
|
||||||
.then(() => window.location.reload(), this.loaded.bind(this));
|
.then(() => window.location.reload(), this.loaded.bind(this));
|
||||||
@@ -179,14 +178,14 @@ export default class SignUpModal extends Modal {
|
|||||||
* @return {Object}
|
* @return {Object}
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
submitData() {
|
submitData(attrs) {
|
||||||
const data = {
|
const data = {
|
||||||
username: this.username(),
|
username: this.username(),
|
||||||
email: this.email(),
|
email: this.email(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.props.token) {
|
if (attrs.token) {
|
||||||
data.token = this.props.token;
|
data.token = attrs.token;
|
||||||
} else {
|
} else {
|
||||||
data.password = this.password();
|
data.password = this.password();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user