mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
Show error if user creation fails due to existing email (#317)
- Fix https://github.com/ToolJet/ToolJet/issues/316 Co-authored-by: Nishant Samel <nishant@saeloun.com>
This commit is contained in:
parent
511022b3e9
commit
de76116c38
2 changed files with 30 additions and 20 deletions
|
|
@ -14,23 +14,27 @@ class OrganizationUsersController < ApplicationController
|
|||
password = SecureRandom.uuid
|
||||
org = @current_user.organization
|
||||
|
||||
user = User.create(
|
||||
first_name: first_name,
|
||||
last_name: last_name,
|
||||
email: email,
|
||||
password: password,
|
||||
password_confirmation: password,
|
||||
organization: org,
|
||||
invitation_token: SecureRandom.uuid
|
||||
)
|
||||
if User.find_by(email: email).present?
|
||||
render json: { message: "Email address is already taken" }, status: :unprocessable_entity
|
||||
else
|
||||
user = User.create(
|
||||
first_name: first_name,
|
||||
last_name: last_name,
|
||||
email: email,
|
||||
password: password,
|
||||
password_confirmation: password,
|
||||
organization: org,
|
||||
invitation_token: SecureRandom.uuid
|
||||
)
|
||||
|
||||
org_user = OrganizationUser.new(
|
||||
role: role,
|
||||
user: user,
|
||||
organization: org
|
||||
)
|
||||
org_user = OrganizationUser.new(
|
||||
role: role,
|
||||
user: user,
|
||||
organization: org
|
||||
)
|
||||
|
||||
UserMailer.with(user: user, sender: @current_user).invitation_email.deliver if org_user.save
|
||||
UserMailer.with(user: user, sender: @current_user).invitation_email.deliver if org_user.save
|
||||
end
|
||||
end
|
||||
|
||||
def change_role
|
||||
|
|
|
|||
|
|
@ -86,11 +86,17 @@ class ManageOrgUsers extends React.Component {
|
|||
|
||||
const { firstName, lastName, email, role } = this.state.newUser;
|
||||
|
||||
organizationUserService.create(firstName, lastName, email, role).then(() => {
|
||||
this.setState({ creatingUser: false, showNewUserForm: false, newUser: {} });
|
||||
toast.success('User has been created', { hideProgressBar: true, position: 'top-center' });
|
||||
this.fetchUsers();
|
||||
});
|
||||
organizationUserService
|
||||
.create(firstName, lastName, email, role)
|
||||
.then(() => {
|
||||
this.setState({ creatingUser: false, showNewUserForm: false, newUser: {} });
|
||||
toast.success('User has been created', { hideProgressBar: true, position: 'top-center' });
|
||||
this.fetchUsers();
|
||||
})
|
||||
.catch(({ error }) => {
|
||||
toast.error(error, { hideProgressBar: true, position: 'top-center' });
|
||||
this.setState({ creatingUser: false, showNewUserForm: true, newUser: {} });
|
||||
});
|
||||
};
|
||||
|
||||
logout = () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue