github-actions[bot] commited on
Commit
08797bf
·
1 Parent(s): 0fa212a

deploy: backend from f370a16

Browse files
Files changed (1) hide show
  1. main.py +40 -5
main.py CHANGED
@@ -5212,10 +5212,16 @@ def _auth_user_not_found(error: Exception) -> bool:
5212
 
5213
 
5214
  def _generate_temporary_password(length: int = 12) -> str:
5215
- alphabet = string.ascii_letters + string.digits
 
5216
  while True:
5217
- candidate = "".join(secrets.choice(alphabet) for _ in range(max(10, length)))
5218
- if any(ch.islower() for ch in candidate) and any(ch.isupper() for ch in candidate) and any(ch.isdigit() for ch in candidate):
 
 
 
 
 
5219
  return candidate
5220
 
5221
 
@@ -7045,8 +7051,17 @@ async def create_student_account_for_teacher(
7045
  raise HTTPException(status_code=400, detail="A valid email address is required")
7046
 
7047
  temporary_password = (payload.temporary_password or "").strip()
7048
- if len(temporary_password) < 8:
7049
- raise HTTPException(status_code=400, detail="Temporary password must be at least 8 characters")
 
 
 
 
 
 
 
 
 
7050
 
7051
  grade = (payload.grade or "").strip()
7052
  section = (payload.section or "").strip()
@@ -7094,6 +7109,26 @@ async def create_student_account_for_teacher(
7094
  status_code=409,
7095
  detail="An account with this email already exists.",
7096
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7097
  logger.error("Auth user creation failed for %s: %s", email, create_auth_error)
7098
  raise HTTPException(status_code=500, detail="Failed to create authentication account.")
7099
 
 
5212
 
5213
 
5214
  def _generate_temporary_password(length: int = 12) -> str:
5215
+ special_characters = "!@#$%&*"
5216
+ alphabet = string.ascii_letters + string.digits + special_characters
5217
  while True:
5218
+ candidate = "".join(secrets.choice(alphabet) for _ in range(max(12, length)))
5219
+ if (
5220
+ any(ch.islower() for ch in candidate)
5221
+ and any(ch.isupper() for ch in candidate)
5222
+ and any(ch.isdigit() for ch in candidate)
5223
+ and any(ch in special_characters for ch in candidate)
5224
+ ):
5225
  return candidate
5226
 
5227
 
 
7051
  raise HTTPException(status_code=400, detail="A valid email address is required")
7052
 
7053
  temporary_password = (payload.temporary_password or "").strip()
7054
+ if (
7055
+ len(temporary_password) < 8
7056
+ or not re.search(r"[A-Z]", temporary_password)
7057
+ or not re.search(r"[a-z]", temporary_password)
7058
+ or not re.search(r"\d", temporary_password)
7059
+ or not re.search(r"[^A-Za-z0-9]", temporary_password)
7060
+ ):
7061
+ raise HTTPException(
7062
+ status_code=400,
7063
+ detail="Temporary password must be at least 8 characters and include uppercase, lowercase, a number, and a special character.",
7064
+ )
7065
 
7066
  grade = (payload.grade or "").strip()
7067
  section = (payload.section or "").strip()
 
7109
  status_code=409,
7110
  detail="An account with this email already exists.",
7111
  )
7112
+ if (
7113
+ "password_does_not_meet_requirements" in error_text
7114
+ or "password requirements" in error_text
7115
+ or "weak password" in error_text
7116
+ or "password must" in error_text
7117
+ ):
7118
+ raise HTTPException(
7119
+ status_code=400,
7120
+ detail="Password does not meet authentication policy requirements. Ensure it includes uppercase, lowercase, numbers, and special characters.",
7121
+ )
7122
+ if (
7123
+ "invalid_email" in error_text
7124
+ or "invalid email" in error_text
7125
+ or "improperly formatted" in error_text
7126
+ or "malformed email" in error_text
7127
+ ):
7128
+ raise HTTPException(
7129
+ status_code=400,
7130
+ detail="The email address is improperly formatted or not accepted.",
7131
+ )
7132
  logger.error("Auth user creation failed for %s: %s", email, create_auth_error)
7133
  raise HTTPException(status_code=500, detail="Failed to create authentication account.")
7134