Consolidate actions/security.js --> actions/auth.js
This commit is contained in:
parent
c1f3dbd22d
commit
8fd5a3cd35
3 changed files with 42 additions and 43 deletions
|
@ -15,6 +15,14 @@ export const RESET_PASSWORD_REQUEST = 'RESET_PASSWORD_REQUEST';
|
||||||
export const RESET_PASSWORD_SUCCESS = 'RESET_PASSWORD_SUCCESS';
|
export const RESET_PASSWORD_SUCCESS = 'RESET_PASSWORD_SUCCESS';
|
||||||
export const RESET_PASSWORD_FAIL = 'RESET_PASSWORD_FAIL';
|
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());
|
const noOp = () => () => new Promise(f => f());
|
||||||
|
|
||||||
function createAppAndToken() {
|
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) {
|
export function authAppCreated(app) {
|
||||||
return {
|
return {
|
||||||
type: AUTH_APP_CREATED,
|
type: AUTH_APP_CREATED,
|
||||||
|
|
|
@ -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;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
FieldsGroup,
|
FieldsGroup,
|
||||||
TextInput,
|
TextInput,
|
||||||
} from 'soapbox/features/forms';
|
} from 'soapbox/features/forms';
|
||||||
import { changeEmail, changePassword } from 'soapbox/actions/security';
|
import { changeEmail, changePassword } from 'soapbox/actions/auth';
|
||||||
import { showAlert } from 'soapbox/actions/alerts';
|
import { showAlert } from 'soapbox/actions/alerts';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
|
|
Loading…
Reference in a new issue