RajaThor commited on
Commit
d78cc8d
·
verified ·
1 Parent(s): 2d529a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -23
app.py CHANGED
@@ -37,27 +37,21 @@ detector = dlib.get_frontal_face_detector()
37
  shape_predictor = dlib.shape_predictor(shape_predictor_path)
38
 
39
  # Firebase Authentication
40
- def authenticate_user(email_or_username, password):
41
  try:
42
- # Check if the input is an email
43
- if "@" in email_or_username:
44
- user = auth.get_user_by_email(email_or_username)
45
- else:
46
- # If not an email, assume it's a username
47
- user = auth.get_user_by_email(email_or_username + "@example.com") # Assuming the username is unique and we append a dummy domain
48
- # The user is successfully fetched, meaning the email/username and password are valid.
49
  return True, user
50
- except Exception as e:
51
  print(f"Authentication error: {str(e)}")
52
  return False, None
53
 
54
  # Sign-up Functionality
55
- def create_user(email, username, password):
56
  try:
57
  user = auth.create_user(
58
  email=email,
59
- password=password,
60
- display_name=username # Using display_name to store the username
61
  )
62
  return True, user.uid
63
  except Exception as e:
@@ -273,13 +267,13 @@ def authenticate_user_ui():
273
  else:
274
  option = st.sidebar.radio("Select Option", ["Login", "Sign-Up"])
275
 
 
 
 
276
  if option == "Login":
277
- st.write("## Login")
278
- email = st.text_input("Email or Username", help="Enter your email address or username")
279
- password = st.text_input("Password", type="password", help="Enter your password")
280
  if st.button("Login"):
281
  if not email or not password:
282
- st.error("Please enter both email/username and password.")
283
  else:
284
  success, user = authenticate_user(email, password)
285
  if success:
@@ -288,20 +282,17 @@ def authenticate_user_ui():
288
  st.success("Authentication successful! You can now manage your set of images and profiles.")
289
  main()
290
  else:
291
- st.error("Authentication failed. Please check your email/username and password.")
 
292
  elif option == "Sign-Up":
293
- st.write("## Sign-Up")
294
- email = st.text_input("Email", help="Enter your email address")
295
- username = st.text_input("Username", help="Enter your desired username")
296
- password = st.text_input("Password", type="password", help="Enter your password")
297
  confirm_password = st.text_input("Confirm Password", type="password", help="Re-enter your password for confirmation")
298
  if st.button("Sign-Up"):
299
- if not email or not username or not password or not confirm_password:
300
  st.error("Please fill all the fields.")
301
  elif password != confirm_password:
302
  st.error("Passwords do not match.")
303
  else:
304
- success, uid = create_user(email, username, password) # Include username argument here
305
  if success:
306
  st.success(f"User with UID: {uid} created successfully! You can now log in.")
307
  else:
 
37
  shape_predictor = dlib.shape_predictor(shape_predictor_path)
38
 
39
  # Firebase Authentication
40
+ def authenticate_user(email, password):
41
  try:
42
+ user = auth.get_user_by_email(email)
43
+ # The user is successfully fetched, meaning the email and password are valid.
 
 
 
 
 
44
  return True, user
45
+ except auth.AuthError as e:
46
  print(f"Authentication error: {str(e)}")
47
  return False, None
48
 
49
  # Sign-up Functionality
50
+ def create_user(email, password):
51
  try:
52
  user = auth.create_user(
53
  email=email,
54
+ password=password
 
55
  )
56
  return True, user.uid
57
  except Exception as e:
 
267
  else:
268
  option = st.sidebar.radio("Select Option", ["Login", "Sign-Up"])
269
 
270
+ email = st.text_input("Enter Email", help="Enter your email address")
271
+ password = st.text_input("Enter Password", type="password", help="Enter your password")
272
+
273
  if option == "Login":
 
 
 
274
  if st.button("Login"):
275
  if not email or not password:
276
+ st.error("Please enter both email and password.")
277
  else:
278
  success, user = authenticate_user(email, password)
279
  if success:
 
282
  st.success("Authentication successful! You can now manage your set of images and profiles.")
283
  main()
284
  else:
285
+ st.error("Authentication failed. Please check your email and password.")
286
+
287
  elif option == "Sign-Up":
 
 
 
 
288
  confirm_password = st.text_input("Confirm Password", type="password", help="Re-enter your password for confirmation")
289
  if st.button("Sign-Up"):
290
+ if not email or not password or not confirm_password:
291
  st.error("Please fill all the fields.")
292
  elif password != confirm_password:
293
  st.error("Passwords do not match.")
294
  else:
295
+ success, uid = create_user(email, password)
296
  if success:
297
  st.success(f"User with UID: {uid} created successfully! You can now log in.")
298
  else: