Refactor registration action
This commit is contained in:
parent
41c7612b47
commit
4d1af4764f
|
@ -8,6 +8,10 @@ import {
|
||||||
} from './importer';
|
} from './importer';
|
||||||
import { isLoggedIn } from 'soapbox/utils/auth';
|
import { isLoggedIn } from 'soapbox/utils/auth';
|
||||||
|
|
||||||
|
export const ACCOUNT_CREATE_REQUEST = 'ACCOUNT_CREATE_REQUEST';
|
||||||
|
export const ACCOUNT_CREATE_SUCCESS = 'ACCOUNT_CREATE_SUCCESS';
|
||||||
|
export const ACCOUNT_CREATE_FAIL = 'ACCOUNT_CREATE_FAIL';
|
||||||
|
|
||||||
export const ACCOUNT_FETCH_REQUEST = 'ACCOUNT_FETCH_REQUEST';
|
export const ACCOUNT_FETCH_REQUEST = 'ACCOUNT_FETCH_REQUEST';
|
||||||
export const ACCOUNT_FETCH_SUCCESS = 'ACCOUNT_FETCH_SUCCESS';
|
export const ACCOUNT_FETCH_SUCCESS = 'ACCOUNT_FETCH_SUCCESS';
|
||||||
export const ACCOUNT_FETCH_FAIL = 'ACCOUNT_FETCH_FAIL';
|
export const ACCOUNT_FETCH_FAIL = 'ACCOUNT_FETCH_FAIL';
|
||||||
|
@ -98,6 +102,18 @@ function getFromDB(dispatch, getState, index, id) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createAccount(params) {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
dispatch({ type: ACCOUNT_CREATE_REQUEST, params });
|
||||||
|
return api(getState, 'app').post('/api/v1/accounts', params).then(({ data: token }) => {
|
||||||
|
dispatch({ type: ACCOUNT_CREATE_SUCCESS, params, token });
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch({ type: ACCOUNT_CREATE_FAIL, error, params });
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function fetchAccount(id) {
|
export function fetchAccount(id) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch(fetchRelationships([id]));
|
dispatch(fetchRelationships([id]));
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import api from '../api';
|
import api from '../api';
|
||||||
import { importFetchedAccount } from './importer';
|
import { importFetchedAccount } from './importer';
|
||||||
import snackbar from 'soapbox/actions/snackbar';
|
import snackbar from 'soapbox/actions/snackbar';
|
||||||
|
import { createAccount } from 'soapbox/actions/accounts';
|
||||||
import { ME_FETCH_SUCCESS } from 'soapbox/actions/me';
|
import { ME_FETCH_SUCCESS } from 'soapbox/actions/me';
|
||||||
|
|
||||||
export const SWITCH_ACCOUNT = 'SWITCH_ACCOUNT';
|
export const SWITCH_ACCOUNT = 'SWITCH_ACCOUNT';
|
||||||
|
@ -14,10 +15,6 @@ export const VERIFY_CREDENTIALS_REQUEST = 'VERIFY_CREDENTIALS_REQUEST';
|
||||||
export const VERIFY_CREDENTIALS_SUCCESS = 'VERIFY_CREDENTIALS_SUCCESS';
|
export const VERIFY_CREDENTIALS_SUCCESS = 'VERIFY_CREDENTIALS_SUCCESS';
|
||||||
export const VERIFY_CREDENTIALS_FAIL = 'VERIFY_CREDENTIALS_FAIL';
|
export const VERIFY_CREDENTIALS_FAIL = 'VERIFY_CREDENTIALS_FAIL';
|
||||||
|
|
||||||
export const AUTH_REGISTER_REQUEST = 'AUTH_REGISTER_REQUEST';
|
|
||||||
export const AUTH_REGISTER_SUCCESS = 'AUTH_REGISTER_SUCCESS';
|
|
||||||
export const AUTH_REGISTER_FAIL = 'AUTH_REGISTER_FAIL';
|
|
||||||
|
|
||||||
export const RESET_PASSWORD_REQUEST = 'RESET_PASSWORD_REQUEST';
|
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';
|
||||||
|
@ -211,15 +208,11 @@ export function fetchOwnAccounts() {
|
||||||
export function register(params) {
|
export function register(params) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
params.fullname = params.username;
|
params.fullname = params.username;
|
||||||
dispatch({ type: AUTH_REGISTER_REQUEST });
|
|
||||||
return dispatch(createAppAndToken()).then(() => {
|
return dispatch(createAppAndToken()).then(() => {
|
||||||
return api(getState, 'app').post('/api/v1/accounts', params);
|
return dispatch(createAccount(params));
|
||||||
}).then(response => {
|
}).then(token => {
|
||||||
dispatch({ type: AUTH_REGISTER_SUCCESS, token: response.data });
|
dispatch(authLoggedIn(token));
|
||||||
dispatch(authLoggedIn(response.data));
|
|
||||||
}).catch(error => {
|
|
||||||
dispatch({ type: AUTH_REGISTER_FAIL, error });
|
|
||||||
throw error;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue