2020-01-18 02:07:52 +05:30
|
|
|
|
import React, { ComponentType, ReactElement, ReactNode } from 'react';
|
|
|
|
|
import { Link } from 'react-router-dom';
|
2019-11-11 14:10:05 +05:30
|
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
2020-01-18 02:07:52 +05:30
|
|
|
|
|
2019-12-08 00:32:00 +05:30
|
|
|
|
import { RelativeTime } from 'app/components/ui';
|
2016-05-02 13:34:23 +05:30
|
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
|
const SuggestResetPassword: ComponentType = () => (
|
2020-05-24 04:38:24 +05:30
|
|
|
|
<>
|
|
|
|
|
<br />
|
|
|
|
|
<Message
|
2020-06-04 22:11:27 +05:30
|
|
|
|
key="suggestResetPassword"
|
|
|
|
|
defaultMessage="Have you {forgotYourPassword}?"
|
2020-05-24 04:38:24 +05:30
|
|
|
|
values={{
|
|
|
|
|
forgotYourPassword: (
|
|
|
|
|
<Link to="/forgot-password">
|
2020-06-04 22:11:27 +05:30
|
|
|
|
<Message key="forgotYourPassword" defaultMessage="forgot your password" />
|
2020-05-24 04:38:24 +05:30
|
|
|
|
</Link>
|
|
|
|
|
),
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2020-01-18 02:07:52 +05:30
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const ResendKey: ComponentType<{ url: string }> = ({ url }) => (
|
|
|
|
|
<>
|
2020-05-24 04:38:24 +05:30
|
|
|
|
{' '}
|
|
|
|
|
<Link to={url}>
|
2020-06-04 22:11:27 +05:30
|
|
|
|
<Message key="doYouWantRequestKey" defaultMessage="Do you want to request a new key?" />
|
2020-05-24 04:38:24 +05:30
|
|
|
|
</Link>
|
2020-01-18 02:07:52 +05:30
|
|
|
|
</>
|
2020-05-24 04:38:24 +05:30
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const errorsMap: Record<string, (props?: Record<string, any>) => ReactElement> = {
|
2020-06-04 22:11:27 +05:30
|
|
|
|
'error.login_required': () => <Message key="loginRequired" defaultMessage="Please enter E‑mail or username" />,
|
2020-06-04 22:24:33 +05:30
|
|
|
|
'error.login_not_exist': () => (
|
|
|
|
|
<Message key="loginNotExist" defaultMessage="Sorry, Ely doesn't recognise your login." />
|
|
|
|
|
),
|
2020-06-04 22:11:27 +05:30
|
|
|
|
'error.password_required': () => <Message key="passwordRequired" defaultMessage="Please enter password" />,
|
2020-05-24 04:38:24 +05:30
|
|
|
|
|
|
|
|
|
'error.password_incorrect': (props) => (
|
|
|
|
|
// props are handled in validationErrorsHandler in components/auth/actions
|
|
|
|
|
<>
|
2020-06-04 22:11:27 +05:30
|
|
|
|
<Message key="invalidPassword" defaultMessage="You have entered wrong account password." />
|
2020-05-24 04:38:24 +05:30
|
|
|
|
{props && props.isGuest ? <SuggestResetPassword /> : null}
|
|
|
|
|
</>
|
|
|
|
|
),
|
|
|
|
|
|
2020-06-04 22:11:27 +05:30
|
|
|
|
'error.username_required': () => <Message key="usernameRequired" defaultMessage="Username is required" />,
|
|
|
|
|
'error.username_invalid': () => <Message key="usernameInvalid" defaultMessage="Username is invalid" />,
|
|
|
|
|
'error.username_too_short': () => <Message key="usernameTooShort" defaultMessage="Username is too short" />,
|
|
|
|
|
'error.username_too_long': () => <Message key="usernameTooLong" defaultMessage="Username is too long" />,
|
2020-06-04 22:24:33 +05:30
|
|
|
|
'error.username_not_available': () => (
|
|
|
|
|
<Message key="usernameUnavailable" defaultMessage="This username is already taken" />
|
|
|
|
|
),
|
2020-05-24 04:38:24 +05:30
|
|
|
|
|
2020-06-04 22:11:27 +05:30
|
|
|
|
'error.email_required': () => <Message key="emailRequired" defaultMessage="E‑mail is required" />,
|
|
|
|
|
'error.email_too_long': () => <Message key="emailToLong" defaultMessage="E‑mail is too long" />,
|
|
|
|
|
'error.email_invalid': () => <Message key="emailInvalid" defaultMessage="E‑mail is invalid" />,
|
2020-06-04 22:24:33 +05:30
|
|
|
|
'error.email_is_tempmail': () => (
|
|
|
|
|
<Message key="emailIsTempmail" defaultMessage="Tempmail E‑mail addresses is not allowed" />
|
|
|
|
|
),
|
2020-05-24 04:38:24 +05:30
|
|
|
|
'error.email_not_available': (props) => (
|
|
|
|
|
// props are handled in validationErrorsHandler in components/auth/actions
|
|
|
|
|
<>
|
2020-06-04 22:11:27 +05:30
|
|
|
|
<Message key="emailNotAvailable" defaultMessage="This E‑mail is already registered." />
|
2020-05-24 04:38:24 +05:30
|
|
|
|
{props && props.isGuest ? <SuggestResetPassword /> : null}
|
|
|
|
|
</>
|
|
|
|
|
),
|
|
|
|
|
|
2020-06-04 22:11:27 +05:30
|
|
|
|
'error.totp_required': () => <Message key="totpRequired" defaultMessage="Please, enter the code" />,
|
|
|
|
|
'error.totp_incorrect': () => <Message key="totpIncorrect" defaultMessage="The code is incorrect" />,
|
2020-06-04 22:24:33 +05:30
|
|
|
|
'error.otp_already_enabled': () => (
|
|
|
|
|
<Message key="mfaAlreadyEnabled" defaultMessage="The two factor auth is already enabled" />
|
|
|
|
|
),
|
2020-05-24 04:38:24 +05:30
|
|
|
|
|
2020-06-04 22:24:33 +05:30
|
|
|
|
'error.rePassword_required': () => (
|
|
|
|
|
<Message key="rePasswordRequired" defaultMessage="Please retype your password" />
|
|
|
|
|
),
|
|
|
|
|
'error.password_too_short': () => (
|
|
|
|
|
<Message key="passwordTooShort" defaultMessage="Your password should be at least 8 characters length" />
|
|
|
|
|
),
|
|
|
|
|
'error.rePassword_does_not_match': () => (
|
|
|
|
|
<Message key="passwordsDoesNotMatch" defaultMessage="The passwords does not match" />
|
|
|
|
|
),
|
|
|
|
|
'error.rulesAgreement_required': () => (
|
|
|
|
|
<Message key="rulesAgreementRequired" defaultMessage="You must accept rules in order to create an account" />
|
|
|
|
|
),
|
2020-06-04 22:11:27 +05:30
|
|
|
|
'error.key_required': () => <Message key="keyRequired" defaultMessage="Please, enter an activation key" />,
|
2020-05-24 04:38:24 +05:30
|
|
|
|
'error.key_not_exists': (props) => (
|
|
|
|
|
<>
|
2020-06-04 22:11:27 +05:30
|
|
|
|
<Message key="keyNotExists" defaultMessage="The key is incorrect or has expired." />
|
2020-05-24 04:38:24 +05:30
|
|
|
|
{props && props.repeatUrl ? <ResendKey url={props.repeatUrl} /> : null}
|
|
|
|
|
</>
|
|
|
|
|
),
|
|
|
|
|
'error.key_expire': (props) => errorsMap['error.key_not_exists'](props),
|
|
|
|
|
|
2020-06-04 22:24:33 +05:30
|
|
|
|
'error.newPassword_required': () => (
|
|
|
|
|
<Message key="newPasswordRequired" defaultMessage="Please enter new password" />
|
|
|
|
|
),
|
|
|
|
|
'error.newRePassword_required': () => (
|
|
|
|
|
<Message key="newRePasswordRequired" defaultMessage="Please repeat new password" />
|
|
|
|
|
),
|
2020-05-24 04:38:24 +05:30
|
|
|
|
|
2020-06-04 22:24:33 +05:30
|
|
|
|
'error.account_not_activated': () => (
|
|
|
|
|
<Message key="accountNotActivated" defaultMessage="The account is not activated" />
|
|
|
|
|
),
|
2020-06-04 22:11:27 +05:30
|
|
|
|
'error.account_banned': () => <Message key="accountBanned" defaultMessage="Account is blocked" />,
|
2020-05-24 04:38:24 +05:30
|
|
|
|
|
|
|
|
|
'error.recently_sent_message': (props) => (
|
|
|
|
|
<Message
|
2020-06-04 22:11:27 +05:30
|
|
|
|
key="emailFrequency"
|
|
|
|
|
defaultMessage="Please cool down, you are requesting E‑mails too often. New key can be retrieved {time}."
|
2020-05-24 04:38:24 +05:30
|
|
|
|
values={{
|
|
|
|
|
// for msLeft @see AuthError.jsx
|
|
|
|
|
time: <RelativeTime timestamp={props!.msLeft} />,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
|
2020-06-04 22:11:27 +05:30
|
|
|
|
'error.email_not_found': () => <Message key="emailNotFound" defaultMessage="Specified E‑mail is not found" />,
|
2020-06-04 22:24:33 +05:30
|
|
|
|
'error.account_already_activated': () => (
|
|
|
|
|
<Message key="accountAlreadyActivated" defaultMessage="This account is already activated" />
|
|
|
|
|
),
|
2020-05-24 04:38:24 +05:30
|
|
|
|
|
2020-06-04 22:11:27 +05:30
|
|
|
|
'error.captcha_required': () => <Message key="captchaRequired" defaultMessage="Please, solve the captcha" />,
|
2020-05-24 04:38:24 +05:30
|
|
|
|
'error.captcha_invalid': (props) => errorsMap['error.captcha_required'](props),
|
|
|
|
|
|
2020-06-04 22:11:27 +05:30
|
|
|
|
'error.redirectUri_required': () => <Message key="redirectUriRequired" defaultMessage="Redirect URI is required" />,
|
|
|
|
|
'error.redirectUri_invalid': () => <Message key="redirectUriInvalid" defaultMessage="Redirect URI is invalid" />,
|
2020-01-18 02:07:52 +05:30
|
|
|
|
};
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
|
interface ErrorLiteral {
|
2020-05-24 04:38:24 +05:30
|
|
|
|
type: string;
|
|
|
|
|
payload?: Record<string, any>;
|
2020-01-18 02:07:52 +05:30
|
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
|
type Error = string | ErrorLiteral;
|
|
|
|
|
|
|
|
|
|
export function resolve(error: Error): ReactNode {
|
2020-05-24 04:38:24 +05:30
|
|
|
|
let payload = {};
|
2020-01-18 02:07:52 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
if (typeof error !== 'string') {
|
|
|
|
|
payload = error.payload || {};
|
|
|
|
|
error = error.type;
|
|
|
|
|
}
|
2020-01-18 02:07:52 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
return errorsMap[error] ? errorsMap[error](payload) : error;
|
2020-01-18 02:07:52 +05:30
|
|
|
|
}
|