larxius commited on
Commit
999ce94
·
verified ·
1 Parent(s): 8eb59ca

Update backend_structured/routes.py

Browse files
Files changed (1) hide show
  1. backend_structured/routes.py +11 -8
backend_structured/routes.py CHANGED
@@ -254,25 +254,27 @@ def require_role(roles):
254
  @limiter.limit("5 per hour")
255
  def register():
256
  data = request.get_json() or {}
257
- email = data.get('email')
258
  password = data.get('password')
259
 
260
- if not email or not password:
261
  return jsonify({'message': 'Email and password are required!'}), 400
262
 
 
 
263
  if len(password) < 8:
264
  return jsonify({'message': 'Password must be at least 8 characters!'}), 400
265
 
266
- if User.query.filter_by(email=email).first():
267
  return jsonify({'message': 'User with this email already exists!'}), 400
268
 
269
  try:
270
- org_name = email.split('@')[0].capitalize() + " Organization"
271
  new_org = Organization(name=org_name)
272
  db.session.add(new_org)
273
  db.session.flush()
274
 
275
- new_user = User(email=email, org_id=new_org.id)
276
  new_user.set_password(password)
277
  db.session.add(new_user)
278
  db.session.flush()
@@ -308,13 +310,14 @@ def register():
308
  @limiter.limit("10 per minute")
309
  def login():
310
  data = request.get_json() or {}
311
- email = data.get('email')
312
  password = data.get('password')
313
 
314
- if not email or not password:
315
  return jsonify({'message': 'Email and password are required!'}), 400
316
 
317
- user = User.query.filter_by(email=email).first()
 
318
 
319
  # BUG-5 / SEC-1 FIX: Check lockout BEFORE verifying password.
320
  # Previously the order was reversed - a locked account would still call
 
254
  @limiter.limit("5 per hour")
255
  def register():
256
  data = request.get_json() or {}
257
+ raw_email = data.get('email')
258
  password = data.get('password')
259
 
260
+ if not raw_email or not password:
261
  return jsonify({'message': 'Email and password are required!'}), 400
262
 
263
+ email_clean = str(raw_email).strip().lower()
264
+
265
  if len(password) < 8:
266
  return jsonify({'message': 'Password must be at least 8 characters!'}), 400
267
 
268
+ if User.query.filter(func.lower(User.email) == email_clean).first():
269
  return jsonify({'message': 'User with this email already exists!'}), 400
270
 
271
  try:
272
+ org_name = email_clean.split('@')[0].capitalize() + " Organization"
273
  new_org = Organization(name=org_name)
274
  db.session.add(new_org)
275
  db.session.flush()
276
 
277
+ new_user = User(email=email_clean, org_id=new_org.id)
278
  new_user.set_password(password)
279
  db.session.add(new_user)
280
  db.session.flush()
 
310
  @limiter.limit("10 per minute")
311
  def login():
312
  data = request.get_json() or {}
313
+ raw_email = data.get('email')
314
  password = data.get('password')
315
 
316
+ if not raw_email or not password:
317
  return jsonify({'message': 'Email and password are required!'}), 400
318
 
319
+ email_clean = str(raw_email).strip().lower()
320
+ user = User.query.filter(func.lower(User.email) == email_clean).first()
321
 
322
  # BUG-5 / SEC-1 FIX: Check lockout BEFORE verifying password.
323
  # Previously the order was reversed - a locked account would still call