missing container message during login
fredzannarbor opened this issue · 3 comments
Hi,
I'm making progress on the authentication front but run into an issue I don't understand. I modified the "save signup data" function as below. the authlib _create_user function requires authentication so i am making the save signup data function authenticate using hydralit's LoginApp.do_login before it tries to _create_user. This is almost working (I think) but _do_login wants to know the current msg_container, which I don't know.
def _save_signup(self, signup_data):
# show the data we captured
what_we_got = f"""
captured signup details: \n
username: {signup_data['username']} \n
password: {signup_data['password']} \n
access level: {signup_data['access_level']} \n
"""
st.write(what_we_got)
try:
**LoginApp._do_login("test", "test2")
_create_user(username=signup_data['username'], password=signup_data['password'], is_su=False, mode='create')**
st.write(signup_data)
st.write('User created successfully')
except Exception as e:
st.write(e)
on running signup.py:
captured signup details:
username: meme
password: meme2828
access level: 1
TypeError: _do_login() missing 1 required positional argument: 'msg_container'
Traceback:
File "nimbleunity/apps/signup.py", line 104, in _save_signup
LoginApp._do_login("test", "test2")
I wrote that function so the signup form would be aligned how i wanted in the middle using streamlit columns, the function just wants a container for the form, https://github.com/TangleSpace/hydralit-example/blob/657ebf7cda89e629ba37736efa4d8b4a55c16542/apps/signup.py#L29, this is passed through, https://github.com/TangleSpace/hydralit-example/blob/657ebf7cda89e629ba37736efa4d8b4a55c16542/apps/signup.py#L46, which also passes through to, https://github.com/TangleSpace/hydralit-example/blob/657ebf7cda89e629ba37736efa4d8b4a55c16542/apps/signup.py#L61, these are just for formatting, you could place them all with st, for streamlit, except the form will spread the width of the page
I'm being dense, but still getting an error. If I understand correctly, when I jump into LoginApp to do the silent login, the program then looks to _check_login in _Sign_Up app, which doesn't know about _check_login?
try:
print('trying to login')
LoginApp._do_login(self, {'username': 'joe', 'password': 'joe', 'access_level': 1, 'submitted': True}, 'st')
print('login success')
except Exception as e:
print('login error: ', e)
st.error(e)
try:
auth._create_user(username=signup_data['username'], password=signup_data['password'], is_su=False, mode='create')
st.write('User created successfully')
except Exception as e:
print(e)
st.error(e)
trying to login
login error: 'SignUpApp' object has no attribute '_check_login'
{'username': 'hojo2828', 'password': 'hojo2828', 'access_level': 1, 'submitted': False}
no you've got to go back to the login app to login, calling a function from another app isn't a good idea, as the apps should handle their own presentation and logic, if you want common functions, put them in a separate module, absolutely there is no do_login in the signup app, it's for signing up, you need to go back to the login app, in the example, once someone signs up, they go back to the login app,https://github.com/TangleSpace/hydralit-example/blob/657ebf7cda89e629ba37736efa4d8b4a55c16542/apps/signup.py#L96, i think you're getting confused as i reused the login app code to quickly write the signup app, apps should take care of their own logic, if you need different logic, navigate to another app, it keeps it clean. I saw you come from a Flask background, think of Hydralit Apps as routes, you wouldn't implement the logic in one route to call the internals of another route, you would either have shared function modules, or call a different route within the handler for a route, separation of concerns.