diff --git a/app/modules/auth/routes.py b/app/modules/auth/routes.py index bfa5eda0d..7e9df504d 100644 --- a/app/modules/auth/routes.py +++ b/app/modules/auth/routes.py @@ -1,5 +1,5 @@ from flask import flash, render_template, redirect, url_for, request -from flask_login import current_user, login_user, logout_user +from flask_login import current_user, logout_user from pymysql import IntegrityError from app.modules.auth import auth_bp @@ -52,9 +52,6 @@ def show_signup_form(): return render_template("auth/signup_form.html", form=form) - - - @auth_bp.route('/login', methods=['GET', 'POST']) @guest_required def login(): diff --git a/app/modules/auth/services.py b/app/modules/auth/services.py index fb359dde6..99d9eac7f 100644 --- a/app/modules/auth/services.py +++ b/app/modules/auth/services.py @@ -82,3 +82,6 @@ def get_authenticated_user_profile(self) -> UserProfile | None: def temp_folder_by_user(self, user: User) -> str: return os.path.join(uploads_folder_name(), "temp", str(user.id)) + + def get_by_email(self, email: str, active: bool = True) -> User: + return self.repository.get_by_email(email, active) diff --git a/app/modules/captcha/services.py b/app/modules/captcha/services.py index 971ec8309..9224ccdb6 100644 --- a/app/modules/captcha/services.py +++ b/app/modules/captcha/services.py @@ -1,7 +1,6 @@ import base64 from io import BytesIO import random -import string from PIL import Image from captcha.image import ImageCaptcha diff --git a/app/modules/confirmemail/services.py b/app/modules/confirmemail/services.py index 9ac39d23c..08ce04c28 100644 --- a/app/modules/confirmemail/services.py +++ b/app/modules/confirmemail/services.py @@ -1,4 +1,5 @@ import os +from app.modules.auth.services import AuthenticationService from flask import current_app, url_for from itsdangerous import BadTimeSignature, SignatureExpired, URLSafeTimedSerializer from dotenv import load_dotenv @@ -11,6 +12,8 @@ # Load environment variables load_dotenv() +authentication_service = AuthenticationService() + class ConfirmemailService(BaseService): def __init__(self): @@ -27,7 +30,7 @@ def get_token_from_email(self, email): def send_confirmation_email(self, user_email): token = self.get_token_from_email(user_email) - url = url_for("auth.confirm_user", token=token, _external=True) + url = url_for("confirmemail.confirm_user", token=token, _external=True) html_body = f"Please confirm your email" @@ -47,7 +50,7 @@ def confirm_user_with_token(self, token): except BadTimeSignature: raise Exception("The confirmation link has been tampered with.") - user = self.repository.get_by_email(email, active=False) + user = authentication_service.get_by_email(email, active=False) user.active = True self.repository.session.commit() - return user \ No newline at end of file + return user diff --git a/app/modules/mail/services.py b/app/modules/mail/services.py index 02730f3e1..58e5432ab 100644 --- a/app/modules/mail/services.py +++ b/app/modules/mail/services.py @@ -26,7 +26,6 @@ def init_app(self, app): def send_email(self, subject, recipients, body, html_body=None): msg = Message(subject, sender=self.sender, recipients=recipients) - msg.body = body if html_body: msg.html = html_body