-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginFailureAlert.jsx
176 lines (165 loc) · 4.95 KB
/
LoginFailureAlert.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import React from 'react';
import { getConfig } from '@edx/frontend-platform';
import { useIntl } from '@edx/frontend-platform/i18n';
import { Alert, Hyperlink } from '@openedx/paragon';
import PropTypes from 'prop-types';
import {
FORBIDDEN_REQUEST,
INTERNAL_SERVER_ERROR,
INVALID_FORM,
} from '../../../data/constants';
import {
ACCOUNT_LOCKED_OUT,
ALLOWED_DOMAIN_LOGIN_ERROR,
FAILED_LOGIN_ATTEMPT,
INACTIVE_USER,
INCORRECT_EMAIL_PASSWORD,
NON_COMPLIANT_PASSWORD_EXCEPTION,
TPA_AUTHENTICATION_FAILURE,
} from '../data/constants';
import messages from '../messages';
/**
* LoginFailureAlert component that is responsible to show error alert based on error code.
* It accepts the following props
* - errorCode
* - context
*/
const LoginFailureAlert = (props) => {
const { formatMessage } = useIntl();
const { context, errorCode } = props;
if (!errorCode) {
return null;
}
let resetLink = (
<Hyperlink destination="reset" isInline>
{formatMessage(messages.loginIncorrectCredentialsErrorResetLinkText)}
</Hyperlink>
);
let errorMessage;
switch (errorCode) {
case NON_COMPLIANT_PASSWORD_EXCEPTION: {
errorMessage = (
<>
<strong>{formatMessage(messages.nonCompliantPasswordTitle)}</strong>
<p>{formatMessage(messages.nonCompliantPasswordMessage)}</p>
</>
);
break;
}
case FORBIDDEN_REQUEST:
errorMessage = <span>{formatMessage(messages.loginRateLimitReachedMessage)}</span>;
break;
case INACTIVE_USER: {
const supportLink = (
<a href={context.supportLink}>
{formatMessage(messages.contactSupportLink, { platformName: context.platformName })}
</a>
);
errorMessage = (
<span>
{formatMessage(messages.loginInactiveUserError, {
lineBreak: <br />,
email: <strong className="data-hj-suppress">{context.email}</strong>,
supportLink,
})}
</span>
);
break;
}
case ALLOWED_DOMAIN_LOGIN_ERROR: {
const url = `${getConfig().LMS_BASE_URL}/dashboard/?tpa_hint=${context.tpaHint}`;
const tpaLink = (
<a href={url}>
{formatMessage(messages.tpaAccountLink, { provider: context.provider })}
</a>
);
errorMessage = (
<span>
{formatMessage(messages.allowedDomainLoginError, { allowedDomain: context.allowedDomain, tpaLink })}
</span>
);
break;
}
case INVALID_FORM:
errorMessage = <span>{formatMessage(messages.loginFormInvalidErrorMessage)}</span>;
break;
case FAILED_LOGIN_ATTEMPT: {
resetLink = (
<Hyperlink destination="reset" isInline>
{formatMessage(messages.loginIncorrectCredentialsErrorBeforeAccountBlockedText)}
</Hyperlink>
);
errorMessage = (
<>
<span>
{formatMessage(messages.loginIncorrectCredentialsErrorAttemptsText1, {
remainingAttempts: context.remainingAttempts,
})}
</span>
<p>
{formatMessage(messages.loginIncorrectCredentialsErrorAttemptsText2, { resetLink })}
</p>
</>
);
break;
}
case ACCOUNT_LOCKED_OUT: {
errorMessage = (
<>
<span>{formatMessage(messages.accountLockedOutMessage1)}</span>
<p>{formatMessage(messages.accountLockedOutMessage2, { resetLink })}</p>
</>
);
break;
}
case INCORRECT_EMAIL_PASSWORD:
if (context.failureCount <= 1) {
errorMessage = <span>{formatMessage(messages.loginIncorrectCredentialsError)}</span>;
} else if (context.failureCount === 2) {
errorMessage = (
<span>
{formatMessage(messages.loginIncorrectCredentialsErrorWithResetLink, { resetLink })}
</span>
);
}
break;
case TPA_AUTHENTICATION_FAILURE:
errorMessage = (
<span>
{formatMessage(messages.loginTpaAuthenticationFailure, {
platform_name: getConfig().SITE_NAME,
lineBreak: <br />,
errorMessage: context.errorMessage,
})}
</span>
);
break;
case INTERNAL_SERVER_ERROR:
default:
errorMessage = <span>{formatMessage(messages.internalServerErrorMessage)}</span>;
break;
}
return (
<Alert id="login-failure-alert" className="mb-5" variant="danger">
{formatMessage(messages.loginFailureHeaderTitle)} { errorMessage }
</Alert>
);
};
LoginFailureAlert.defaultProps = {
context: {},
};
LoginFailureAlert.propTypes = {
context: PropTypes.shape({
supportLink: PropTypes.string,
platformName: PropTypes.string,
tpaHint: PropTypes.string,
provider: PropTypes.string,
allowedDomain: PropTypes.string,
remainingAttempts: PropTypes.number,
failureCount: PropTypes.number,
errorMessage: PropTypes.string,
email: PropTypes.string,
}),
errorCode: PropTypes.string.isRequired,
};
export default LoginFailureAlert;