chualinwei3 commited on
Commit
4669b4f
·
verified ·
1 Parent(s): fc966ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -74,6 +74,17 @@ with app.app_context():
74
  logger.error(f"Admin initialization error: {str(init_err)}")
75
 
76
  logger.info("Database initialized")
 
 
 
 
 
 
 
 
 
 
 
77
 
78
 
79
  @app.after_request
@@ -216,12 +227,14 @@ def register_user():
216
  if existing_email:
217
  return format_error_response("Email already registered", 409)
218
 
219
- # Create user
220
  user = User(
221
  matric_no=matric_no,
222
  name=name,
223
  email=email,
224
- role=role
 
 
225
  )
226
  user.set_password(password)
227
 
 
74
  logger.error(f"Admin initialization error: {str(init_err)}")
75
 
76
  logger.info("Database initialized")
77
+
78
+ # Force fix any users who are pending but accidentally active
79
+ try:
80
+ inconsistent_users = User.query.filter_by(status='pending', is_active=True).all()
81
+ if inconsistent_users:
82
+ for u in inconsistent_users:
83
+ u.is_active = False
84
+ db.session.commit()
85
+ logger.info(f"Fixed {len(inconsistent_users)} inconsistent pending accounts.")
86
+ except Exception as e:
87
+ logger.error(f"Cleanup error: {str(e)}")
88
 
89
 
90
  @app.after_request
 
227
  if existing_email:
228
  return format_error_response("Email already registered", 409)
229
 
230
+ # Create user - explicitly set status and activity for Admin approval workflow
231
  user = User(
232
  matric_no=matric_no,
233
  name=name,
234
  email=email,
235
+ role=role,
236
+ is_active=False,
237
+ status='pending'
238
  )
239
  user.set_password(password)
240