Complete change password functionality
This commit is contained in:
@@ -9,17 +9,19 @@ import {
|
||||
clearEmailVerificationError,
|
||||
clearAuthRequestSuccess,
|
||||
clearEmailVerificationSuccess,
|
||||
setSelfUserToken,
|
||||
setFormEmail,
|
||||
setFormPassword,
|
||||
setFormPasswordConfirmation,
|
||||
setFormEmailVerification,
|
||||
setSelfUserToken
|
||||
setFormOldPassword,
|
||||
} from "../actions/auth/reducer.actions";
|
||||
import {
|
||||
registerUser,
|
||||
verifyEmail,
|
||||
loginUser,
|
||||
logoutUser
|
||||
logoutUser,
|
||||
changePassword
|
||||
} from "../api/auth.api";
|
||||
|
||||
function* registerUserCall(postBody) {
|
||||
@@ -65,6 +67,19 @@ function* logoutUserCall() {
|
||||
yield effects.call(logoutUser);
|
||||
}
|
||||
|
||||
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);
|
||||
} catch (exception) {
|
||||
yield effects.put(setAuthRequestError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingAuthRequest(false));
|
||||
}
|
||||
}
|
||||
|
||||
export function* registerUserFlow(request) {
|
||||
yield effects.put(clearAuthRequestSuccess());
|
||||
yield effects.put(clearAuthRequestError());
|
||||
@@ -109,3 +124,16 @@ export function* logoutUserFlow(request) {
|
||||
yield effects.call(logoutUserCall);
|
||||
yield effects.put(setSelfUserToken(""));
|
||||
}
|
||||
|
||||
export function* changePasswordFlow(request) {
|
||||
yield effects.put(clearAuthRequestSuccess());
|
||||
yield effects.put(clearAuthRequestError());
|
||||
const wasSuccessful = yield effects.call(changePasswordCall, request.data);
|
||||
if (wasSuccessful) {
|
||||
yield effects.put(setAuthRequestSuccess(wasSuccessful));
|
||||
yield effects.put(clearAuthRequestError());
|
||||
yield effects.put(setFormOldPassword(""));
|
||||
yield effects.put(setFormPassword(""));
|
||||
yield effects.put(setFormPasswordConfirmation(""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,15 @@ import {
|
||||
SEND_REGISTER_REQUEST,
|
||||
SEND_EMAIL_VERIFICATION_REQUEST,
|
||||
SEND_LOGIN_REQUEST,
|
||||
SEND_LOGOUT_REQUEST
|
||||
SEND_LOGOUT_REQUEST,
|
||||
SEND_CHANGE_PASSWORD_REQUEST
|
||||
} from "../constants/auth.constants";
|
||||
import {
|
||||
registerUserFlow,
|
||||
verifyEmailFlow,
|
||||
loginUserFlow,
|
||||
logoutUserFlow
|
||||
logoutUserFlow,
|
||||
changePasswordFlow
|
||||
} from "./auth.sagas";
|
||||
|
||||
export default function* rootSaga() {
|
||||
@@ -17,4 +19,5 @@ export default function* rootSaga() {
|
||||
yield takeLatest(SEND_EMAIL_VERIFICATION_REQUEST, verifyEmailFlow);
|
||||
yield takeLatest(SEND_LOGIN_REQUEST, loginUserFlow);
|
||||
yield takeLatest(SEND_LOGOUT_REQUEST, logoutUserFlow);
|
||||
yield takeLatest(SEND_CHANGE_PASSWORD_REQUEST, changePasswordFlow);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user