Skip to content

Commit 72b0932

Browse files
author
Travis
committed
Merge branch 'development'
2 parents f3165b7 + 1d7d47a commit 72b0932

File tree

9 files changed

+102
-94
lines changed

9 files changed

+102
-94
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const ACTIVATION_REQUEST = 'ACTIVATION_REQUEST';
2+
export const ACTIVATION_SUCCESS = 'ACTIVATION_SUCCESS';
3+
export const ACTIVATION_FAILURE = 'ACTIVATION_FAILURE';
4+
export const SET_ACTIVATION_DATA = 'SET_ACTIVATION_DATA';
5+
export const SET_ACTIVATION_ERROR_MESSAGE = 'SET_ACTIVATION_ERROR_MESSAGE';
6+
export const SET_ACTIVATION_SUCCESS_MESSAGE = 'SET_ACTIVATION_SUCCESS_MESSAGE';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {activateUser} from '../../services/authService';
2+
import * as activationActionTypes from './activationActionTypes';
3+
4+
export const activateIfNeeded = (userId, bearerToken) => {
5+
return (dispatch, getState) => {
6+
if (shouldActivate(getState())) {
7+
return dispatch(activation(userId, bearerToken));
8+
}
9+
return Promise.resolve();
10+
};
11+
};
12+
const shouldActivate = ({auth: {isLoggingIn, isLoggedIn, isActivating}}) => !isLoggingIn && !isLoggedIn && !isActivating;
13+
const activation = (userId, bearerToken) => {
14+
return (dispatch) => {
15+
dispatch(activationRequest());
16+
17+
return activateUser(userId, bearerToken)
18+
.then((response) => {
19+
if (response.status === 204) {
20+
dispatch(activationSuccess('Account activated. You can now log in.'));
21+
22+
return {success: true};
23+
} else {
24+
return response.json();
25+
}
26+
})
27+
.then((json) => {
28+
if (!json.success) {
29+
throw Error(json.message || 'Something went wrong');
30+
}
31+
})
32+
.catch(e => dispatch(activationFailure(e.message)));
33+
};
34+
};
35+
const activationRequest = () => ({type: activationActionTypes.ACTIVATION_REQUEST});
36+
const activationSuccess = payload => ({type: activationActionTypes.ACTIVATION_SUCCESS, payload});
37+
const activationFailure = payload => ({type: activationActionTypes.ACTIVATION_FAILURE, payload});
38+
39+
export const setActivationData = () => {
40+
const {host, hostname, protocol} = location;
41+
return {type: activationActionTypes.SET_ACTIVATION_DATA, payload: {host, hostname, protocol}};
42+
};
43+
44+
export const setActivationErrorMessage = payload => ({type: activationActionTypes.SET_ACTIVATION_ERROR_MESSAGE, payload});
45+
export const setActivationSuccessMessage = payload => ({type: activationActionTypes.SET_ACTIVATION_SUCCESS_MESSAGE, payload});

app/actions/auth/authActionTypes.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,14 @@ export const LOGIN_REQUEST = 'LOGIN_REQUEST';
22
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
33
export const LOGIN_FAILURE = 'LOGIN_FAILURE';
44

5-
export const REGISTRATION_REQUEST = 'REGISTRATION_REQUEST';
6-
export const REGISTRATION_SUCCESS = 'REGISTRATION_SUCCESS';
7-
export const REGISTRATION_FAILURE = 'REGISTRATION_FAILURE';
8-
9-
export const ACTIVATION_REQUEST = 'ACTIVATION_REQUEST';
10-
export const ACTIVATION_SUCCESS = 'ACTIVATION_SUCCESS';
11-
export const ACTIVATION_FAILURE = 'ACTIVATION_FAILURE';
12-
135
export const ON_CHANGE_LOGIN_FIELD = 'ON_CHANGE_LOGIN_FIELD';
146
export const ON_FOCUS_LOGIN_FIELD = 'ON_FOCUS_LOGIN_FIELD';
15-
export const ON_CHANGE_REGISTRATION_FIELD = 'ON_CHANGE_REGISTRATION_FIELD';
16-
export const ON_FOCUS_REGISTRATION_FIELD = 'ON_FOCUS_REGISTRATION_FIELD';
177

