Create user from form

I am trying to add a new user in iUser table, but the password doesn’t match when I try to login.

function CreateUserFromStaff(five, context, result)  {
     const currentUserKey = five.currentUserKey();

const sqlStatement = `INSERT INTO iUser (iUserKey, iRoleKey, UserID, FullName, Password, Email, PhoneNo) Values(?, 'Public', ?, ?, 'admin', ?, '')`;
 let userResults = five.executeQuery(sqlStatement, 0, five.uuid(), context.new.name,context.new.name, context.new.email);
   
  if (userResults.isOk() === false) {
    return five.createError(userResults);
  }

  return five.success(userResults);
}

I have added this code to Do Before Insert

Hi Shweta,

Due to security concerns, passwords for users are hashed in the backend. As a result, directly inserting users into the iUser table would lead to a mismatch. I would recommend using a form to add users. You can achieve this by navigating to the “Forms” section and selecting “iUser” as your table.

Hello Pranoy,

I want to create a user when the admin adds new staff. I have created a user details form which has other details too.

So I wanted to insert those details in iUser whenever new staff is added and mail the details to the staff. Won’t this be possible, if I apply the same hashing algo while storing details?

Thank you!

Hi Shweta,

Regarding your use case, the admin should have the ability to add new staff members, and you want to send an email to the added staff members. This can be achieved within Five using the invite email feature. Here’s how you can do it:

  1. Go to the “Setup” menu and click on “Instances.”

  2. Once you’re on the instances page, navigate to the “Mail” tab. At the bottom, you’ll find a field labelled “Invite Email.” Double-click on that field, and an editor will open up, allowing you to set up your invite email. You can even add links to this email that redirect the user to update their password.


  3. After configuring your invite email, run your application and log in as an admin. Since your app is a multi-user app, you should have a menu item labelled “Users.” Click on it, and then select “Add Item.”

Here, the admin can add new users to the app. Once a user has been added, they will receive an invite email that we set up in step 2. Additionally, you’ll find a button on the header bar that directly sends the invite email to the users.

let me know if this helped or not.