Get the name of organization on account confirmation

This commit is contained in:
navaneeth 2021-05-17 16:53:11 +05:30
parent de4d39ba40
commit ff8fb8ef4b
4 changed files with 37 additions and 10 deletions

View file

@ -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')

View file

@ -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

View file

@ -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 (
<div className="page page-center">
@ -50,7 +53,24 @@ class InvitationPage extends React.Component {
<form className="card card-md" action="." method="get" autoComplete="off">
<div className="card-body">
<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>
<div className="input-group input-group-flat">
<input
@ -64,7 +84,7 @@ class InvitationPage extends React.Component {
<span className="input-group-text"></span>
</div>
</div>
<div className="mb-2">
<div className="mb-3">
<label className="form-label">Confirm Password</label>
<div className="input-group input-group-flat">
<input

View file

@ -30,10 +30,12 @@ function deleteUser(id) {
return fetch(`${config.apiUrl}/users/${id}`, requestOptions).then(handleResponse);
}
function setPasswordFromToken(token, password) {
function setPasswordFromToken({ token, password, organization, newSignup }) {
const body = {
token,
password
password,
organization,
new_signup: newSignup
};
const requestOptions = { method: 'POST', headers: authHeader(), body: JSON.stringify(body) };