summaryrefslogtreecommitdiffstats
path: root/webapp/components/signup
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-09-06 14:56:03 -0400
committerHarrison Healey <harrisonmhealey@gmail.com>2016-09-06 14:56:03 -0400
commit558821bc546fbb00ece4d4635011e4a6cca5e252 (patch)
treeae38b4806912ab4fd5d9484f52c029aeaaa07676 /webapp/components/signup
parent35b816b92217237de922c928a6623b5ac426655a (diff)
downloadchat-558821bc546fbb00ece4d4635011e4a6cca5e252.tar.gz
chat-558821bc546fbb00ece4d4635011e4a6cca5e252.tar.bz2
chat-558821bc546fbb00ece4d4635011e4a6cca5e252.zip
Fix email invitations (#3964)
Diffstat (limited to 'webapp/components/signup')
-rw-r--r--webapp/components/signup/signup_controller.jsx109
1 files changed, 56 insertions, 53 deletions
diff --git a/webapp/components/signup/signup_controller.jsx b/webapp/components/signup/signup_controller.jsx
index a4ec26a5f..229e91762 100644
--- a/webapp/components/signup/signup_controller.jsx
+++ b/webapp/components/signup/signup_controller.jsx
@@ -31,16 +31,15 @@ export default class SignupController extends React.Component {
let usedBefore = false;
if (props.location.query) {
- loading = true;
const hash = props.location.query.h;
const inviteId = props.location.query.id;
- if (hash && hash.length > 0 && !UserStore.getCurrentUser()) {
+ if (inviteId) {
+ loading = true;
+ } else if (hash && !UserStore.getCurrentUser()) {
usedBefore = BrowserStore.getGlobalItem(hash);
- loading = false;
} else if (!inviteId && global.window.mm_config.EnableOpenServer !== 'true' && !UserStore.getNoAccounts()) {
noOpenServerError = true;
- loading = false;
serverError = (
<FormattedMessage
id='signup_user_completed.no_open_server'
@@ -66,58 +65,62 @@ export default class SignupController extends React.Component {
const data = this.props.location.query.d;
const inviteId = this.props.location.query.id;
- if ((inviteId && inviteId.length > 0) || (hash && hash.length > 0)) {
- if (UserStore.getCurrentUser()) {
- Client.addUserToTeamFromInvite(
- data,
- hash,
- inviteId,
- (team) => {
- GlobalActions.emitInitialLoad(
- () => {
- browserHistory.push('/' + team.name + '/channels/town-square');
- }
- );
- },
- (err) => {
- this.setState({ // eslint-disable-line react/no-did-mount-set-state
- serverError: err.message
- });
- }
- );
- } else if (!this.state.usedBefore) {
- Client.getInviteInfo(
- inviteId,
- (inviteData) => {
- if (!inviteData) {
- return;
+ const userLoggedIn = UserStore.getCurrentUser() != null;
+
+ if ((inviteId || hash) && userLoggedIn) {
+ Client.addUserToTeamFromInvite(
+ data,
+ hash,
+ inviteId,
+ (team) => {
+ GlobalActions.emitInitialLoad(
+ () => {
+ browserHistory.push('/' + team.name + '/channels/town-square');
}
+ );
+ },
+ (err) => {
+ this.setState({ // eslint-disable-line react/no-did-mount-set-state
+ serverError: err.message
+ });
+ }
+ );
- this.setState({ // eslint-disable-line react/no-did-mount-set-state
- serverError: '',
- loading: false
- });
- },
- () => {
- this.setState({ // eslint-disable-line react/no-did-mount-set-state
- noOpenServerError: true,
- loading: false,
- serverError: (
- <FormattedMessage
- id='signup_user_completed.invalid_invite'
- defaultMessage='The invite link was invalid. Please speak with your Administrator to receive an invitation.'
- />
- )
- });
+ return;
+ }
+
+ if (inviteId) {
+ Client.getInviteInfo(
+ inviteId,
+ (inviteData) => {
+ if (!inviteData) {
+ return;
}
- );
- }
- } else if (UserStore.getCurrentUser()) {
+
+ this.setState({ // eslint-disable-line react/no-did-mount-set-state
+ serverError: '',
+ loading: false
+ });
+ },
+ () => {
+ this.setState({ // eslint-disable-line react/no-did-mount-set-state
+ noOpenServerError: true,
+ loading: false,
+ serverError: (
+ <FormattedMessage
+ id='signup_user_completed.invalid_invite'
+ defaultMessage='The invite link was invalid. Please speak with your Administrator to receive an invitation.'
+ />
+ )
+ });
+ }
+ );
+
+ return;
+ }
+
+ if (userLoggedIn) {
browserHistory.push('/select_team');
- } else {
- this.setState({ // eslint-disable-line react/no-did-mount-set-state
- loading: false
- });
}
}
}
@@ -337,4 +340,4 @@ export default class SignupController extends React.Component {
SignupController.propTypes = {
location: React.PropTypes.object
-}; \ No newline at end of file
+};