Show login modal when starting a discussion as a guest

This commit is contained in:
Toby Zerner 2015-05-04 10:44:03 +09:30
parent 60900f4837
commit 7638571b82
4 changed files with 13 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import mixin from 'flarum/utils/mixin';
import DiscussionList from 'flarum/components/discussion-list'; import DiscussionList from 'flarum/components/discussion-list';
import WelcomeHero from 'flarum/components/welcome-hero'; import WelcomeHero from 'flarum/components/welcome-hero';
import ComposerDiscussion from 'flarum/components/composer-discussion'; import ComposerDiscussion from 'flarum/components/composer-discussion';
import LoginModal from 'flarum/components/login-modal';
import SelectInput from 'flarum/components/select-input'; import SelectInput from 'flarum/components/select-input';
import ActionButton from 'flarum/components/action-button'; import ActionButton from 'flarum/components/action-button';
@ -124,7 +125,10 @@ export default class IndexPage extends Component {
app.composer.load(new ComposerDiscussion({ user: app.session.user() })); app.composer.load(new ComposerDiscussion({ user: app.session.user() }));
app.composer.show(); app.composer.show();
} else { } else {
// signup app.modal.show(new LoginModal({
message: 'You must be logged in to do that.',
callback: this.newDiscussion.bind(this)
}));
} }
} }

View File

@ -17,6 +17,7 @@ export default class LoginModal extends Component {
m('button.btn.btn-icon.btn-link.close.back-control', {onclick: app.modal.close.bind(app.modal)}, icon('times')), m('button.btn.btn-icon.btn-link.close.back-control', {onclick: app.modal.close.bind(app.modal)}, icon('times')),
m('form', {onsubmit: this.login.bind(this)}, [ m('form', {onsubmit: this.login.bind(this)}, [
m('div.modal-header', m('h3.title-control', 'Log In')), m('div.modal-header', m('h3.title-control', 'Log In')),
this.props.message ? m('div.modal-alert.alert', this.props.message) : '',
m('div.modal-body', [ m('div.modal-body', [
m('div.form-centered', [ m('div.form-centered', [
m('div.form-group', [ m('div.form-group', [
@ -47,8 +48,9 @@ export default class LoginModal extends Component {
login(e) { login(e) {
e.preventDefault(); e.preventDefault();
this.loading(true); this.loading(true);
app.session.login(this.email(), this.password()).then(function() { app.session.login(this.email(), this.password()).then(() => {
app.modal.close(); app.modal.close();
this.props.callback && this.props.callback();
}, (response) => { }, (response) => {
this.loading(false); this.loading(false);
m.redraw(); m.redraw();

View File

@ -16,13 +16,14 @@ export default class Modal extends Component {
} }
show(component) { show(component) {
clearTimeout(this.hideTimeout);
this.component = component; this.component = component;
m.redraw(true); m.redraw(true);
this.$().modal('show'); this.$().modal('show');
} }
close() { close() {
this.$().modal('hide'); this.hideTimeout = setTimeout(() => this.$().modal('hide'));
} }
destroy() { destroy() {

View File

@ -8,6 +8,9 @@
opacity: 0.9; opacity: 0.9;
} }
} }
.modal-alert {
text-align: center;
}
.modal-body { .modal-body {
background-color: @fl-body-secondary-color; background-color: @fl-body-secondary-color;
padding: 25px; padding: 25px;