diff --git a/src/components/auth/activation/ActivationBody.jsx b/src/components/auth/activation/ActivationBody.jsx index e119987..49d3e76 100644 --- a/src/components/auth/activation/ActivationBody.jsx +++ b/src/components/auth/activation/ActivationBody.jsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { PropTypes } from 'react'; import { FormattedMessage as Message } from 'react-intl'; @@ -12,9 +12,17 @@ export default class ActivationBody extends BaseAuthBody { static displayName = 'ActivationBody'; static panelId = 'activation'; - autoFocusField = 'key'; + static propTypes = { + params: PropTypes.shape({ + key: PropTypes.string + }) + }; + + autoFocusField = this.props.params && this.props.params.key ? null : 'key'; render() { + const {key} = this.props.params; + return (
{this.renderErrors()} @@ -33,6 +41,9 @@ export default class ActivationBody extends BaseAuthBody { color="blue" style={{textAlign: 'center'}} required + value={key} + readOnly={!!key} + autoComplete="off" placeholder={messages.enterTheCode} />
diff --git a/src/routes.js b/src/routes.js index 969def1..ce446ed 100644 --- a/src/routes.js +++ b/src/routes.js @@ -35,7 +35,7 @@ export default function routesFactory(store) { }; const userOnly = { - onEnter: ({location}, replace) => { + onEnter: (nextState, replace) => { const {user} = store.getState(); if (user.isGuest) { @@ -56,7 +56,7 @@ export default function routesFactory(store) { - + diff --git a/src/services/authFlow/ActivationState.js b/src/services/authFlow/ActivationState.js index a894649..37b8265 100644 --- a/src/services/authFlow/ActivationState.js +++ b/src/services/authFlow/ActivationState.js @@ -4,12 +4,15 @@ import ResendActivationState from './ResendActivationState'; export default class ActivationState extends AbstractState { enter(context) { - const {user} = context.getState(); + const {user, routing} = context.getState(); if (user.isActive) { context.setState(new CompleteState()); } else { - context.navigate('/activation'); + const url = routing.location.pathname.includes('/activation') + ? routing.location.pathname + : '/activation'; + context.navigate(url); } } diff --git a/src/services/authFlow/RecoverPasswordState.js b/src/services/authFlow/RecoverPasswordState.js index d15a6b7..0f9eef8 100644 --- a/src/services/authFlow/RecoverPasswordState.js +++ b/src/services/authFlow/RecoverPasswordState.js @@ -7,7 +7,7 @@ export default class RecoverPasswordState extends AbstractState { const {user, routing} = context.getState(); if (user.isGuest) { - const url = routing.location.pathname.indexOf('/recover-password') === 0 + const url = routing.location.pathname.includes('/recover-password') ? routing.location.pathname : '/recover-password'; context.navigate(url); diff --git a/tests/services/authFlow/ActivationState.test.js b/tests/services/authFlow/ActivationState.test.js index 3d6545f..a0ff21b 100644 --- a/tests/services/authFlow/ActivationState.test.js +++ b/tests/services/authFlow/ActivationState.test.js @@ -23,9 +23,13 @@ describe('ActivationState', () => { describe('#enter', () => { it('should navigate to /activation', () => { + const expectedPath = '/activation'; context.getState.returns({ user: { isActive: false + }, + routing: { + location: {pathname: expectedPath} } }); @@ -34,6 +38,22 @@ describe('ActivationState', () => { state.enter(context); }); + it('should navigate to /activation/key', () => { + const expectedPath = '/activation/sasx5AS4d61'; + context.getState.returns({ + user: { + isActive: false + }, + routing: { + location: {pathname: expectedPath} + } + }); + + expectNavigate(mock, expectedPath); + + state.enter(context); + }); + it('should transition to complete state if account activated', () => { context.getState.returns({ user: {