Commit ad3366d0 authored by Jesús Espino's avatar Jesús Espino Committed by Christopher Speller
Browse files

Replacing hash usage with token for invitations (#1109)

* Replacing hash usage with token for invitations

* Removed unneded data param in the token confirmation
parent b0cfc558
......@@ -64,8 +64,8 @@ export async function updateTeamMemberRoles(teamId, userId, newRoles, success, e
}
}
export function addUserToTeamFromInvite(data, hash, inviteId, success, error) {
Client4.addToTeamFromInvite(hash, data, inviteId).then(
export function addUserToTeamFromInvite(token, inviteId, success, error) {
Client4.addToTeamFromInvite(token, inviteId).then(
async (member) => {
const {data: team} = await TeamActions.getTeam(member.team_id)(dispatch, getState);
dispatch({
......
......@@ -578,8 +578,8 @@ export async function loginById(userId, password, mfaToken, success, error) {
}
}
export async function createUserWithInvite(user, data, emailHash, inviteId, success, error) {
const {data: resp, error: err} = await UserActions.createUser(user, data, emailHash, inviteId)(dispatch, getState);
export async function createUserWithInvite(user, token, inviteId, success, error) {
const {data: resp, error: err} = await UserActions.createUser(user, token, inviteId)(dispatch, getState);
if (resp && success) {
success(resp);
} else if (err && error) {
......
......@@ -181,14 +181,12 @@ export default class LoginController extends React.Component {
() => {
// check for query params brought over from signup_user_complete
const params = new URLSearchParams(this.props.location.search);
const hash = params.get('h') || '';
const data = params.get('d') || '';
const inviteToken = params.get('t') || '';
const inviteId = params.get('id') || '';
if (inviteId || hash) {
if (inviteId || inviteToken) {
addUserToTeamFromInvite(
data,
hash,
inviteToken,
inviteId,
(team) => {
this.finishSignin(team);
......
......@@ -33,9 +33,9 @@ export default class SignupController extends React.Component {
if (this.props.location.search) {
const params = new URLSearchParams(this.props.location.search);
let hash = params.get('h');
if (hash == null) {
hash = '';
let token = params.get('t');
if (token == null) {
token = '';
}
let inviteId = params.get('id');
if (inviteId == null) {
......@@ -44,8 +44,8 @@ export default class SignupController extends React.Component {
if (inviteId) {
loading = true;
} else if (hash && !UserStore.getCurrentUser()) {
usedBefore = BrowserStore.getGlobalItem(hash);
} else if (token && !UserStore.getCurrentUser()) {
usedBefore = BrowserStore.getGlobalItem(token);
} else if (!inviteId && !this.props.enableOpenServer && !this.props.noAccounts) {
noOpenServerError = true;
serverError = (
......@@ -69,16 +69,14 @@ export default class SignupController extends React.Component {
BrowserStore.removeGlobalItem('team');
if (this.props.location.search) {
const params = new URLSearchParams(this.props.location.search);
const hash = params.get('h') || '';
const data = params.get('d') || '';
const token = params.get('t') || '';
const inviteId = params.get('id') || '';
const userLoggedIn = UserStore.getCurrentUser() != null;
if ((inviteId || hash) && userLoggedIn) {
if ((inviteId || token) && userLoggedIn) {
addUserToTeamFromInvite(
data,
hash,
token,
inviteId,
(team) => {
loadMe().then(
......
......@@ -56,7 +56,7 @@ export default class SignupEmail extends React.Component {
getInviteInfo() {
let data = (new URLSearchParams(this.props.location.search)).get('d');
let hash = (new URLSearchParams(this.props.location.search)).get('h');
let token = (new URLSearchParams(this.props.location.search)).get('t');
const inviteId = (new URLSearchParams(this.props.location.search)).get('id');
let email = '';
let teamDisplayName = '';
......@@ -66,7 +66,7 @@ export default class SignupEmail extends React.Component {
const serverError = '';
const noOpenServerError = false;
if (hash && hash.length > 0) {
if (token && token.length > 0) {
const parsedData = JSON.parse(data);
email = parsedData.email;
teamDisplayName = parsedData.display_name;
......@@ -105,12 +105,12 @@ export default class SignupEmail extends React.Component {
);
data = null;
hash = null;
token = null;
}
return {
data,
hash,
token,
email,
teamDisplayName,
teamName,
......@@ -129,8 +129,8 @@ export default class SignupEmail extends React.Component {
user.password,
'',
() => {
if (this.state.hash > 0) {
BrowserStore.setGlobalItem(this.state.hash, JSON.stringify({usedBefore: true}));
if (this.state.token > 0) {
BrowserStore.setGlobalItem(this.state.token, JSON.stringify({usedBefore: true}));
}
loadMe().then(
......@@ -258,7 +258,7 @@ export default class SignupEmail extends React.Component {
createUserWithInvite(user,
this.state.data,
this.state.hash,
this.state.token,
this.state.inviteId,
this.handleSignupSuccess.bind(this, user),
(err) => {
......
......@@ -87,14 +87,12 @@ export default class SignupLdap extends React.Component {
handleLdapSignupSuccess() {
const params = new URLSearchParams(this.props.location.search);
const hash = params.get('h') || '';
const data = params.get('d') || '';
const token = params.get('t') || '';
const inviteId = params.get('id') || '';
if (inviteId || hash) {
if (inviteId || token) {
addUserToTeamFromInvite(
data,
hash,
token,
inviteId,
() => {
this.finishSignup();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment