Skip to content

Commit

Permalink
fix: Fix bugs in confirm email module
Browse files Browse the repository at this point in the history
  • Loading branch information
drorganvidez committed Sep 13, 2024
1 parent e7cd3f8 commit 58217a0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
5 changes: 1 addition & 4 deletions app/modules/auth/routes.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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():
Expand Down
3 changes: 3 additions & 0 deletions app/modules/auth/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 0 additions & 1 deletion app/modules/captcha/services.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import base64
from io import BytesIO
import random
import string
from PIL import Image
from captcha.image import ImageCaptcha

Expand Down
9 changes: 6 additions & 3 deletions app/modules/confirmemail/services.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,6 +12,8 @@
# Load environment variables
load_dotenv()

authentication_service = AuthenticationService()


class ConfirmemailService(BaseService):
def __init__(self):
Expand All @@ -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"<a href='{url}'>Please confirm your email</a>"

Expand All @@ -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
return user
1 change: 0 additions & 1 deletion app/modules/mail/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 58217a0

Please sign in to comment.