Skip to content

Commit df5bd3e

Browse files
committed
Moved message literals to the constants
1 parent b24fe01 commit df5bd3e

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/api/constants/messages.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class PasswordResetMessages(TypedDict):
6464
TOKEN_EXPIRED: str
6565
PASSWORD_RESET: str
6666
DOESNT_EXIST: str
67+
INACTIVE: str
68+
DISABLED: str
6769

6870

6971
class Messages(TypedDict):
@@ -154,6 +156,8 @@ class DynamicMessages(TypedDict):
154156
"INVALID_TOKEN": "Invalid password reset token!",
155157
"DOESNT_EXIST": "You don't have an account with us yet!",
156158
"TOKEN_EXPIRED": "Password reset token has expired!",
159+
"INACTIVE": "You can only reset the password of an active account!",
160+
"DISABLED": "You can only reset the password of an enabled account!",
157161
},
158162
}
159163

src/api/models/payload/requests/Pin.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/api/services/PasswordResetService.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,25 @@ async def request_password_reset(self, req: PasswordResetRequest) -> UserSuccess
4545
self.logger.info(
4646
{
4747
"activity_type": ACTIVITY_TYPES["REQUEST_RESET_PASSWORD"],
48-
"message": "User is not active",
48+
"message": MESSAGES["PASSWORD_RESET"]["INACTIVE"],
4949
"metadata": {"user": {"email": req.email}},
5050
}
5151
)
5252
return {
5353
"is_success": False,
54-
"message": "You can only reset the password of an active account!",
54+
"message": MESSAGES["PASSWORD_RESET"]["INACTIVE"],
5555
}
5656
elif not existing_user.is_enabled:
5757
self.logger.info(
5858
{
5959
"activity_type": ACTIVITY_TYPES["REQUEST_RESET_PASSWORD"],
60-
"message": "User is not enabled",
60+
"message": MESSAGES["PASSWORD_RESET"]["DISABLED"],
6161
"metadata": {"user": {"email": req.email}},
6262
}
6363
)
6464
return {
6565
"is_success": False,
66-
"message": "You can only reset the password of an enabled account!",
66+
"message": MESSAGES["PASSWORD_RESET"]["DISABLED"],
6767
}
6868
password_reset_token = self.utility_service.generate_uuid()
6969
uuid = password_reset_token["uuid"]
@@ -75,7 +75,7 @@ async def request_password_reset(self, req: PasswordResetRequest) -> UserSuccess
7575
self.logger.info(
7676
{
7777
"activity_type": ACTIVITY_TYPES["REQUEST_RESET_PASSWORD"],
78-
"message": "Password reset token set",
78+
"message": DYNAMIC_MESSAGES["PASSWORD_RESET"]["EMAIL_SENT"](req.email),
7979
"metadata": {
8080
"user": {"email": req.email},
8181
"reset_token": existing_user.password_reset_token,
@@ -95,7 +95,7 @@ async def confirm_password_reset(
9595
self.logger.warn(
9696
{
9797
"activity_type": "Confirm password reset",
98-
"message": "User doesn't exist",
98+
"message": MESSAGES["USER"]["DOESNT_EXIST"],
9999
"metadata": {"token": req.reset_token},
100100
}
101101
)
@@ -107,25 +107,25 @@ async def confirm_password_reset(
107107
self.logger.info(
108108
{
109109
"activity_type": "Confirm password reset",
110-
"message": "User is not active",
110+
"message": MESSAGES["PASSWORD_RESET"]["INACTIVE"],
111111
"metadata": {"token": req.reset_token},
112112
}
113113
)
114114
return {
115115
"is_success": False,
116-
"message": "You can only reset the password of an active account!",
116+
"message": MESSAGES["PASSWORD_RESET"]["INACTIVE"],
117117
}
118118
elif not existing_user.is_enabled:
119119
self.logger.info(
120120
{
121121
"activity_type": "Confirm password reset",
122-
"message": "User is not enabled",
122+
"message": MESSAGES["PASSWORD_RESET"]["DISABLED"],
123123
"metadata": {"token": req.reset_token},
124124
}
125125
)
126126
return {
127127
"is_success": False,
128-
"message": "You can only reset the password of an enabled account!",
128+
"message": MESSAGES["PASSWORD_RESET"]["DISABLED"],
129129
}
130130

131131
if existing_user.token_expires_at < timezone.now():

0 commit comments

Comments
 (0)