188
export const SET_TOKEN = 'SET_TOKEN';
199
export const SET_IS_LOGGED_IN = 'SET_IS_LOGGED_IN';
2010
export const SET_LOGIN_FAILED = 'SET_LOGIN_FAILED';
2111
export const LOGOUT = 'LOGOUT';
22-
export const SET_ACTIVATION_DATA = 'SET_ACTIVATION_DATA';
2312

24-
export const SET_REGISTRATION_ERROR_MESSAGE = 'SET_REGISTRATION_ERROR_MESSAGE';
25-
export const SET_REGISTRATION_SUCCESS_MESSAGE = 'SET_REGISTRATION_SUCCESS_MESSAGE';
2613
export const SET_LOGIN_ERROR_MESSAGE = 'SET_LOGIN_ERROR_MESSAGE';
2714
export const SET_LOGIN_SUCCESS_MESSAGE = 'SET_LOGIN_SUCCESS_MESSAGE';
28-
export const SET_ACTIVATION_ERROR_MESSAGE = 'SET_ACTIVATION_ERROR_MESSAGE';
29-
export const SET_ACTIVATION_SUCCESS_MESSAGE = 'SET_ACTIVATION_SUCCESS_MESSAGE';
3015
export const TOGGLE_LOGIN_PASSWORD_VISIBILITY = 'TOGGLE_LOGIN_PASSWORD_VISIBILITY';
31-
export const TOGGLE_REGISTRATION_PASSWORD_VISIBILITY = 'TOGGLE_REGISTRATION_PASSWORD_VISIBILITY';
32-
export const TOGGLE_REGISTRATION_REPEAT_PASSWORD_VISIBILITY = 'TOGGLE_REGISTRATION_REPEAT_PASSWORD_VISIBILITY';

app/actions/auth/authActions.js

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getAuthLogin, activateUser} from '../../services/authService';
1+
import {getAuthLogin} from '../../services/authService';
22
import {Cookies} from 'react-cookie';
33
import * as authActionTypes from './authActionTypes';
44

@@ -49,47 +49,5 @@ export const logoutIfNeeded = () => {
4949
export const setToken = payload => ({type: authActionTypes.SET_TOKEN, payload});
5050
export const setIsLoggedIn = payload => ({type: authActionTypes.SET_IS_LOGGED_IN, payload});
5151

52-
export const activateIfNeeded = (userId, bearerToken) => {
53-
return (dispatch, getState) => {
54-
if (shouldActivate(getState())) {
55-
return dispatch(activation(userId, bearerToken));
56-
}
57-
return Promise.resolve();
58-
};
59-
};
60-
const shouldActivate = ({auth: {isLoggingIn, isLoggedIn, isActivating}}) => !isLoggingIn && !isLoggedIn && !isActivating;
61-
const activation = (userId, bearerToken) => {
62-
return (dispatch) => {
63-
dispatch(activationRequest());
64-
65-
return activateUser(userId, bearerToken)
66-
.then((response) => {
67-
if (response.status === 204) {
68-
dispatch(activationSuccess('Account activated. You can now log in.'));
69-
70-
return {success: true};
71-
} else {
72-
return response.json();
73-
}
74-
})
75-
.then((json) => {
76-
if (!json.success) {
77-
throw Error(json.message || 'Something went wrong');
78-
}
79-
})
80-
.catch(e => dispatch(activationFailure(e.message)));
81-
};
82-
};
83-
const activationRequest = () => ({type: authActionTypes.ACTIVATION_REQUEST});
84-
const activationSuccess = payload => ({type: authActionTypes.ACTIVATION_SUCCESS, payload});
85-
const activationFailure = payload => ({type: authActionTypes.ACTIVATION_FAILURE, payload});
86-
87-
export const setActivationData = () => {
88-
const {host, hostname, protocol} = location;
89-
return {type: authActionTypes.SET_ACTIVATION_DATA, payload: {host, hostname, protocol}};
90-
};
91-
9252
export const setLoginErrorMessage = payload => ({type: authActionTypes.SET_LOGIN_ERROR_MESSAGE, payload});
93-
export const setActivationErrorMessage = payload => ({type: authActionTypes.SET_ACTIVATION_ERROR_MESSAGE, payload});
94-
export const setActivationSuccessMessage = payload => ({type: authActionTypes.SET_ACTIVATION_SUCCESS_MESSAGE, payload});
9553
export const toggleLoginPasswordVisibility = () => ({type: authActionTypes.TOGGLE_LOGIN_PASSWORD_VISIBILITY});

app/components/containers/Login.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, {Component, Fragment} from 'react';
22
import {connect} from 'react-redux';
33
import * as authActions from '../../actions/auth/authActions';
4+
import * as activationActions from '../../actions/activation/activationActions';
45
import LoginForm from '../presentation/LoginForm';
56
import {LinearProgress} from 'material-ui/Progress';
67
import NoAuth from './NoAuth';
@@ -40,7 +41,7 @@ class Login extends Component {
4041
}
4142
}
4243

