Skip to content

Commit b6e0151

Browse files
committed
Added email notifications for logging in
1 parent 32ec25c commit b6e0151

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

backend/PyMatcha/routes/api/auth/login.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from PyMatcha.utils.decorators import validate_params
3434
from PyMatcha.utils.errors import NotFoundError
3535
from PyMatcha.utils.errors import UnauthorizedError
36+
from PyMatcha.utils.mail import send_mail_text
3637
from PyMatcha.utils.password import check_password
3738
from PyMatcha.utils.success import Success
3839
from PyMatcha.utils.success import SuccessOutput
@@ -73,6 +74,12 @@ def auth_login():
7374
u.is_online = True
7475
u.dt_lastseen = datetime.datetime.utcnow()
7576
u.save()
77+
send_mail_text.delay(
78+
dest=u.email,
79+
subject="[Matcha] Login notification",
80+
body=f"Someone logged in into your account at {datetime.datetime.utcnow()}."
81+
f"If you believe it wasn't you, please change your password immediately!",
82+
)
7683
ret = {"access_token": access_token, "refresh_token": refresh_token, "is_profile_completed": u.is_profile_completed}
7784
return SuccessOutput("return", ret)
7885

backend/PyMatcha/routes/api/auth/password.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
You should have received a copy of the GNU General Public License
1717
along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
"""
19+
import datetime
1920
import logging
2021

2122
from flask import Blueprint
@@ -31,6 +32,7 @@
3132
from PyMatcha.utils.errors import BadRequestError
3233
from PyMatcha.utils.errors import NotFoundError
3334
from PyMatcha.utils.mail import send_mail_html
35+
from PyMatcha.utils.mail import send_mail_text
3436
from PyMatcha.utils.static import FRONTEND_PASSWORD_RESET_URL
3537
from PyMatcha.utils.success import Success
3638

@@ -87,6 +89,12 @@ def reset_password():
8789
u.password = hash_password(data["password"])
8890
u.previous_reset_token = token
8991
u.save()
92+
send_mail_text.delay(
93+
dest=u.email,
94+
subject="[Matcha] Password change notification",
95+
body=f"Your password was changed at {datetime.datetime.utcnow()}."
96+
f"If you believe it wasn't you, please change it immediately!",
97+
)
9098
logging.debug("Password reset successfully")
9199
return Success("Password reset successful.")
92100

backend/PyMatcha/routes/api/profile/edit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ def edit_password():
212212
current_user.save()
213213
send_mail_text.delay(
214214
dest=current_user.email,
215-
subject="Password change notification",
215+
subject="[Matcha] Password change notification",
216216
body=f"Your password was changed at {datetime.datetime.utcnow()}."
217-
f"If you believe it wasn't you, please change it immediatly!",
217+
f"If you believe it wasn't you, please change it immediately!",
218218
)
219219
logging.info(f"Edited email for {current_user.id}")
220220
return Success("User password successfully updated.")

0 commit comments

Comments
 (0)