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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
import PropTypes from 'prop-types';
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import FormError from 'components/form_error.jsx';
import LoadingScreen from 'components/loading_screen.jsx';
import UserStore from 'stores/user_store.jsx';
import BrowserStore from 'stores/browser_store.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
import Client from 'client/web_client.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import {addUserToTeamFromInvite, getInviteInfo} from 'actions/team_actions.jsx';
import {loadMe} from 'actions/user_actions.jsx';
import logoImage from 'images/logo.png';
import AnnouncementBar from 'components/announcement_bar';
import {FormattedMessage} from 'react-intl';
import {browserHistory, Link} from 'react-router/es6';
export default class SignupController extends React.Component {
constructor(props) {
super(props);
this.renderSignupControls = this.renderSignupControls.bind(this);
let loading = false;
let serverError = '';
let noOpenServerError = false;
let usedBefore = false;
if (props.location.query) {
const hash = props.location.query.h;
const inviteId = props.location.query.id;
if (inviteId) {
loading = true;
} else if (hash && !UserStore.getCurrentUser()) {
usedBefore = BrowserStore.getGlobalItem(hash);
} else if (!inviteId && global.window.mm_config.EnableOpenServer !== 'true' && !UserStore.getNoAccounts()) {
noOpenServerError = true;
serverError = (
<FormattedMessage
id='signup_user_completed.no_open_server'
defaultMessage='This server does not allow open signups. Please speak with your Administrator to receive an invitation.'
/>
);
}
}
this.state = {
loading,
serverError,
noOpenServerError,
usedBefore
};
}
componentDidMount() {
AsyncClient.checkVersion();
BrowserStore.removeGlobalItem('team');
if (this.props.location.query) {
const hash = this.props.location.query.h;
const data = this.props.location.query.d;
const inviteId = this.props.location.query.id;
const userLoggedIn = UserStore.getCurrentUser() != null;
if ((inviteId || hash) && userLoggedIn) {
addUserToTeamFromInvite(
data,
hash,
inviteId,
(team) => {
loadMe(
() => {
browserHistory.push('/' + team.name + '/channels/town-square');
}
);
},
this.handleInvalidInvite
);
return;
}
if (inviteId) {
getInviteInfo(
inviteId,
(inviteData) => {
if (!inviteData) {
return;
}
this.setState({ // eslint-disable-line react/no-did-mount-set-state
serverError: '',
loading: false
});
},
this.handleInvalidInvite
);
return;
}
if (userLoggedIn) {
GlobalActions.redirectUserToDefaultTeam();
}
}
}
handleInvalidInvite = (err) => {
let serverError;
if (err.id === 'store.sql_user.save.max_accounts.app_error') {
serverError = err.message;
} else {
serverError = (
<FormattedMessage
id='signup_user_completed.invalid_invite'
defaultMessage='The invite link was invalid. Please speak with your Administrator to receive an invitation.'
/>
);
}
this.setState({
noOpenServerError: true,
loading: false,
serverError
});
}
renderSignupControls() {
let signupControls = [];
if (global.window.mm_config.EnableSignUpWithEmail === 'true') {
signupControls.push(
<Link
className='btn btn-custom-login btn--full email'
key='email'
to={'/signup_email' + window.location.search}
>
<span>
<span className='icon fa fa-envelope'/>
<FormattedMessage
id='signup.email'
defaultMessage='Email and Password'
/>
</span>
</Link>
);
}
if (global.window.mm_config.EnableSignUpWithGitLab === 'true') {
signupControls.push(
<a
className='btn btn-custom-login btn--full gitlab'
key='gitlab'
href={Client.getOAuthRoute() + '/gitlab/signup' + window.location.search}
>
<span>
<span className='icon'/>
<span>
<FormattedMessage
id='signup.gitlab'
defaultMessage='GitLab Single Sign-On'
/>
</span>
</span>
</a>
);
}
if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_config.EnableSignUpWithGoogle === 'true') {
signupControls.push(
<a
className='btn btn-custom-login btn--full google'
key='google'
href={Client.getOAuthRoute() + '/google/signup' + window.location.search}
>
<span>
<span className='icon'/>
<span>
<FormattedMessage
id='signup.google'
defaultMessage='Google Account'
/>
</span>
</span>
</a>
);
}
if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_config.EnableSignUpWithOffice365 === 'true') {
signupControls.push(
<a
className='btn btn-custom-login btn--full office365'
key='office365'
href={Client.getOAuthRoute() + '/office365/signup' + window.location.search}
>
<span>
<span className='icon'/>
<span>
<FormattedMessage
id='signup.office365'
defaultMessage='Office 365'
/>
</span>
</span>
</a>
);
}
if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_config.EnableLdap === 'true') {
signupControls.push(
<Link
className='btn btn-custom-login btn--full ldap'
key='ldap'
to={'/signup_ldap' + window.location.search}
>
<span>
<span className='icon fa fa-folder-open fa--margin-top'/>
<span>
<FormattedMessage
id='signup.ldap'
defaultMessage='AD/LDAP Credentials'
/>
</span>
</span>
</Link>
);
}
if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_config.EnableSaml === 'true') {
let query = '';
if (window.location.search) {
query = '&action=signup';
} else {
query = '?action=signup';
}
signupControls.push(
<a
className='btn btn-custom-login btn--full saml'
key='saml'
href={'/login/sso/saml' + window.location.search + query}
>
<span>
<span className='icon fa fa-lock fa--margin-top'/>
<span>
{global.window.mm_config.SamlLoginButtonText}
</span>
</span>
</a>
);
}
if (signupControls.length === 0) {
const signupDisabledError = (
<FormattedMessage
id='signup_user_completed.none'
defaultMessage='No user creation method has been enabled. Please contact an administrator for access.'
/>
);
signupControls = (
<FormError
error={signupDisabledError}
margin={true}
/>
);
} else if (signupControls.length === 1) {
if (global.window.mm_config.EnableSignUpWithEmail === 'true') {
return browserHistory.push('/signup_email' + window.location.search);
} else if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_config.EnableLdap === 'true') {
return browserHistory.push('/signup_ldap' + window.location.search);
}
}
return signupControls;
}
render() {
if (this.state.loading) {
return (<LoadingScreen/>);
}
if (this.state.usedBefore) {
return (
<div>
<FormattedMessage
id='signup_user_completed.expired'
defaultMessage="You've already completed the signup process for this invitation or this invitation has expired."
/>
</div>
);
}
let serverError = null;
if (this.state.serverError) {
serverError = (
<div className={'form-group has-error'}>
<label className='control-label'>{this.state.serverError}</label>
</div>
);
}
let signupControls;
if (this.state.noOpenServerError || this.state.usedBefore) {
signupControls = null;
} else {
signupControls = this.renderSignupControls();
}
return (
<div>
<AnnouncementBar/>
<div className='signup-header'>
<Link to='/'>
<span className='fa fa-chevron-left'/>
<FormattedMessage
id='web.header.back'
/>
</Link>
</div>
<div className='col-sm-12'>
<div className='signup-team__container'>
<img
className='signup-team-logo'
src={logoImage}
/>
<div className='signup__content'>
<h1>{global.window.mm_config.SiteName}</h1>
<h4 className='color--light'>
<FormattedMessage
id='web.root.signup_info'
/>
</h4>
<div className='margin--extra'>
<h5><strong>
<FormattedMessage
id='signup.title'
defaultMessage='Create an account with:'
/>
</strong></h5>
</div>
{signupControls}
{serverError}
</div>
<span className='color--light'>
<FormattedMessage
id='signup_user_completed.haveAccount'
defaultMessage='Already have an account?'
/>
{' '}
<Link
to={'/login'}
query={this.props.location.query}
>
<FormattedMessage
id='signup_user_completed.signIn'
defaultMessage='Click here to sign in.'
/>
</Link>
</span>
</div>
</div>
</div>
);
}
}
SignupController.propTypes = {
location: PropTypes.object
};
|