Security: Form confirmations
This commit is contained in:
parent
860b2d18f4
commit
1076788add
2 changed files with 17 additions and 5 deletions
|
@ -11,13 +11,14 @@ export const CHANGE_PASSWORD_FAIL = 'CHANGE_PASSWORD_FAIL';
|
||||||
export function changeEmail(email, password) {
|
export function changeEmail(email, password) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch({ type: CHANGE_EMAIL_REQUEST, email });
|
dispatch({ type: CHANGE_EMAIL_REQUEST, email });
|
||||||
api(getState).post('/api/pleroma/change_email', {
|
return api(getState).post('/api/pleroma/change_email', {
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
dispatch({ type: CHANGE_EMAIL_SUCCESS, email, response });
|
dispatch({ type: CHANGE_EMAIL_SUCCESS, email, response });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: CHANGE_EMAIL_FAIL, email, error });
|
dispatch({ type: CHANGE_EMAIL_FAIL, email, error, skipAlert: true });
|
||||||
|
throw error;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -25,7 +26,7 @@ export function changeEmail(email, password) {
|
||||||
export function changePassword(oldPassword, newPassword, confirmation) {
|
export function changePassword(oldPassword, newPassword, confirmation) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch({ type: CHANGE_PASSWORD_REQUEST });
|
dispatch({ type: CHANGE_PASSWORD_REQUEST });
|
||||||
api(getState).post('/api/pleroma/change_password', {
|
return api(getState).post('/api/pleroma/change_password', {
|
||||||
password: oldPassword,
|
password: oldPassword,
|
||||||
new_password: newPassword,
|
new_password: newPassword,
|
||||||
new_password_confirmation: confirmation,
|
new_password_confirmation: confirmation,
|
||||||
|
|
|
@ -11,10 +11,13 @@ import {
|
||||||
TextInput,
|
TextInput,
|
||||||
} from 'soapbox/features/forms';
|
} from 'soapbox/features/forms';
|
||||||
import { changeEmail } from 'soapbox/actions/security';
|
import { changeEmail } from 'soapbox/actions/security';
|
||||||
|
import { showAlert } from 'soapbox/actions/alerts';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
heading: { id: 'column.security', defaultMessage: 'Security' },
|
heading: { id: 'column.security', defaultMessage: 'Security' },
|
||||||
submit: { id: 'security.submit', defaultMessage: 'Save changes' },
|
submit: { id: 'security.submit', defaultMessage: 'Save changes' },
|
||||||
|
updateEmailSuccess: { id: 'security.update_email.success', defaultMessage: 'Email successfully updated.' },
|
||||||
|
updateEmailFail: { id: 'security.update_email.fail', defaultMessage: 'Update email failed.' },
|
||||||
});
|
});
|
||||||
|
|
||||||
export default @connect()
|
export default @connect()
|
||||||
|
@ -27,7 +30,10 @@ class Security extends ImmutablePureComponent {
|
||||||
intl: PropTypes.object.isRequired,
|
intl: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {}
|
state = {
|
||||||
|
email: '',
|
||||||
|
password: '',
|
||||||
|
}
|
||||||
|
|
||||||
handleInputChange = e => {
|
handleInputChange = e => {
|
||||||
this.setState({ [e.target.name]: e.target.value });
|
this.setState({ [e.target.name]: e.target.value });
|
||||||
|
@ -35,7 +41,12 @@ class Security extends ImmutablePureComponent {
|
||||||
|
|
||||||
handleSubmit = e => {
|
handleSubmit = e => {
|
||||||
const { email, password } = this.state;
|
const { email, password } = this.state;
|
||||||
this.props.dispatch(changeEmail(email, password));
|
const { dispatch, intl } = this.props;
|
||||||
|
dispatch(changeEmail(email, password)).then(() => {
|
||||||
|
dispatch(showAlert('', intl.formatMessage(messages.updateEmailSuccess)));
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch(showAlert('', intl.formatMessage(messages.updateEmailFail)));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
Loading…
Reference in a new issue