mkhorasani / Streamlit-Authenticator

A secure authentication module to manage user access in a Streamlit application.
Other
1.67k stars 260 forks source link

Register User method is giving None, None ,None as a return parameters #198

Closed AnveshMS closed 3 months ago

AnveshMS commented 3 months ago

I have been calling authenticator.register_user(pre_authorization=False,captcha=False), I have given all the initialization of authenticator as below. def initialize_authenticator(): """ Initializes the authenticator by retrieving user credentials from the database.

Returns:
    An instance of the `stauth.Authenticate` class with the retrieved credentials.
"""
# --- USER AUTHENTICATION ---    
conn = sql_db.create_connection()
cursor = conn.cursor()

cursor.execute("SELECT username, name, password FROM users")
rows = cursor.fetchall()

credentials = {"usernames": {}}
for row in rows:
    username, name, password = row
    credentials["usernames"][username] = {"name": name, "password": password}

return stauth.Authenticate(credentials, "sales_dashboard", "abcdef", 30)

def register_user(authenticator): print("Registering user Method") try: email_of_registered_user, username_of_registered_user, name_of_registered_user = authenticator.register_user(pre_authorization=False,captcha=False) print(f"Email: {email_of_registered_user}, Username: {username_of_registered_user}, Name: {name_of_registered_user}")

    if email_of_registered_user:
        # Store the new user in the database
        conn = sql_db.create_connection()
        cursor = conn.cursor()
        print('''INSERT INTO users (name, username, email, password) VALUES (?, ?, ?, ?)''', 
              (name_of_registered_user, username_of_registered_user, email_of_registered_user, 
               authenticator.credentials["usernames"][username_of_registered_user]["password"]))
        cursor.execute('''INSERT INTO users (name, username, email, password) VALUES (?, ?, ?, ?)''', 
                       (name_of_registered_user, username_of_registered_user, email_of_registered_user, 
                        authenticator.credentials["usernames"][username_of_registered_user]["password"]))
        conn.commit()
        conn.close()
    else:
        print("Registration failed: email_of_registered_user is None")
except Exception as e:
    print(f"An error occurred during registration: {e}")

Kindly let me know the what is the error we are getting for? From Console logs Registering user Method Email: None, Username: None, Name: None Registration failed: email_of_registered_user is None

mkhorasani commented 3 months ago

Hi @AnveshMS, the register_user does return None, None, None by design when it is initiated. Once the user fills in the form and submits it, the widget will then return the (email, username, name) of the registered user. This is intended behavior and is not a bug in any way.

AnveshMS commented 3 months ago

@mkhorasani even after submit the form I am getting the None,None,None as return parameters, After giving form values. Can you please check the code snippet which I have provided above?

mkhorasani commented 3 months ago

@mkhorasani even after submit the form I am getting the None,None,None as return parameters, After giving form values. Can you please check the code snippet which I have provided above?

I'm sorry, but I am not able to recreate this issue on my side. Can you please try to exactly follow the example provided in the Readme and see if the problem still persists?

anderson-gznu commented 2 months ago

@mkhorasani even after submit the form I am getting the None,None,None as return parameters, After giving form values. Can you please check the code snippet which I have provided above?

I meet the same issue.