This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
error_page.jsx
133 lines (119 loc) · 4.52 KB
/
error_page.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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import crypto from 'crypto';
import PropTypes from 'prop-types';
import React from 'react';
import {FormattedMessage} from 'react-intl';
import {Link} from 'react-router-dom';
import {ErrorPageTypes, Constants} from 'utils/constants.jsx';
import WarningIcon from 'components/icon/warning_icon';
import ErrorTitle from './error_title.jsx';
import ErrorMessage from './error_message.jsx';
export default class ErrorPage extends React.PureComponent {
static propTypes = {
location: PropTypes.object.isRequired,
asymmetricSigningPublicKey: PropTypes.string,
siteName: PropTypes.string,
};
componentDidMount() {
document.body.setAttribute('class', 'sticky error');
}
componentWillUnmount() {
document.body.removeAttribute('class');
}
render() {
const params = new URLSearchParams(this.props.location.search);
const signature = params.get('s');
var trustParams = false;
if (signature) {
params.delete('s');
const key = this.props.asymmetricSigningPublicKey;
const keyPEM = '-----BEGIN PUBLIC KEY-----\n' + key + '\n-----END PUBLIC KEY-----';
const verify = crypto.createVerify('sha256');
verify.update('/error?' + params.toString());
trustParams = verify.verify(keyPEM, signature, 'base64');
}
const type = params.get('type');
const title = (trustParams && params.get('title')) || '';
const message = (trustParams && params.get('message')) || '';
const service = (trustParams && params.get('service')) || '';
const returnTo = (trustParams && params.get('returnTo')) || '';
let backButton;
if (type === ErrorPageTypes.PERMALINK_NOT_FOUND && returnTo) {
backButton = (
<Link to={returnTo}>
<FormattedMessage
id='error.generic.link'
defaultMessage='Back to Mattermost'
/>
</Link>
);
} else if (type === ErrorPageTypes.TEAM_NOT_FOUND) {
backButton = (
<Link to='/'>
<FormattedMessage
id='error.generic.link'
defaultMessage='Back to {siteName}'
values={{
siteName: this.props.siteName,
}}
/>
</Link>
);
} else if (type === ErrorPageTypes.CHANNEL_NOT_FOUND) {
backButton = (
<Link to={params.get('returnTo')}>
<FormattedMessage
id='error.channelNotFound.link'
defaultMessage='Back to {defaultChannelName}'
values={{
defaultChannelName: Constants.DEFAULT_CHANNEL_UI_NAME,
}}
/>
</Link>
);
} else if (type === ErrorPageTypes.OAUTH_ACCESS_DENIED || type === ErrorPageTypes.OAUTH_MISSING_CODE) {
backButton = (
<Link to='/'>
<FormattedMessage
id='error.generic.link_login'
defaultMessage='Back to login page'
/>
</Link>
);
} else {
backButton = (
<Link to='/'>
<FormattedMessage
id='error.generic.link'
defaultMessage='Back to {siteName}'
values={{
siteName: this.props.siteName,
}}
/>
</Link>
);
}
return (
<div className='container-fluid'>
<div className='error__container'>
<div className='error__icon'>
<WarningIcon/>
</div>
<h2>
<ErrorTitle
type={type}
title={title}
/>
</h2>
<ErrorMessage
type={type}
message={message}
service={service}
/>
{backButton}
</div>
</div>
);
}
}