43-
const mapStateToProps = state => ({...state.auth});
44+
const mapStateToProps = state => ({...state.auth, ...state.activation});
4445
const mapDispatchToProps = (dispatch, {history}) => ({
4546
handleFocus(event) {
4647
dispatch(authActions.focus(event.target.name, event.target.value));
@@ -68,10 +69,10 @@ const mapDispatchToProps = (dispatch, {history}) => ({
6869
dispatch(authActions.setLoginErrorMessage(''));
6970
},
7071
onCloseActivationErrorMessageBar() {
71-
dispatch(authActions.setActivationErrorMessage(''));
72+
dispatch(activationActions.setActivationErrorMessage(''));
7273
},
7374
onCloseSuccessMessageBar() {
74-
dispatch(authActions.setActivationSuccessMessage(''));
75+
dispatch(activationActions.setActivationSuccessMessage(''));
7576
},
7677
handleClickTogglePassword() {
7778
dispatch(authActions.toggleLoginPasswordVisibility());

app/components/containers/Registration.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {Component, Fragment} from 'react';
22
import {connect} from 'react-redux';
3-
import * as authActions from '../../actions/auth/authActions';
43
import * as registrationActions from '../../actions/registration/registrationActions';
4+
import * as activationActions from '../../actions/activation/activationActions';
55
import RegistrationForm from '../presentation/RegistrationForm';
66
import MessageBar from '../presentation/MessageBar';
77
import {LinearProgress} from 'material-ui/Progress';
@@ -38,15 +38,15 @@ class Registration extends Component {
3838
}
3939
}
4040

41-
const mapStateToProps = state => ({...state.auth, ...state.registration});
41+
const mapStateToProps = state => ({...state.auth, ...state.registration, ...state.activation});
4242
const mapDispatchToProps = (dispatch, {match: {params}, history}) => ({
4343
activateUserIfNeeded() {
4444
const {bearerToken, userId} = params;
4545
if (bearerToken && userId) {
46-
dispatch(authActions.activateIfNeeded(userId, bearerToken))
46+
dispatch(activationActions.activateIfNeeded(userId, bearerToken))
4747
.then(() => history.replace('/login'));
4848
} else {
49-
dispatch(authActions.setActivationData());
49+
dispatch(activationActions.setActivationData());
5050
}
5151
},
5252
handleFocus(event) {

app/reducers/activationReducer.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as activationActionTypes from '../actions/activation/activationActionTypes';
2+
3+
const initialState = {
4+
activationUrl: '',
5+
activationFromEmail: '',
6+
isActivating: false,
7+
activationErrorMessage: '',
8+
activationSuccessMessage: '',
9+
};
10+
11+
const activation = (state = initialState, action) => {
12+
switch (action.type) {
13+
case activationActionTypes.ACTIVATION_REQUEST:
14+
return {...state, isActivating: true};
15+
case activationActionTypes.ACTIVATION_SUCCESS:
16+
return {
17+
...state,
18+
isActivating: false,
19+
activationSuccessMessage: action.payload,
20+
};
21+
case activationActionTypes.ACTIVATION_FAILURE:
22+
return {
23+
...state,
24+
isActivating: false,
25+
activationErrorMessage: action.payload,
26+
};
27+
case activationActionTypes.SET_ACTIVATION_DATA:
28+
return {
29+
...state,
30+
activationUrl: `${action.payload.protocol}//${action.payload.host}/register`,
31+
activationFromEmail: `no-reply@${action.payload.hostname}`,
32+
};
33+
case activationActionTypes.SET_ACTIVATION_SUCCESS_MESSAGE:
34+
return {...state, activationSuccessMessage: action.payload};
35+
default:
36+
return state;
37+
}
38+
};
39+
40+
export default activation;

app/reducers/authReducer.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ const initialState = {
99
loginErrors: {},
1010
isLoggedIn: false,
1111
isLoggingIn: false,
12-
activationUrl: '',
13-
activationFromEmail: '',
14-
isActivating: false,
15-
activationErrorMessage: '',
16-
activationSuccessMessage: '',
1712
isVerifying: false,
1813
token: '',
1914
expiresIn: 0,
@@ -41,20 +36,6 @@ const auth = (state = initialState, action) => {
4136
isLoggingIn: false,
4237
loginErrors: action.payload.errors || {},
4338
};
44-
case authActionTypes.ACTIVATION_REQUEST:
45-
return {...state, isActivating: true};
46-
case authActionTypes.ACTIVATION_SUCCESS:
47-
return {
48-
...state,
49-
isActivating: false,
50-
activationSuccessMessage: action.payload,
51-
};
52-
case authActionTypes.ACTIVATION_FAILURE:
53-
return {
54-
...state,
55-
isActivating: false,
56-
activationErrorMessage: action.payload,
57-
};
5839
case authActionTypes.SET_IS_LOGGED_IN:
5940
return {...state, isLoggedIn: action.payload};
6041
case authActionTypes.SET_TOKEN:
@@ -75,18 +56,10 @@ const auth = (state = initialState, action) => {
7556
};
7657
case authActionTypes.ON_CHANGE_LOGIN_FIELD:
7758
return {...state, login: {...state.login, [action.fieldName]: action.fieldValue}};
78-
case authActionTypes.SET_ACTIVATION_DATA:
79-
return {
80-
...state,
81-
activationUrl: `${action.payload.protocol}//${action.payload.host}/register`,
82-
activationFromEmail: `no-reply@${action.payload.hostname}`,
83-
};
8459
case authActionTypes.TOGGLE_LOGIN_PASSWORD_VISIBILITY:
8560
return {...state, showLoginPassword: !state.showLoginPassword};
8661
case authActionTypes.SET_LOGIN_ERROR_MESSAGE:
8762
return {...state, loginErrorMessage: action.payload};
88-
case authActionTypes.SET_ACTIVATION_SUCCESS_MESSAGE:
89-
return {...state, activationSuccessMessage: action.payload};
9063
default:
9164
return state;
9265
}

app/reducers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import app from './appReducer';
77
import recovery from './recoveryReducer';
88
import passwordReset from './passwordResetReducer';
99
import registration from './registrationReducer';
10+
import activation from './activationReducer';
1011

1112
const reducers = combineReducers({
1213
auth,
@@ -17,6 +18,7 @@ const reducers = combineReducers({
1718
recovery,
1819
passwordReset,
1920
registration,
21+
activation,
2022
});
2123

2224
export default reducers;

0 commit comments

Comments
 (0)