Security: Form confirmations

merge-requests/45/head
Alex Gleason 2020-06-05 14:39:27 -05:00
rodzic 860b2d18f4
commit 1076788add
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 17 dodań i 5 usunięć

Wyświetl plik

@ -11,13 +11,14 @@ export const CHANGE_PASSWORD_FAIL = 'CHANGE_PASSWORD_FAIL';
export function changeEmail(email, password) {
return (dispatch, getState) => {
dispatch({ type: CHANGE_EMAIL_REQUEST, email });
api(getState).post('/api/pleroma/change_email', {
return api(getState).post('/api/pleroma/change_email', {
email,
password,
}).then(response => {
dispatch({ type: CHANGE_EMAIL_SUCCESS, email, response });
}).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) {
return (dispatch, getState) => {
dispatch({ type: CHANGE_PASSWORD_REQUEST });
api(getState).post('/api/pleroma/change_password', {
return api(getState).post('/api/pleroma/change_password', {
password: oldPassword,
new_password: newPassword,
new_password_confirmation: confirmation,

Wyświetl plik

@ -11,10 +11,13 @@ import {
TextInput,
} from 'soapbox/features/forms';
import { changeEmail } from 'soapbox/actions/security';
import { showAlert } from 'soapbox/actions/alerts';
const messages = defineMessages({
heading: { id: 'column.security', defaultMessage: 'Security' },
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()
@ -27,7 +30,10 @@ class Security extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
};
state = {}
state = {
email: '',
password: '',
}
handleInputChange = e => {
this.setState({ [e.target.name]: e.target.value });
@ -35,7 +41,12 @@ class Security extends ImmutablePureComponent {
handleSubmit = e => {
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() {