1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 21:06:42 +07:00

password restore dialog

This commit is contained in:
Fedor Katurov 2019-11-25 16:52:01 +07:00
parent 0cfc6357b9
commit 078c531e93
14 changed files with 270 additions and 33 deletions

View file

@ -87,7 +87,7 @@ export const authSetRestore = (restore: Partial<IAuthState['restore']>) => ({
restore,
});
export const authRestorePassword = (code: string) => ({
type: AUTH_USER_ACTIONS.RESTORE_PASSWORD,
export const authShowRestoreModal = (code: string) => ({
type: AUTH_USER_ACTIONS.SHOW_RESTORE_MODAL,
code,
});

View file

@ -72,3 +72,9 @@ export const apiRequestRestoreCode = ({ field }): Promise<IResultWithStatus<{}>>
.post(API.USER.REQUEST_CODE(), { field })
.then(resultMiddleware)
.catch(errorMiddleware);
export const apiCheckRestoreCode = ({ code }): Promise<IResultWithStatus<{}>> =>
api
.get(API.USER.REQUEST_CODE(code))
.then(resultMiddleware)
.catch(errorMiddleware);

View file

@ -21,7 +21,7 @@ export const AUTH_USER_ACTIONS = {
SET_RESTORE: 'SET_RESTORE',
REQUEST_RESTORE_CODE: 'REQUEST_RESTORE_CODE',
RESTORE_PASSWORD: 'RESTORE_PASSWORD',
SHOW_RESTORE_MODAL: 'SHOW_RESTORE_MODAL',
};
export const USER_ERRORS = {

View file

@ -14,7 +14,7 @@ import {
authLoggedIn,
authSetLastSeenMessages,
authPatchUser,
authRestorePassword,
authShowRestoreModal,
authSetRestore,
authRequestRestoreCode,
} from '~/redux/auth/actions';
@ -27,6 +27,7 @@ import {
apiAuthGetUpdates,
apiUpdateUser,
apiRequestRestoreCode,
apiCheckRestoreCode,
} from '~/redux/auth/api';
import { modalSetShown, modalShowDialog } from '~/redux/modal/actions';
import { selectToken, selectAuthProfile, selectAuthUser, selectAuthUpdates } from './selectors';
@ -290,7 +291,7 @@ function* requestRestoreCode({ field }: ReturnType<typeof authRequestRestoreCode
yield put(authSetRestore({ is_loading: false, is_succesfull: true }));
}
function* restorePassword({ code }: ReturnType<typeof authRestorePassword>) {
function* showRestoreModal({ code }: ReturnType<typeof authShowRestoreModal>) {
if (!code && !code.length) {
return yield put(
authSetRestore({
@ -299,6 +300,19 @@ function* restorePassword({ code }: ReturnType<typeof authRestorePassword>) {
})
);
}
yield put(authSetRestore({ user: null, is_loading: true }));
const { error, data } = yield call(apiCheckRestoreCode, { code });
if (data.error || error || !data.user) {
return yield put(
authSetRestore({ is_loading: false, error: data.error || error || ERRORS.CODE_IS_INVALID })
);
}
yield put(modalShowDialog(DIALOGS.RESTORE_PASSWORD));
yield put(authSetRestore({ user: data.user, is_loading: false }));
}
function* authSaga() {
@ -313,7 +327,7 @@ function* authSaga() {
yield takeLatest(AUTH_USER_ACTIONS.SEND_MESSAGE, sendMessage);
yield takeLatest(AUTH_USER_ACTIONS.SET_LAST_SEEN_MESSAGES, setLastSeenMessages);
yield takeLatest(AUTH_USER_ACTIONS.PATCH_USER, patchUser);
yield takeLatest(AUTH_USER_ACTIONS.RESTORE_PASSWORD, restorePassword);
yield takeLatest(AUTH_USER_ACTIONS.SHOW_RESTORE_MODAL, showRestoreModal);
yield takeLatest(AUTH_USER_ACTIONS.REQUEST_RESTORE_CODE, requestRestoreCode);
}