diff --git a/ref-test/app/models/entry.py b/ref-test/app/models/entry.py index 4e528e4..b215afc 100644 --- a/ref-test/app/models/entry.py +++ b/ref-test/app/models/entry.py @@ -6,6 +6,7 @@ from .test import Test from flask_login import current_user from flask_mail import Message +from smtplib import SMTPException from datetime import datetime, timedelta from uuid import uuid4 @@ -174,4 +175,7 @@ class Entry(db.Model):
Best wishes,
SKA Refereeing
SKA Refereeing
""" ) - mail.send(email) + try: + mail.send(email) + except SMTPException as exception: + write('system.log', f'SMTP Error while trying to notify new user account creation to {self.get_username()} with error: {exception}') return True, f'User {self.get_username()} was created successfully.' def login(self, remember:bool=False): @@ -109,7 +113,6 @@ class User(UserMixin, db.Model): self.set_password(new_password) self.reset_token = secrets.token_urlsafe(16) self.verification_token = secrets.token_urlsafe(16) - db.session.commit() email = Message( subject='RefTest | Password Reset', recipients=[self.get_email()], @@ -142,11 +145,12 @@ class User(UserMixin, db.Model):SKA Refereeing
""" ) - mail.send(email) - print('Password', new_password) - print('Reset Token', self.reset_token) - print('Verification Token', self.verification_token) - print('Reset Link', f'{url_for("admin._reset", token=self.reset_token, verification=self.verification_token, _external=True)}') + try: + mail.send(email) + except SMTPException as exception: + write('system.log', f'SMTP Error while trying to reset password for {self.get_username()} with error: {exception}') + return jsonify({'error': f'SMTP Error: {exception}'}), 500 + db.session.commit() return jsonify({'success': 'Your password reset link has been generated.'}), 200 def clear_reset_tokens(self): @@ -182,7 +186,10 @@ class User(UserMixin, db.Model):SKA Refereeing
""" ) - mail.send(email) + try: + mail.send(email) + except SMTPException as exception: + write('system.log', f'SMTP Error when trying to delete account {username} with error: {exception}') return True, message def update(self, password:str=None, email:str=None, notify:bool=False): @@ -223,5 +230,8 @@ class User(UserMixin, db.Model):SKA Refereeing
""" ) - mail.send(message) + try: + mail.send(message) + except SMTPException as exception: + write('system.log', f'SMTP Error when trying to update account {self.get_username()} with error: {exception}') return True, f'Account {self.get_username()} has been updated.'