Login page creation help

Hi,

I am new to the anvil. i dont want to use the default login (signin / signup ) functionality. I just want to create my login form and create the default administrator and password to enter and i should manually create the username and password for other user and store it in userdata. then using the same username and password to login. is there any example to follow ?

Here is an example project using custom signup/login forms.

Is this what you’re looking for?

In addition to the tutorial shared by @david.wylie (thanks David), this section of the reference docs explains the API for creating custom signup forms

https://anvil.works/doc/#-div-id-users_api-python-api-div-

Email + password

To log in manually with an email and password, call anvil.users.login_with_email() , passing the email address and password as arguments. This function returns the newly-logged-in user, or raises an AuthenticationFailed exception if the login failed.

This function can be called from client or server code.

anvil.users.send_password_reset_email("abc@example.com")

To reset a user’s password, call anvil.users.send_password_reset_email() . If the specified email address is in the Users table, Anvil will send them an email with a link where they can set a new password for their account.

This function can be called from client or server code.

anvil.users.signup_with_email("abc@example.com",
                              "<password>")

To register a new account with an email and password, call anvil.users.signup_with_email() . If signup succeeds, this function returns the newly-created user object. The new user will also be logged in if email confirmation is not required, and new-user registrations are automatically enabled.

This function can be called from client or server code, if the “allow signups” option is enabled in the users service configuration. Otherwise, it can only be called from server code.

(That’s the most relevant section; the reference docs also describe the exceptions to use to check if the user has entered the wrong password, etc.)

Hi,

Sorry for the late reply.

My requirement is to “Admin will create the username and password for the user”. Then admin will share the credentials with the user, then the user use the same credential for login.

Hi @yuvarajan1989

This is possible in two ways: in the App Editor and in the Anvil App itself. Which one to use depends on what the administrator has access to.

1. In the App Editor

If your administrator has access to the Anvil app editor, you can add users to the Users table manually.


2. From Python code

If you are writing an ‘Admin’ section of your app, you can create user accounts in code by running this function:

anvil.users.signup_with_email(username, password)

So you could provide a TextBox for both the username and password. Set hide_text to True for the password TextBox. Then run

anvil.users.signup_with_email(
  self.text_box_username.text,
  self.text_box_password.text
)

Here’s an example app that does that, with a bit of error handling:

https://anvil.works/build#clone:FVX23CAXHIDGQ47M=FWVHZA5K7G6QXTLJHUIO2M3D

You can clone the app and import the AdminUserCreation form into your app using App Dependencies.

Here it is in action:

Let me know if you need any more help.

thanks. i started working on it. if i need any help, i will let you know.

1 Like