mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 01:18:23 +00:00
Get the name of organization on account confirmation
This commit is contained in:
parent
de4d39ba40
commit
ff8fb8ef4b
4 changed files with 37 additions and 10 deletions
|
|
@ -21,7 +21,7 @@ class AuthenticationController < ApplicationController
|
||||||
email = params[:email]
|
email = params[:email]
|
||||||
password = SecureRandom.uuid
|
password = SecureRandom.uuid
|
||||||
org = Organization.create(name: 'new org')
|
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')
|
org_user = OrganizationUser.create(user: user, organization: org, role: 'admin')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,12 @@ class UsersController < ApplicationController
|
||||||
user = User.where(invitation_token: params[:token]).first
|
user = User.where(invitation_token: params[:token]).first
|
||||||
|
|
||||||
if user
|
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
|
else
|
||||||
render json: { message: 'Invalid Invitation Token' }, status: :bad_request
|
render json: { message: 'Invalid Invitation Token' }, status: :bad_request
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,17 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { userService } from '@/_services';
|
import { userService } from '@/_services';
|
||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
|
import queryString from 'query-string';
|
||||||
|
|
||||||
class InvitationPage extends React.Component {
|
class InvitationPage extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
isLoading: false
|
isLoading: false,
|
||||||
|
newSignup: queryString.parse(props.location.search).signup
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange = (event) => {
|
handleChange = (event) => {
|
||||||
|
|
@ -19,12 +22,12 @@ class InvitationPage extends React.Component {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const token = this.props.match.params.token;
|
const token = this.props.match.params.token;
|
||||||
const password = this.state.password;
|
const { password, organization, newSignup } = this.state;
|
||||||
|
|
||||||
this.setState({ isLoading: true });
|
this.setState({ isLoading: true });
|
||||||
|
|
||||||
userService
|
userService
|
||||||
.setPasswordFromToken(token, password)
|
.setPasswordFromToken({ token, password, organization, newSignup })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.setState({ isLoading: false });
|
this.setState({ isLoading: false });
|
||||||
toast.success('Password has been set successfully.', { hideProgressBar: true, position: 'top-center' });
|
toast.success('Password has been set successfully.', { hideProgressBar: true, position: 'top-center' });
|
||||||
|
|
@ -37,7 +40,7 @@ class InvitationPage extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isLoading } = this.state;
|
const { isLoading, newSignup } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="page page-center">
|
<div className="page page-center">
|
||||||
|
|
@ -50,7 +53,24 @@ class InvitationPage extends React.Component {
|
||||||
<form className="card card-md" action="." method="get" autoComplete="off">
|
<form className="card card-md" action="." method="get" autoComplete="off">
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<h2 className="card-title text-center mb-4">Set up your account</h2>
|
<h2 className="card-title text-center mb-4">Set up your account</h2>
|
||||||
<div className="mb-2">
|
{newSignup === "true" &&
|
||||||
|
<div className="mb-3">
|
||||||
|
<label className="form-label">Organization</label>
|
||||||
|
<div className="input-group input-group-flat">
|
||||||
|
<input
|
||||||
|
onChange={this.handleChange}
|
||||||
|
name="organization"
|
||||||
|
type="text"
|
||||||
|
className="form-control"
|
||||||
|
placeholder="Organization"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
<span className="input-group-text"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<div className="mb-3">
|
||||||
<label className="form-label">Password</label>
|
<label className="form-label">Password</label>
|
||||||
<div className="input-group input-group-flat">
|
<div className="input-group input-group-flat">
|
||||||
<input
|
<input
|
||||||
|
|
@ -64,7 +84,7 @@ class InvitationPage extends React.Component {
|
||||||
<span className="input-group-text"></span>
|
<span className="input-group-text"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mb-2">
|
<div className="mb-3">
|
||||||
<label className="form-label">Confirm Password</label>
|
<label className="form-label">Confirm Password</label>
|
||||||
<div className="input-group input-group-flat">
|
<div className="input-group input-group-flat">
|
||||||
<input
|
<input
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,12 @@ function deleteUser(id) {
|
||||||
return fetch(`${config.apiUrl}/users/${id}`, requestOptions).then(handleResponse);
|
return fetch(`${config.apiUrl}/users/${id}`, requestOptions).then(handleResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPasswordFromToken(token, password) {
|
function setPasswordFromToken({ token, password, organization, newSignup }) {
|
||||||
const body = {
|
const body = {
|
||||||
token,
|
token,
|
||||||
password
|
password,
|
||||||
|
organization,
|
||||||
|
new_signup: newSignup
|
||||||
};
|
};
|
||||||
|
|
||||||
const requestOptions = { method: 'POST', headers: authHeader(), body: JSON.stringify(body) };
|
const requestOptions = { method: 'POST', headers: authHeader(), body: JSON.stringify(body) };
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue