From 8fd5a3cd35dc9f9b671f8c7c4c3f1afea79a8caf Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 5 Jun 2020 15:27:31 -0500 Subject: [PATCH] Consolidate actions/security.js --> actions/auth.js --- app/soapbox/actions/auth.js | 41 +++++++++++++++++++++++++ app/soapbox/actions/security.js | 42 -------------------------- app/soapbox/features/security/index.js | 2 +- 3 files changed, 42 insertions(+), 43 deletions(-) delete mode 100644 app/soapbox/actions/security.js diff --git a/app/soapbox/actions/auth.js b/app/soapbox/actions/auth.js index 46e7ea97e..23252cbcd 100644 --- a/app/soapbox/actions/auth.js +++ b/app/soapbox/actions/auth.js @@ -15,6 +15,14 @@ export const RESET_PASSWORD_REQUEST = 'RESET_PASSWORD_REQUEST'; export const RESET_PASSWORD_SUCCESS = 'RESET_PASSWORD_SUCCESS'; export const RESET_PASSWORD_FAIL = 'RESET_PASSWORD_FAIL'; +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 CHANGE_PASSWORD_REQUEST = 'CHANGE_PASSWORD_REQUEST'; +export const CHANGE_PASSWORD_SUCCESS = 'CHANGE_PASSWORD_SUCCESS'; +export const CHANGE_PASSWORD_FAIL = 'CHANGE_PASSWORD_FAIL'; + const noOp = () => () => new Promise(f => f()); function createAppAndToken() { @@ -148,6 +156,39 @@ export function resetPassword(nickNameOrEmail) { }; } +export function changeEmail(email, password) { + return (dispatch, getState) => { + dispatch({ type: CHANGE_EMAIL_REQUEST, email }); + return api(getState).post('/api/pleroma/change_email', { + email, + password, + }).then(response => { + if (response.data.error) throw response.data.error; // This endpoint returns HTTP 200 even on failure + dispatch({ type: CHANGE_EMAIL_SUCCESS, email, response }); + }).catch(error => { + dispatch({ type: CHANGE_EMAIL_FAIL, email, error, skipAlert: true }); + throw error; + }); + }; +} + +export function changePassword(oldPassword, newPassword, confirmation) { + return (dispatch, getState) => { + dispatch({ type: CHANGE_PASSWORD_REQUEST }); + return api(getState).post('/api/pleroma/change_password', { + password: oldPassword, + new_password: newPassword, + new_password_confirmation: confirmation, + }).then(response => { + if (response.data.error) throw response.data.error; // This endpoint returns HTTP 200 even on failure + dispatch({ type: CHANGE_PASSWORD_SUCCESS, response }); + }).catch(error => { + dispatch({ type: CHANGE_PASSWORD_FAIL, error, skipAlert: true }); + throw error; + }); + }; +} + export function authAppCreated(app) { return { type: AUTH_APP_CREATED, diff --git a/app/soapbox/actions/security.js b/app/soapbox/actions/security.js deleted file mode 100644 index 3779a58a8..000000000 --- a/app/soapbox/actions/security.js +++ /dev/null @@ -1,42 +0,0 @@ -import api from '../api'; - -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 CHANGE_PASSWORD_REQUEST = 'CHANGE_PASSWORD_REQUEST'; -export const CHANGE_PASSWORD_SUCCESS = 'CHANGE_PASSWORD_SUCCESS'; -export const CHANGE_PASSWORD_FAIL = 'CHANGE_PASSWORD_FAIL'; - -export function changeEmail(email, password) { - return (dispatch, getState) => { - dispatch({ type: CHANGE_EMAIL_REQUEST, email }); - return api(getState).post('/api/pleroma/change_email', { - email, - password, - }).then(response => { - if (response.data.error) throw response.data.error; // This endpoint returns HTTP 200 even on failure - dispatch({ type: CHANGE_EMAIL_SUCCESS, email, response }); - }).catch(error => { - dispatch({ type: CHANGE_EMAIL_FAIL, email, error, skipAlert: true }); - throw error; - }); - }; -} - -export function changePassword(oldPassword, newPassword, confirmation) { - return (dispatch, getState) => { - dispatch({ type: CHANGE_PASSWORD_REQUEST }); - return api(getState).post('/api/pleroma/change_password', { - password: oldPassword, - new_password: newPassword, - new_password_confirmation: confirmation, - }).then(response => { - if (response.data.error) throw response.data.error; // This endpoint returns HTTP 200 even on failure - dispatch({ type: CHANGE_PASSWORD_SUCCESS, response }); - }).catch(error => { - dispatch({ type: CHANGE_PASSWORD_FAIL, error, skipAlert: true }); - throw error; - }); - }; -} diff --git a/app/soapbox/features/security/index.js b/app/soapbox/features/security/index.js index 477d0f520..91d907ce7 100644 --- a/app/soapbox/features/security/index.js +++ b/app/soapbox/features/security/index.js @@ -10,7 +10,7 @@ import { FieldsGroup, TextInput, } from 'soapbox/features/forms'; -import { changeEmail, changePassword } from 'soapbox/actions/security'; +import { changeEmail, changePassword } from 'soapbox/actions/auth'; import { showAlert } from 'soapbox/actions/alerts'; const messages = defineMessages({