-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage_user.py
68 lines (53 loc) · 1.84 KB
/
page_user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from helper import check_username, time_now
from dotenv import load_dotenv
import streamlit as st
from tables import Users
from task_loads import add_user
load_dotenv()
def register_user():
user = Users(role="user", created_at=time_now())
with st.container(border=True):
st.markdown("### Registration")
col1, col2 = st.columns(2)
with col1:
user.username = st.text_input("Alias")
with col2:
user.name = st.text_input("Name")
col1, col2 = st.columns(2)
with col1:
user.password = st.text_input("Password", type="password")
with col2:
password = st.text_input("Password Repeat", type="password")
btn = st.button("Summit")
if btn:
if not user.username:
st.error("Alias is required.")
return
if not user.name:
st.error("name is required.")
return
if not user.password:
st.error("password is required.")
return
if user.password != password:
st.error("passwords do not match")
return
# username must be a-z0-9.
if not check_username(user.username):
st.error("username must start with [a-z][a-z0-9.")
return
if len(user.username) < 3:
st.error("username must be at least 3 characters")
return
if len(user.password) < 5:
st.error("password must be at least 5 characters")
return
if len(user.password) > 20:
st.error("password must be at most 20 characters")
return
if len(user.username) > 20:
st.error("username must be at most 20 characters")
return
user.email = f"{user.username}@microsoft.com"
add_user(user)
st.success("Register")