Cleaned up email verification reducer logic

master
Alexander Wong 7 years ago
parent a5df76d7e9
commit 4cadf5df3a
  1. 44
      src/actions/auth/reducer.actions.js
  2. 8
      src/components/App.jsx
  3. 32
      src/components/Auth/VerifyEmail.jsx
  4. 3
      src/components/Shared/PrivateRoute.jsx
  5. 5
      src/constants/auth.constants.js
  6. 26
      src/reducers/authReducer.js
  7. 16
      src/sagas/auth.sagas.js

@ -4,10 +4,6 @@ import {
CLEAR_AUTH_REQUEST_ERROR, CLEAR_AUTH_REQUEST_ERROR,
SET_AUTH_REQUEST_SUCCESS, SET_AUTH_REQUEST_SUCCESS,
CLEAR_AUTH_REQUEST_SUCCESS, CLEAR_AUTH_REQUEST_SUCCESS,
SET_EMAIL_VERIFICATION_SUCCESS,
CLEAR_EMAIL_VERIFICATION_SUCCESS,
SET_EMAIL_VERIFICATION_ERROR,
CLEAR_EMAIL_VERIFICATION_ERROR,
SET_SELF_USER_TOKEN, SET_SELF_USER_TOKEN,
SET_FORM_EMAIL, SET_FORM_EMAIL,
SET_FORM_PASSWORD, SET_FORM_PASSWORD,
@ -70,6 +66,10 @@ export function setAuthRequestError(exception) {
error["UID"] = error.uid; error["UID"] = error.uid;
delete error["uid"]; delete error["uid"];
} }
if (error.key) {
error["Email Verification Key"] = error.key;
delete error["key"];
}
return { return {
type: SET_AUTH_REQUEST_ERROR, type: SET_AUTH_REQUEST_ERROR,
@ -96,42 +96,6 @@ export function clearAuthRequestSuccess() {
}; };
} }
export function setEmailVerificationError(exception) {
let error = parseError(exception);
if (error.detail) {
error["Email"] = error.detail;
delete error["detail"];
}
if (error.key) {
error["Verification Key"] = error.key;
delete error["key"];
}
return {
type: SET_EMAIL_VERIFICATION_ERROR,
data: error
};
}
export function clearEmailVerificationError() {
return {
type: CLEAR_EMAIL_VERIFICATION_ERROR
};
}
export function setEmailVerificationSuccess(response) {
return {
type: SET_EMAIL_VERIFICATION_SUCCESS,
data: response.detail || response
};
}
export function clearEmailVerificationSuccess() {
return {
type: CLEAR_EMAIL_VERIFICATION_SUCCESS
};
}
export function setSelfUserToken(selfUser) { export function setSelfUserToken(selfUser) {
return { return {
type: SET_SELF_USER_TOKEN, type: SET_SELF_USER_TOKEN,

@ -15,6 +15,10 @@ import NoMatch from "./Static/NoMatch";
import Navbar from "./Navbar"; import Navbar from "./Navbar";
class App extends Component { class App extends Component {
componentDidMount() {
}
render() { render() {
const footSmash = { const footSmash = {
display: "flex", display: "flex",
@ -35,6 +39,10 @@ class App extends Component {
path="/auth/verify-email/:emailKey" path="/auth/verify-email/:emailKey"
component={VerifyEmail} component={VerifyEmail}
/> />
<Route
path="/auth/verify-email"
component={VerifyEmail}
/>
<PrivateRoute path="/auth/settings" component={Settings} /> <PrivateRoute path="/auth/settings" component={Settings} />
<Route path="/auth/forgot-password" component={ForgotPassword} /> <Route path="/auth/forgot-password" component={ForgotPassword} />
<Route path="/auth/reset-password/:uid/:token" component={ResetPassword} /> <Route path="/auth/reset-password/:uid/:token" component={ResetPassword} />

@ -4,8 +4,8 @@ import { Link } from "react-router-dom";
import { Container, Form, Header, Message } from "semantic-ui-react"; import { Container, Form, Header, Message } from "semantic-ui-react";
import { import {
clearEmailVerificationError, clearAuthRequestError,
clearEmailVerificationSuccess, clearAuthRequestSuccess,
setFormEmailVerification setFormEmailVerification
} from "../../actions/auth/reducer.actions"; } from "../../actions/auth/reducer.actions";
import { sendEmailVerificationRequest } from "../../actions/auth/saga.actions"; import { sendEmailVerificationRequest } from "../../actions/auth/saga.actions";
@ -14,9 +14,12 @@ import Error from "../Shared/Error";
class VerifyEmail extends Component { class VerifyEmail extends Component {
componentWillMount() { componentWillMount() {
const emailKey = this.props.match.params.emailKey; const emailKey = this.props.match.params.emailKey;
this.props.dispatch(clearEmailVerificationError()); this.props.dispatch(clearAuthRequestError());
this.props.dispatch(clearEmailVerificationSuccess()); this.props.dispatch(clearAuthRequestSuccess());
this.props.dispatch(setFormEmailVerification(emailKey)); this.props.dispatch(setFormEmailVerification(emailKey));
if (emailKey) {
this.props.dispatch(sendEmailVerificationRequest({ emailKey }));
}
} }
changeEmailKey = event => { changeEmailKey = event => {
@ -34,15 +37,15 @@ class VerifyEmail extends Component {
render() { render() {
const { const {
isSendingAuthRequest, isSendingAuthRequest,
emailVerificationRequestError, authRequestError,
emailVerificationRequestSuccess, authRequestSuccess,
emailVerificationString emailVerificationString
} = this.props; } = this.props;
return ( return (
<VerifyEmailView <VerifyEmailView
isSendingAuthRequest={isSendingAuthRequest} isSendingAuthRequest={isSendingAuthRequest}
emailVerificationRequestError={emailVerificationRequestError} authRequestError={authRequestError}
emailVerificationRequestSuccess={emailVerificationRequestSuccess} authRequestSuccess={authRequestSuccess}
emailVerificationString={emailVerificationString} emailVerificationString={emailVerificationString}
changeEmailKey={this.changeEmailKey} changeEmailKey={this.changeEmailKey}
onSubmitEmailVerification={this.onSubmitEmailVerification} onSubmitEmailVerification={this.onSubmitEmailVerification}
@ -57,8 +60,8 @@ function mapStateToProps(state) {
const VerifyEmailView = ({ const VerifyEmailView = ({
isSendingAuthRequest, isSendingAuthRequest,
emailVerificationRequestError, authRequestError,
emailVerificationRequestSuccess, authRequestSuccess,
emailVerificationString, emailVerificationString,
changeEmailKey, changeEmailKey,
onSubmitEmailVerification onSubmitEmailVerification
@ -68,8 +71,8 @@ const VerifyEmailView = ({
<Form <Form
loading={isSendingAuthRequest} loading={isSendingAuthRequest}
onSubmit={onSubmitEmailVerification} onSubmit={onSubmitEmailVerification}
error={!!emailVerificationRequestError} error={!!authRequestError}
success={!!emailVerificationRequestSuccess} success={!!authRequestSuccess}
> >
<Form.Field> <Form.Field>
<label>Email Verification Key</label> <label>Email Verification Key</label>
@ -80,10 +83,7 @@ const VerifyEmailView = ({
onChange={changeEmailKey} onChange={changeEmailKey}
/> />
</Form.Field> </Form.Field>
<Error <Error header="Email Verification failed!" error={authRequestError} />
header="Email Verification failed!"
error={emailVerificationRequestError}
/>
<Message success> <Message success>
<Message.Header>Email Verified!</Message.Header> <Message.Header>Email Verified!</Message.Header>
<p>Please proceed to <Link to="/auth/login">log in</Link>.</p> <p>Please proceed to <Link to="/auth/login">log in</Link>.</p>

@ -4,7 +4,8 @@ import { connect } from "react-redux";
import { Redirect, Route } from "react-router-dom"; import { Redirect, Route } from "react-router-dom";
const propTypes = { const propTypes = {
userToken: PropTypes.string, path: PropTypes.string.isRequired,
userToken: PropTypes.string.isRequired,
component: PropTypes.oneOfType([PropTypes.element, PropTypes.func]).isRequired component: PropTypes.oneOfType([PropTypes.element, PropTypes.func]).isRequired
}; };

@ -4,11 +4,6 @@ export const SET_AUTH_REQUEST_ERROR = "SET_AUTH_REQUEST_ERROR";
export const CLEAR_AUTH_REQUEST_ERROR = "CLEAR_AUTH_REQUEST_ERROR"; export const CLEAR_AUTH_REQUEST_ERROR = "CLEAR_AUTH_REQUEST_ERROR";
export const SET_AUTH_REQUEST_SUCCESS = "SET_AUTH_REQUEST_SUCCESS"; export const SET_AUTH_REQUEST_SUCCESS = "SET_AUTH_REQUEST_SUCCESS";
export const CLEAR_AUTH_REQUEST_SUCCESS = "CLEAR_AUTH_REQUEST_SUCCESS"; export const CLEAR_AUTH_REQUEST_SUCCESS = "CLEAR_AUTH_REQUEST_SUCCESS";
export const SET_EMAIL_VERIFICATION_SUCCESS = "SET_EMAIL_VERIFICATION_SUCCESS";
export const CLEAR_EMAIL_VERIFICATION_SUCCESS =
"CLEAR_EMAIL_VERIFICATION_SUCCESS";
export const SET_EMAIL_VERIFICATION_ERROR = "SET_EMAIL_VERIFICATION_ERROR";
export const CLEAR_EMAIL_VERIFICATION_ERROR = "CLEAR_EMAIL_VERIFICATION_ERROR";
export const SET_SELF_USER_TOKEN = "SET_SELF_USER_TOKEN"; export const SET_SELF_USER_TOKEN = "SET_SELF_USER_TOKEN";
export const SET_FORM_EMAIL = "SET_FORM_EMAIL"; export const SET_FORM_EMAIL = "SET_FORM_EMAIL";
export const SET_FORM_PASSWORD = "SET_FORM_PASSWORD"; export const SET_FORM_PASSWORD = "SET_FORM_PASSWORD";

@ -4,10 +4,6 @@ import {
CLEAR_AUTH_REQUEST_ERROR, CLEAR_AUTH_REQUEST_ERROR,
SET_AUTH_REQUEST_SUCCESS, SET_AUTH_REQUEST_SUCCESS,
CLEAR_AUTH_REQUEST_SUCCESS, CLEAR_AUTH_REQUEST_SUCCESS,
SET_EMAIL_VERIFICATION_ERROR,
CLEAR_EMAIL_VERIFICATION_ERROR,
SET_EMAIL_VERIFICATION_SUCCESS,
CLEAR_EMAIL_VERIFICATION_SUCCESS,
SET_SELF_USER_TOKEN, SET_SELF_USER_TOKEN,
SET_FORM_EMAIL, SET_FORM_EMAIL,
SET_FORM_PASSWORD, SET_FORM_PASSWORD,
@ -32,8 +28,6 @@ const initialState = {
isSendingAuthRequest: false, isSendingAuthRequest: false,
authRequestError: "", authRequestError: "",
authRequestSuccess: "", authRequestSuccess: "",
emailVerificationRequestError: "",
emailVerificationRequestSuccess: "",
userToken: me(null), userToken: me(null),
email: "", email: "",
password: "", password: "",
@ -69,26 +63,6 @@ function authReducer(state = initialState, action) {
...state, ...state,
authRequestSuccess: "" authRequestSuccess: ""
}; };
case SET_EMAIL_VERIFICATION_ERROR:
return {
...state,
emailVerificationRequestError: action.data
};
case CLEAR_EMAIL_VERIFICATION_ERROR:
return {
...state,
emailVerificationRequestError: ""
};
case SET_EMAIL_VERIFICATION_SUCCESS:
return {
...state,
emailVerificationRequestSuccess: action.data
};
case CLEAR_EMAIL_VERIFICATION_SUCCESS:
return {
...state,
emailVerificationRequestSuccess: ""
};
case SET_SELF_USER_TOKEN: case SET_SELF_USER_TOKEN:
return { return {
...state, ...state,

@ -3,17 +3,12 @@ import {
isSendingAuthRequest, isSendingAuthRequest,
setAuthRequestError, setAuthRequestError,
setAuthRequestSuccess, setAuthRequestSuccess,
setEmailVerificationError,
setEmailVerificationSuccess,
clearAuthRequestError, clearAuthRequestError,
clearEmailVerificationError,
clearAuthRequestSuccess, clearAuthRequestSuccess,
clearEmailVerificationSuccess,
setSelfUserToken, setSelfUserToken,
setFormEmail, setFormEmail,
setFormPassword, setFormPassword,
setFormPasswordConfirmation, setFormPasswordConfirmation,
setFormEmailVerification,
setFormOldPassword setFormOldPassword
} from "../actions/auth/reducer.actions"; } from "../actions/auth/reducer.actions";
import { import {
@ -45,7 +40,7 @@ function* verifyEmailCall(postBody) {
try { try {
return yield effects.call(verifyEmail, emailKey); return yield effects.call(verifyEmail, emailKey);
} catch (exception) { } catch (exception) {
yield effects.put(setEmailVerificationError(exception)); yield effects.put(setAuthRequestError(exception));
return false; return false;
} finally { } finally {
yield effects.put(isSendingAuthRequest(false)); yield effects.put(isSendingAuthRequest(false));
@ -133,13 +128,12 @@ export function* registerUserFlow(request) {
} }
export function* verifyEmailFlow(request) { export function* verifyEmailFlow(request) {
yield effects.put(clearEmailVerificationSuccess()); yield effects.put(clearAuthRequestSuccess());
yield effects.put(clearEmailVerificationError()); yield effects.put(clearAuthRequestError());
const wasSuccessful = yield effects.call(verifyEmailCall, request.data); const wasSuccessful = yield effects.call(verifyEmailCall, request.data);
if (wasSuccessful) { if (wasSuccessful) {
yield effects.put(setEmailVerificationSuccess(wasSuccessful)); yield effects.put(setAuthRequestSuccess(wasSuccessful));
yield effects.put(clearEmailVerificationError()); yield effects.put(clearAuthRequestError());
yield effects.put(setFormEmailVerification(""));
} }
} }

Loading…
Cancel
Save