Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/redirect to login page after activate an account #1553

Merged
6 changes: 1 addition & 5 deletions src/components/Account/Activate/Activate.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ export function activate(url) {
return axios
.post(`${API_URL}user/activate/${url}`)
.then(response => {
setTimeout(() => {
window.location.href = '/';
}, 1000);

return response.data;
return { ...response.data, success: true };
})
.catch(get('response.data'));
}
40 changes: 33 additions & 7 deletions src/components/Account/Activate/Activate.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Link } from 'react-router-dom';
import { activate } from './Activate.actions';
import './Activate.css';

import { FormattedMessage } from 'react-intl';
import messages from './Activate.messages';

class ActivateContainer extends PureComponent {
state = {
isActivating: false,
Expand All @@ -19,24 +22,47 @@ class ActivateContainer extends PureComponent {
this.setState({ isActivating: true });

activate(url)
.then(activationStatus => this.setState({ activationStatus }))
.catch(activationStatus => this.setState({ activationStatus }))
.then(activationStatus => {
this.setState({ activationStatus });
if (activationStatus.success) {
setTimeout(() => {
this.props.history.replace('/login-signup');
}, 2000);
return;
}
this.handleError();
})
.catch(activationStatus => {
this.setState({ activationStatus });
this.handleError();
})
.finally(() => this.setState({ isActivating: false }));
}

handleError() {
this.setState({ error: true });
setTimeout(() => {
this.props.history.replace('/login-signup');
}, 2000);
}

render() {
const { isActivating, activationStatus } = this.state;
const { isActivating, error } = this.state;

return (
<div className="Activate">
{isActivating ? (
'Activating your account...'
<FormattedMessage {...messages.activating} />
) : (
<Fragment>
{activationStatus.message}
{error ? (
<FormattedMessage {...messages.error} />
) : (
<FormattedMessage {...messages.success} />
)}
<br />
<Link to="/" className="Activate_home">
Home page
<Link to="/login-signup" className="Activate_home">
<FormattedMessage {...messages.loginSignUpPage} />
</Link>
</Fragment>
)}
Expand Down
21 changes: 21 additions & 0 deletions src/components/Account/Activate/Activate.messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineMessages } from 'react-intl';

export default defineMessages({
activating: {
id: 'cboard.components.Activate.activating',
defaultMessage: 'Activating your account...'
},
loginSignUpPage: {
id: 'cboard.components.Activate.LoginSignUpPage',
defaultMessage: 'Login or sign up page'
},
error: {
id: 'cboard.components.Activate.error',
defaultMessage:
'ERROR: confirming your temporary user FAILED, please try to login again'
},
success: {
id: 'cboard.components.Activate.success',
defaultMessage: 'CONFIRMED!'
}
});
14 changes: 10 additions & 4 deletions src/components/Account/Login/Login.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ export function loginSuccess(payload) {
};
}

function firstLoginActions(dispatch, payload) {
API.updateUser({ ...payload, isFirstLogin: false });
async function firstLoginActions(dispatch, payload) {
try {
await API.updateUser({ ...payload, isFirstLogin: false });
} catch (err) {
console.error(err);
}
dispatch(enableAllTours());
}

Expand All @@ -43,7 +47,7 @@ function logoutSuccess() {
};
}

export function login({ email, password }, type = 'local') {
export function login({ email, password, activatedData }, type = 'local') {
const setAVoice = ({ loginData, dispatch, getState }) => {
const {
language: { lang: appLang },
Expand Down Expand Up @@ -117,7 +121,9 @@ export function login({ email, password }, type = 'local') {
return async (dispatch, getState) => {
try {
const apiMethod = type === 'local' ? 'login' : 'oAuthLogin';
const loginData = await API[apiMethod](email, password);
const loginData = activatedData
? activatedData
: await API[apiMethod](email, password);
const { communicator, board } = getState();

const activeCommunicatorId = communicator.activeCommunicatorId;
Expand Down
4 changes: 4 additions & 0 deletions src/translations/src/cboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"cboard.components.WelcomeScreenInformation.text": "Cboard helps users with speech and language impairments to communicate with symbols and text-to-speech.",
"cboard.components.AuthScreenInformation.heading": "Cboard",
"cboard.components.AuthScreenInformation.text": "Sign up to sync your settings!",
"cboard.components.Activate.activating": "Activating your account...",
"cboard.components.Activate.loginSignUpPage": "Login or sign up page",
"cboard.components.Activate.error": "ERROR: confirming your temporary user FAILED, please try to login again",
"cboard.components.Activate.success": "CONFIRMED!",
"cboard.components.Login.loginToCboard": "Login to Cboard",
"cboard.components.Login.login": "Login",
"cboard.components.Login.email": "Email",
Expand Down