deadshot2003 commited on
Commit
7087711
·
verified ·
1 Parent(s): e593742

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -3
app.py CHANGED
@@ -13,8 +13,10 @@ from llama_index.llms.mistralai import MistralAI
13
  from translate import Translator
14
  from dotenv import load_dotenv
15
  import re
 
16
  import ast
17
  import json
 
18
 
19
  # Connect to MongoDB
20
  client = MongoClient(os.getenv("MONGODB_URI"))
@@ -323,6 +325,9 @@ def login():
323
  # Register page
324
  def register():
325
  st.markdown('<h2 style="font-size: 2.5rem;">User Registration</h2>', unsafe_allow_html=True)
 
 
 
326
  with st.form("registration_form"):
327
  name = st.text_input("Name *", key="register_name")
328
  email = st.text_input("Email *", key="register_email")
@@ -340,8 +345,17 @@ def register():
340
  submitted = st.form_submit_button("Register")
341
 
342
  if submitted:
 
 
 
 
 
 
 
343
  if password != confirm_password:
344
  st.error("Passwords do not match!")
 
 
345
  else:
346
  bmi = calculate_bmi(weight, height)
347
  user_data = {
@@ -360,9 +374,29 @@ def register():
360
  }
361
  customer_collection.insert_one(user_data)
362
  st.success(f"Registration successful! Your BMI is {bmi}. Please log in.")
363
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
  def main():
365
- st.set_page_config(layout="wide")
366
  add_video_background()
367
  local_css("style.css")
368
 
@@ -528,4 +562,8 @@ def main():
528
 
529
 
530
  if __name__ == "__main__":
531
- main()
 
 
 
 
 
13
  from translate import Translator
14
  from dotenv import load_dotenv
15
  import re
16
+ from streamlit.components.v1 import html
17
  import ast
18
  import json
19
+ import uuid
20
 
21
  # Connect to MongoDB
22
  client = MongoClient(os.getenv("MONGODB_URI"))
 
325
  # Register page
326
  def register():
327
  st.markdown('<h2 style="font-size: 2.5rem;">User Registration</h2>', unsafe_allow_html=True)
328
+ st.info("Password must be at least 8 characters long and contain at least one uppercase letter, one digit, and one special character.")
329
+
330
+
331
  with st.form("registration_form"):
332
  name = st.text_input("Name *", key="register_name")
333
  email = st.text_input("Email *", key="register_email")
 
345
  submitted = st.form_submit_button("Register")
346
 
347
  if submitted:
348
+ # Check if email is already registered
349
+ existing_user = customer_collection.find_one({"email": email})
350
+ if existing_user:
351
+ st.error("This email is already registered. Please use a different email.")
352
+ return
353
+
354
+ # Validate password strength
355
  if password != confirm_password:
356
  st.error("Passwords do not match!")
357
+ elif not validate_password_strength(password):
358
+ st.error("Password must be at least 8 characters long, contain one uppercase letter, one special character, and one digit.")
359
  else:
360
  bmi = calculate_bmi(weight, height)
361
  user_data = {
 
374
  }
375
  customer_collection.insert_one(user_data)
376
  st.success(f"Registration successful! Your BMI is {bmi}. Please log in.")
377
+
378
+ def validate_password_strength(password):
379
+ if len(password) < 8:
380
+ return False
381
+ if not re.search(r'[A-Z]', password):
382
+ return False
383
+ if not re.search(r'\d', password):
384
+ return False
385
+ if not re.search(r'[!@#$%^&*(),.?":{}|<>]', password):
386
+ return False
387
+ return True
388
+ def is_valid_password(password):
389
+ return (len(password) >= 8 and
390
+ re.search(r"[A-Z]", password) and
391
+ re.search(r"\d", password) and
392
+ re.search(r"[!@#$%^&*(),.?\":{}|<>]", password))
393
+ def check_email_exists(email):
394
+ existing_user = customer_collection.find_one({"email": email})
395
+ st.write(f"Checking email: {email}")
396
+ st.write(f"User exists: {existing_user is not None}")
397
+ return existing_user is not None
398
  def main():
399
+ st.set_page_config(layout="wide", page_icon="🥑")
400
  add_video_background()
401
  local_css("style.css")
402
 
 
562
 
563
 
564
  if __name__ == "__main__":
565
+ main()
566
+ favicon_html = """
567
+ <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🥑</text></svg>">
568
+ """
569
+ html(favicon_html)