Added sagas + pages for password reset. WIP BOD-165

This commit is contained in:
Patrick Fic
2020-07-20 13:52:24 -07:00
parent e6865a4bfc
commit d2aa72f5d9
15 changed files with 427 additions and 3 deletions

View File

@@ -72,3 +72,29 @@ export const setLocalFingerprint = (fingerprint) => ({
type: UserActionTypes.SET_LOCAL_FINGERPRINT,
payload: fingerprint,
});
export const sendPasswordReset = (email) => ({
type: UserActionTypes.SEND_PASSWORD_RESET_EMAIL_START,
payload: email,
});
export const sendPasswordResetFailure = (error) => ({
type: UserActionTypes.SEND_PASSWORD_RESET_EMAIL_FAILURE,
payload: error,
});
export const sendPasswordResetSuccess = () => ({
type: UserActionTypes.SEND_PASSWORD_RESET_EMAIL_SUCCESS,
});
export const validatePasswordResetStart = (emailAndPin) => ({
type: UserActionTypes.VALIDATE_PASSWORD_RESET_START,
payload: emailAndPin,
});
export const validatePasswordResetSuccess = () => ({
type: UserActionTypes.VALIDATE_PASSWORD_RESET_SUCCESS,
});
export const validatePasswordResetFailure = (error) => ({
type: UserActionTypes.VALIDATE_PASSWORD_RESET_FAILURE,
payload: error,
});

View File

@@ -9,6 +9,11 @@ const INITIAL_STATE = {
fingerprint: null,
error: null,
conflict: false,
passwordreset: {
email: null,
error: null,
success: false,
},
};
const userReducer = (state = INITIAL_STATE, action) => {
@@ -19,6 +24,25 @@ const userReducer = (state = INITIAL_STATE, action) => {
return { ...state, conflict: false };
case UserActionTypes.SET_INSTANCE_CONFLICT:
return { ...state, conflict: true };
case UserActionTypes.VALIDATE_PASSWORD_RESET_START:
case UserActionTypes.SEND_PASSWORD_RESET_EMAIL_START:
return {
...state,
passwordreset: {
email: action.payload,
error: null,
success: false,
},
};
case UserActionTypes.VALIDATE_PASSWORD_RESET_FAILURE:
case UserActionTypes.SEND_PASSWORD_RESET_EMAIL_FAILURE:
return { ...state, passwordreset: { error: action.payload } };
case UserActionTypes.VALIDATE_PASSWORD_RESET_SUCCESS:
case UserActionTypes.SEND_PASSWORD_RESET_EMAIL_SUCCESS:
return {
...state,
passwordreset: { ...state.passwordreset, success: true },
};
case UserActionTypes.SIGN_IN_SUCCESS:
return {
...state,

View File

@@ -19,6 +19,10 @@ import {
signOutSuccess,
unauthorizedUser,
updateUserDetailsSuccess,
sendPasswordResetFailure,
sendPasswordResetSuccess,
validatePasswordResetSuccess,
validatePasswordResetFailure
} from "./user.actions";
import UserActionTypes from "./user.types";
@@ -161,6 +165,41 @@ export function* signInSuccessSaga({ payload }) {
yield logImEXEvent("redux_sign_in_success");
}
export function* onSendPasswordResetStart() {
yield takeLatest(
UserActionTypes.SEND_PASSWORD_RESET_EMAIL_START,
sendPasswordResetEmail
);
}
export function* sendPasswordResetEmail({ payload }) {
try {
yield auth.sendPasswordResetEmail(payload, {
url: "https://imex.online/passwordreset",
});
console.log("Good should send.");
yield put(sendPasswordResetSuccess());
} catch (error) {
yield put(sendPasswordResetFailure(error.message));
}
}
export function* onValidatePasswordResetStart() {
yield takeLatest(
UserActionTypes.VALIDATE_PASSWORD_RESET_START,
validatePasswordResetStart
);
}
export function* validatePasswordResetStart({ payload: { password, code } }) {
try {
yield auth.confirmPasswordReset(code, password);
console.log("Good should send.");
yield put(validatePasswordResetSuccess());
} catch (error) {
console.log("function*validatePasswordResetStart -> error", error);
yield put(validatePasswordResetFailure(error.message));
}
}
export function* userSagas() {
yield all([
call(onEmailSignInStart),
@@ -170,5 +209,7 @@ export function* userSagas() {
call(onSetInstanceId),
call(onCheckInstanceId),
call(onSignInSuccess),
call(onSendPasswordResetStart),
call(onValidatePasswordResetStart)
]);
}

View File

@@ -21,3 +21,8 @@ export const selectInstanceConflict = createSelector(
[selectUser],
(user) => user.conflict
);
export const selectPasswordReset = createSelector(
[selectUser],
(user) => user.passwordreset
);

View File

@@ -19,6 +19,12 @@ const UserActionTypes = {
SET_INSTANCE_ID: "SET_INSTANCE_ID",
CHECK_INSTANCE_ID: "CHECK_INSTANCE_ID",
SET_INSTANCE_CONFLICT: "SET_INSTANCE_CONFLICT",
SET_LOCAL_FINGERPRINT: "SET_LOCAL_FINGERPRINT"
SET_LOCAL_FINGERPRINT: "SET_LOCAL_FINGERPRINT",
SEND_PASSWORD_RESET_EMAIL_START: "SEND_PASSWORD_RESET_EMAIL_START",
SEND_PASSWORD_RESET_EMAIL_FAILURE: "SEND_PASSWORD_RESET_EMAIL_FAILURE",
SEND_PASSWORD_RESET_EMAIL_SUCCESS: "SEND_PASSWORD_RESET_EMAIL_SUCCESS",
VALIDATE_PASSWORD_RESET_START: "VALIDATE_PASSWORD_RESET_START",
VALIDATE_PASSWORD_RESET_SUCCESS: "VALIDATE_PASSWORD_RESET_SUCCESS",
VALIDATE_PASSWORD_RESET_FAILURE: "VALIDATE_PASSWORD_RESET_FAILURE",
};
export default UserActionTypes;