Mbonea commited on
Commit
a4d5446
·
1 Parent(s): 3931352
Files changed (2) hide show
  1. App/Users/Model.py +6 -3
  2. App/Users/UserRoutes.py +2 -2
App/Users/Model.py CHANGED
@@ -56,7 +56,7 @@ class User(models.Model):
56
  """Hashes a plain password."""
57
  return pwd_context.hash(plain_password)
58
 
59
- def verify_password(self, plain_password: str) -> bool:
60
  """
61
  Verifies a plain password against the hashed password.
62
  Handles account locking after multiple failed attempts.
@@ -75,14 +75,14 @@ class User(models.Model):
75
  self.failed_attempts = 0
76
  self.account_locked = False
77
  self.lastLogin = datetime.datetime.now()
78
- self.save()
79
  return True
80
  else:
81
  self.failed_attempts += 1
82
  if self.failed_attempts >= 5:
83
  self.account_locked = True
84
  logger.warning(f"Account {self.phoneNumber} has been locked.")
85
- self.save()
86
  return False
87
 
88
  async def initiate_password_reset(self):
@@ -257,3 +257,6 @@ class User(models.Model):
257
  logger.error(
258
  f"Failed to send insufficient funds message to {self.phoneNumber}: {e}"
259
  )
 
 
 
 
56
  """Hashes a plain password."""
57
  return pwd_context.hash(plain_password)
58
 
59
+ async def verify_password(self, plain_password: str) -> bool:
60
  """
61
  Verifies a plain password against the hashed password.
62
  Handles account locking after multiple failed attempts.
 
75
  self.failed_attempts = 0
76
  self.account_locked = False
77
  self.lastLogin = datetime.datetime.now()
78
+ await self.save()
79
  return True
80
  else:
81
  self.failed_attempts += 1
82
  if self.failed_attempts >= 5:
83
  self.account_locked = True
84
  logger.warning(f"Account {self.phoneNumber} has been locked.")
85
+ await self.save()
86
  return False
87
 
88
  async def initiate_password_reset(self):
 
257
  logger.error(
258
  f"Failed to send insufficient funds message to {self.phoneNumber}: {e}"
259
  )
260
+
261
+ async def delete_user(self):
262
+ pass
App/Users/UserRoutes.py CHANGED
@@ -64,9 +64,9 @@ async def register_user(request: RegisterUserRequest):
64
  async def login_user(request: LoginUserRequest):
65
  # Find user by phone number
66
  db_user = await User.filter(phoneNumber=request.phoneNumber).first()
67
-
68
  # Check if user exists and password is correct
69
- if db_user and db_user.verify_password(request.password):
70
  # Fetch active subscription if it exists
71
  subscription = await Subscription.filter(user=db_user, active=True).first()
72
 
 
64
  async def login_user(request: LoginUserRequest):
65
  # Find user by phone number
66
  db_user = await User.filter(phoneNumber=request.phoneNumber).first()
67
+ valid_password = await db_user.verify_password(request.password)
68
  # Check if user exists and password is correct
69
+ if db_user and valid_password:
70
  # Fetch active subscription if it exists
71
  subscription = await Subscription.filter(user=db_user, active=True).first()
72