Skip to content

Commit 0320fb3

Browse files
committed
Added html mail for user registration
1 parent d6bfa44 commit 0320fb3

File tree

4 files changed

+438
-7
lines changed

4 files changed

+438
-7
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
22
max-line-length = 120
33
exclude = venv/* frontend/*
4-
ignore = E402, W291
4+
ignore = E402, W291, W503

backend/PyMatcha/routes/api/auth.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
from itsdangerous import BadSignature
3434
from itsdangerous import SignatureExpired
3535
from PyMatcha import ACCESS_TOKEN_EXPIRES
36+
from flask import Blueprint, request, redirect, render_template
37+
38+
from itsdangerous import SignatureExpired, BadSignature
39+
40+
import flask_jwt_extended as fjwt
41+
3642
from PyMatcha import redis
3743
from PyMatcha import REFRESH_TOKEN_EXPIRES
3844
from PyMatcha.models.user import get_user
@@ -50,6 +56,14 @@
5056
from PyMatcha.utils.success import SuccessOutput
5157
from PyMatcha.utils.success import SuccessOutputMessage
5258

59+
import PyMatcha.models.user as user
60+
from PyMatcha.errors import ConflictError, NotFoundError, BadRequestError, UnauthorizedError
61+
from PyMatcha.success import SuccessOutputMessage, Success, SuccessOutput
62+
from PyMatcha.utils.confirm_token import generate_confirmation_token, confirm_token
63+
from PyMatcha.utils.mail import send_mail_html, send_mail_text
64+
from PyMatcha.utils.decorators import validate_required_params
65+
from PyMatcha.utils import hash_password
66+
5367

5468
REQUIRED_KEYS_USER_CREATION = {"username": str, "email": str, "password": str, "first_name": str, "last_name": str}
5569
REQUIRED_KEYS_PASSWORD_FORGOT = {"email": str}
@@ -80,12 +94,30 @@ def api_create_user():
8094
raise e
8195
else:
8296
token = generate_confirmation_token(email=data["email"], token_type="confirm")
83-
send_mail_text.delay(
84-
dest=data["email"],
85-
subject="Confirm your email for PyMatcha",
86-
body=os.getenv("APP_URL") + "/auth/confirm/" + token,
97+
title = "Confirm your email address"
98+
text1 = "Thank you for registering on PyMatcha !"
99+
text2 = "Please confirm your email address using the following link"
100+
text3 = "Once your email is confirmed, you can log in"
101+
text4 = (
102+
"If the button didn't work, copy and paste this url in your web browser: "
103+
+ os.getenv("APP_URL")
104+
+ "/auth/confirm/"
105+
+ token
87106
)
88107
current_app.logger.debug("New user {} successfully created".format(new_user.email))
108+
buttonlink = os.getenv("APP_URL") + "/auth/confirm/" + token
109+
buttontext = "Confirm my email"
110+
rendered_html = render_template(
111+
"email.html.jinja2",
112+
title=title,
113+
text1=text1,
114+
text2=text2,
115+
text3=text3,
116+
text4=text4,
117+
buttonlink=buttonlink,
118+
buttontext=buttontext,
119+
)
120+
send_mail_html.delay(dest=data["email"], subject=title, html=rendered_html)
89121
return SuccessOutputMessage("email", new_user.email, "New user successfully created.")
90122

91123

0 commit comments

Comments
 (0)