userIdc2024 commited on
Commit
7210db0
·
verified ·
1 Parent(s): 91ac9e0

Update src/authen/authentication.py

Browse files
Files changed (1) hide show
  1. src/authen/authentication.py +4 -9
src/authen/authentication.py CHANGED
@@ -48,9 +48,7 @@ def _ensure_email_unique_index(col):
48
 
49
 
50
  def login_or_create(email: str, password: str):
51
- """
52
- Returns (ok: bool, msg_or_uid: str)
53
- """
54
  if not email or not password:
55
  return False, "Enter both email and password."
56
 
@@ -64,7 +62,6 @@ def login_or_create(email: str, password: str):
64
  if user:
65
  pwd = user.get("password")
66
 
67
- # normal hashed password
68
  if isinstance(pwd, str):
69
  if not verify_password(password, pwd):
70
  return False, "Invalid credentials."
@@ -73,8 +70,7 @@ def login_or_create(email: str, password: str):
73
  {"$set": {"last_login": datetime.utcnow()}}
74
  )
75
  return True, email_norm
76
-
77
- # legacy dict password
78
  if isinstance(pwd, dict):
79
  if verify_legacy_password(password, pwd.get("salt"), pwd.get("hash")):
80
  new_hash = hash_password(password)
@@ -87,7 +83,7 @@ def login_or_create(email: str, password: str):
87
 
88
  return False, "Password format invalid in DB."
89
 
90
- # user not found
91
  return False, "Invalid Credentials"
92
 
93
 
@@ -104,7 +100,6 @@ def login_gate() -> str:
104
  if st.session_state.get("uid"):
105
  return st.session_state["uid"]
106
 
107
- # ✅ Optional slight vertical centering without creating a 'box'
108
  st.markdown(
109
  """
110
  <style>
@@ -121,7 +116,7 @@ def login_gate() -> str:
121
  with st.form("login_form", clear_on_submit=False):
122
  email = st.text_input("Email", key="login_email", placeholder="you@example.com")
123
  password = st.text_input("Password", type="password", key="login_pass")
124
- submit = st.form_submit_button("Continue") # ✅ removed width
125
 
126
  if submit:
127
  ok, msg = login_or_create(email, password)
 
48
 
49
 
50
  def login_or_create(email: str, password: str):
51
+
 
 
52
  if not email or not password:
53
  return False, "Enter both email and password."
54
 
 
62
  if user:
63
  pwd = user.get("password")
64
 
 
65
  if isinstance(pwd, str):
66
  if not verify_password(password, pwd):
67
  return False, "Invalid credentials."
 
70
  {"$set": {"last_login": datetime.utcnow()}}
71
  )
72
  return True, email_norm
73
+
 
74
  if isinstance(pwd, dict):
75
  if verify_legacy_password(password, pwd.get("salt"), pwd.get("hash")):
76
  new_hash = hash_password(password)
 
83
 
84
  return False, "Password format invalid in DB."
85
 
86
+
87
  return False, "Invalid Credentials"
88
 
89
 
 
100
  if st.session_state.get("uid"):
101
  return st.session_state["uid"]
102
 
 
103
  st.markdown(
104
  """
105
  <style>
 
116
  with st.form("login_form", clear_on_submit=False):
117
  email = st.text_input("Email", key="login_email", placeholder="you@example.com")
118
  password = st.text_input("Password", type="password", key="login_pass")
119
+ submit = st.form_submit_button("Continue")
120
 
121
  if submit:
122
  ok, msg = login_or_create(email, password)