- debugged features/security

- added deactivateAccount method to actions/auth
- successful deactivation logs user out
This commit is contained in:
crockwave 2020-06-28 10:51:55 -05:00
parent 8827b5ffd6
commit a2bd359c76
2 changed files with 22 additions and 0 deletions

View file

@ -19,6 +19,10 @@ export const CHANGE_EMAIL_REQUEST = 'CHANGE_EMAIL_REQUEST';
export const CHANGE_EMAIL_SUCCESS = 'CHANGE_EMAIL_SUCCESS';
export const CHANGE_EMAIL_FAIL = 'CHANGE_EMAIL_FAIL';
export const DEACTIVATE_ACCOUNT_REQUEST = 'DEACTIVATE_ACCOUNT_REQUEST';
export const DEACTIVATE_ACCOUNT_SUCCESS = 'DEACTIVATE_ACCOUNT_SUCCESS';
export const DEACTIVATE_ACCOUNT_FAIL = 'DEACTIVATE_ACCOUNT_FAIL';
export const CHANGE_PASSWORD_REQUEST = 'CHANGE_PASSWORD_REQUEST';
export const CHANGE_PASSWORD_SUCCESS = 'CHANGE_PASSWORD_SUCCESS';
export const CHANGE_PASSWORD_FAIL = 'CHANGE_PASSWORD_FAIL';
@ -183,6 +187,23 @@ export function changeEmail(email, password) {
};
}
export function deactivateAccount(password) {
return (dispatch, getState) => {
dispatch({ type: DEACTIVATE_ACCOUNT_REQUEST });
return api(getState).post('/api/pleroma/disable_account', {
password,
}).then(response => {
if (response.data.error) throw response.data.error; // This endpoint returns HTTP 200 even on failure
dispatch({ type: DEACTIVATE_ACCOUNT_SUCCESS, response });
dispatch({ type: AUTH_LOGGED_OUT });
dispatch(showAlert('Successfully logged out.', ''));
}).catch(error => {
dispatch({ type: DEACTIVATE_ACCOUNT_FAIL, error, skipAlert: true });
throw error;
});
};
}
export function changePassword(oldPassword, newPassword, confirmation) {
return (dispatch, getState) => {
dispatch({ type: CHANGE_PASSWORD_REQUEST });

View file

@ -16,6 +16,7 @@ import {
changePassword,
fetchOAuthTokens,
revokeOAuthToken,
deactivateAccount,
} from 'soapbox/actions/auth';
import { showAlert } from 'soapbox/actions/alerts';