Finished Forgot Password request, Reset Password request

This commit is contained in:
Alexander Wong
2017-09-03 13:22:27 -06:00
parent ffe3cba510
commit a5df76d7e9
13 changed files with 364 additions and 16 deletions

View File

@@ -14,14 +14,16 @@ import {
setFormPassword,
setFormPasswordConfirmation,
setFormEmailVerification,
setFormOldPassword,
setFormOldPassword
} from "../actions/auth/reducer.actions";
import {
registerUser,
verifyEmail,
loginUser,
logoutUser,
changePassword
changePassword,
forgotPassword,
resetPassword
} from "../api/auth.api";
function* registerUserCall(postBody) {
@@ -71,7 +73,44 @@ function* changePasswordCall(postBody) {
yield effects.put(isSendingAuthRequest(true));
const { new_password1, new_password2, old_password } = postBody;
try {
return yield effects.call(changePassword, new_password1, new_password2, old_password);
return yield effects.call(
changePassword,
new_password1,
new_password2,
old_password
);
} catch (exception) {
yield effects.put(setAuthRequestError(exception));
return false;
} finally {
yield effects.put(isSendingAuthRequest(false));
}
}
function* forgotPasswordCall(postBody) {
yield effects.put(isSendingAuthRequest(true));
const { email } = postBody;
try {
return yield effects.call(forgotPassword, email);
} catch (exception) {
yield effects.put(setAuthRequestError(exception));
return false;
} finally {
yield effects.put(isSendingAuthRequest(false));
}
}
function* resetPasswordCall(postBody) {
yield effects.put(isSendingAuthRequest(true));
const { uid, token, new_password1, new_password2 } = postBody;
try {
return yield effects.call(
resetPassword,
uid,
token,
new_password1,
new_password2
);
} catch (exception) {
yield effects.put(setAuthRequestError(exception));
return false;
@@ -137,3 +176,25 @@ export function* changePasswordFlow(request) {
yield effects.put(setFormPasswordConfirmation(""));
}
}
export function* forgotPasswordFlow(request) {
yield effects.put(clearAuthRequestSuccess());
yield effects.put(clearAuthRequestError());
const wasSuccessful = yield effects.call(forgotPasswordCall, request.data);
if (wasSuccessful) {
yield effects.put(setAuthRequestSuccess(wasSuccessful));
yield effects.put(clearAuthRequestError());
}
}
export function* resetPasswordFlow(request) {
yield effects.put(clearAuthRequestSuccess());
yield effects.put(clearAuthRequestError());
const wasSuccessful = yield effects.call(resetPasswordCall, request.data);
if (wasSuccessful) {
yield effects.put(setAuthRequestSuccess(wasSuccessful));
yield effects.put(clearAuthRequestError());
yield effects.put(setFormPassword(""));
yield effects.put(setFormPasswordConfirmation(""));
}
}

View File

@@ -4,14 +4,18 @@ import {
SEND_EMAIL_VERIFICATION_REQUEST,
SEND_LOGIN_REQUEST,
SEND_LOGOUT_REQUEST,
SEND_CHANGE_PASSWORD_REQUEST
SEND_CHANGE_PASSWORD_REQUEST,
SEND_FORGOT_PASSWORD_REQUEST,
SEND_RESET_PASSWORD_REQUEST
} from "../constants/auth.constants";
import {
registerUserFlow,
verifyEmailFlow,
loginUserFlow,
logoutUserFlow,
changePasswordFlow
changePasswordFlow,
forgotPasswordFlow,
resetPasswordFlow,
} from "./auth.sagas";
export default function* rootSaga() {
@@ -20,4 +24,6 @@ export default function* rootSaga() {
yield takeLatest(SEND_LOGIN_REQUEST, loginUserFlow);
yield takeLatest(SEND_LOGOUT_REQUEST, logoutUserFlow);
yield takeLatest(SEND_CHANGE_PASSWORD_REQUEST, changePasswordFlow);
yield takeLatest(SEND_FORGOT_PASSWORD_REQUEST, forgotPasswordFlow);
yield takeLatest(SEND_RESET_PASSWORD_REQUEST, resetPasswordFlow);
}