diff --git a/app/controllers/authentication_controller.rb b/app/controllers/authentication_controller.rb index 0f584b8a69..d06651bd73 100644 --- a/app/controllers/authentication_controller.rb +++ b/app/controllers/authentication_controller.rb @@ -21,7 +21,7 @@ class AuthenticationController < ApplicationController email = params[:email] password = SecureRandom.uuid org = Organization.create(name: 'new org') - user = User.create(email: email, password: password, organization: org) + user = User.create(email: email, password: password, organization: org, invitation_token: SecureRandom.uuid) org_user = OrganizationUser.create(user: user, organization: org, role: 'admin') diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c58305b600..6a248e698a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,7 +5,12 @@ class UsersController < ApplicationController user = User.where(invitation_token: params[:token]).first if user - user.update(password: params[:password], invitation_token: nil, status: 'active') + user.update(password: params[:password], invitation_token: nil) + user.organization_users.first.update(status: 'active') + + if params[:new_signup] + user.organization.update(name: params[:organization]) + end else render json: { message: 'Invalid Invitation Token' }, status: :bad_request end diff --git a/frontend/src/InvitationPage/InvitationPage.jsx b/frontend/src/InvitationPage/InvitationPage.jsx index ad16d52c8c..dccf6672d8 100644 --- a/frontend/src/InvitationPage/InvitationPage.jsx +++ b/frontend/src/InvitationPage/InvitationPage.jsx @@ -1,14 +1,17 @@ import React from 'react'; import { userService } from '@/_services'; import { toast } from 'react-toastify'; +import queryString from 'query-string'; class InvitationPage extends React.Component { constructor(props) { super(props); this.state = { - isLoading: false + isLoading: false, + newSignup: queryString.parse(props.location.search).signup }; + } handleChange = (event) => { @@ -19,12 +22,12 @@ class InvitationPage extends React.Component { e.preventDefault(); const token = this.props.match.params.token; - const password = this.state.password; + const { password, organization, newSignup } = this.state; this.setState({ isLoading: true }); userService - .setPasswordFromToken(token, password) + .setPasswordFromToken({ token, password, organization, newSignup }) .then(() => { this.setState({ isLoading: false }); toast.success('Password has been set successfully.', { hideProgressBar: true, position: 'top-center' }); @@ -37,7 +40,7 @@ class InvitationPage extends React.Component { }; render() { - const { isLoading } = this.state; + const { isLoading, newSignup } = this.state; return (