mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 06:24:53 +08:00
Roughly implement change password/email, delete account modals
This commit is contained in:
parent
5a266ed305
commit
b6be2cddab
44
framework/core/js/forum/src/components/change-email-modal.js
Normal file
44
framework/core/js/forum/src/components/change-email-modal.js
Normal file
@ -0,0 +1,44 @@
|
||||
import FormModal from 'flarum/components/form-modal';
|
||||
import Alert from 'flarum/components/alert';
|
||||
|
||||
export default class ChangeEmailModal extends FormModal {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.email = m.prop(app.session.user().email());
|
||||
}
|
||||
|
||||
view() {
|
||||
return super.view({
|
||||
className: 'modal-sm change-email-modal',
|
||||
title: 'Change Email',
|
||||
body: [
|
||||
m('div.form-group', [
|
||||
m('input.form-control[type=email][name=email][placeholder=Email]', {value: this.email(), onchange: m.withAttr('value', this.email)})
|
||||
]),
|
||||
m('div.form-group', [
|
||||
m('button.btn.btn-primary.btn-block[type=submit]', 'Save Changes')
|
||||
])
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
onsubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (this.email() === app.session.user().email()) {
|
||||
this.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
this.loading(true);
|
||||
app.session.user().save({ email: this.email() }).then(() => {
|
||||
this.hide();
|
||||
}, response => {
|
||||
this.loading(false);
|
||||
this.alert = new Alert({ type: 'warning', message: response.errors.map((error, k) => [error.detail, k < response.errors.length - 1 ? m('br') : '']) });
|
||||
m.redraw();
|
||||
this.$('[name='+response.errors[0].path+']').select();
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
import FormModal from 'flarum/components/form-modal';
|
||||
|
||||
export default class ChangePasswordModal extends FormModal {
|
||||
view() {
|
||||
return super.view({
|
||||
className: 'modal-sm change-password-modal',
|
||||
title: 'Change Password',
|
||||
body: [
|
||||
m('p.help-text', 'Click the button below and check your email for a link to change your password.'),
|
||||
m('div.form-group', [
|
||||
m('button.btn.btn-primary.btn-block[type=submit]', 'Send Password Reset Email')
|
||||
])
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
onsubmit(e) {
|
||||
e.preventDefault();
|
||||
this.loading(true);
|
||||
|
||||
m.request({
|
||||
method: 'POST',
|
||||
url: app.config['api_url']+'/forgot',
|
||||
data: {email: app.session.user().email()},
|
||||
background: true
|
||||
}).then(response => {
|
||||
this.hide();
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
import FormModal from 'flarum/components/form-modal';
|
||||
|
||||
export default class DeleteAccountModal extends FormModal {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.confirmation = m.prop();
|
||||
}
|
||||
|
||||
view() {
|
||||
return super.view({
|
||||
className: 'modal-sm change-password-modal',
|
||||
title: 'Delete Account',
|
||||
body: [
|
||||
m('p.help-text', 'Hold up there skippy! If you delete your account, there\'s no going back. All of your posts will be kept, but no longer associated with your account.'),
|
||||
m('div.form-group', [
|
||||
m('input.form-control[name=confirm][placeholder=Type "DELETE" to proceed]', {oninput: m.withAttr('value', this.confirmation)})
|
||||
]),
|
||||
m('div.form-group', [
|
||||
m('button.btn.btn-primary.btn-block[type=submit]', {disabled: this.loading() || this.confirmation() != 'DELETE'}, 'Delete Account')
|
||||
])
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
onsubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (this.confirmation() !== 'DELETE') return;
|
||||
|
||||
this.loading(true);
|
||||
app.session.user().delete().then(() => app.session.logout());
|
||||
}
|
||||
}
|
@ -4,6 +4,9 @@ import SwitchInput from 'flarum/components/switch-input';
|
||||
import ActionButton from 'flarum/components/action-button';
|
||||
import FieldSet from 'flarum/components/field-set';
|
||||
import NotificationGrid from 'flarum/components/notification-grid';
|
||||
import ChangePasswordModal from 'flarum/components/change-password-modal';
|
||||
import ChangeEmailModal from 'flarum/components/change-email-modal';
|
||||
import DeleteAccountModal from 'flarum/components/delete-account-modal';
|
||||
import listItems from 'flarum/helpers/list-items';
|
||||
import icon from 'flarum/helpers/icon';
|
||||
|
||||
@ -62,21 +65,24 @@ export default class SettingsPage extends UserPage {
|
||||
items.add('changePassword',
|
||||
ActionButton.component({
|
||||
label: 'Change Password',
|
||||
className: 'btn btn-default'
|
||||
className: 'btn btn-default',
|
||||
onclick: () => app.modal.show(new ChangePasswordModal())
|
||||
})
|
||||
);
|
||||
|
||||
items.add('changeEmail',
|
||||
ActionButton.component({
|
||||
label: 'Change Email',
|
||||
className: 'btn btn-default'
|
||||
className: 'btn btn-default',
|
||||
onclick: () => app.modal.show(new ChangeEmailModal())
|
||||
})
|
||||
);
|
||||
|
||||
items.add('deleteAccount',
|
||||
ActionButton.component({
|
||||
label: 'Delete Account',
|
||||
className: 'btn btn-default btn-danger'
|
||||
className: 'btn btn-default btn-danger',
|
||||
onclick: () => app.modal.show(new DeleteAccountModal())
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -214,7 +214,7 @@ class CoreServiceProvider extends ServiceProvider
|
||||
});
|
||||
|
||||
// Allow a user to edit their own account.
|
||||
User::grantPermission('edit', function ($grant, $user) {
|
||||
User::grantPermission(['edit', 'delete'], function ($grant, $user) {
|
||||
$grant->where('id', $user->id);
|
||||
});
|
||||
|
||||
|
@ -38,9 +38,9 @@ class EmailConfirmationMailer
|
||||
'url' => route('flarum.forum.confirm', ['id' => $user->id, 'token' => $user->confirmation_token])
|
||||
];
|
||||
|
||||
$this->mailer->send(['text' => 'flarum::emails.confirm'], $data, function ($message) use ($user, $forumTitle) {
|
||||
$this->mailer->send(['text' => 'flarum::emails.confirm'], $data, function ($message) use ($user) {
|
||||
$message->to($user->email);
|
||||
$message->subject('['.$forumTitle.'] Email Address Confirmation');
|
||||
$message->subject('Email Address Confirmation');
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,9 @@ class LoginWithCookie
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (($token = $request->cookie('flarum_remember')) &&
|
||||
($accessToken = AccessToken::where('id', $token)->first())) {
|
||||
$this->actor->setUser($user = $accessToken->user);
|
||||
($accessToken = AccessToken::where('id', $token)->first()) &&
|
||||
($user = $accessToken->user)) {
|
||||
$this->actor->setUser($user);
|
||||
|
||||
$user->updateLastSeen()->save();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user