pass emails to templates

This commit is contained in:
Cayo Puigdefabregas 2022-10-20 12:51:20 +02:00
parent c93c143cc8
commit 469ce1c6e0
5 changed files with 18 additions and 19 deletions

View File

@ -1,5 +1,5 @@
from flask import current_app as app from flask import current_app as app
from flask import g from flask import g, render_template
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from werkzeug.security import generate_password_hash from werkzeug.security import generate_password_hash
from wtforms import ( from wtforms import (
@ -188,25 +188,21 @@ class UserNewRegisterForm(FlaskForm):
host = app.config.get('HOST') host = app.config.get('HOST')
token = self._token token = self._token
url = f'https://{ host }/validate_user/{ token }' url = f'https://{ host }/validate_user/{ token }'
message = """ template = 'ereuse_devicehub/email_validation.txt'
Hello, you are register in Usody.com message = render_template(template, url=url)
Please for activate your account click in the next address: """
message += url
subject = "Validate email for register in Usody.com" subject = "Validate email for register in Usody.com"
send_email(subject, [self.email.data], message) send_email(subject, [self.email.data], message)
def send_mail_admin(self, user): def send_mail_admin(self, user):
person = next(iter(user.individuals)) person = next(iter(user.individuals))
email = person.email context = {
name = person.name 'email': person.email,
telephone = person.telephone 'name': person.name,
'telephone': person.telephone,
message = f"""A new user has been registered. These are your data" }
Name: {name} template = 'ereuse_devicehub/email_admin_new_user.txt'
Telephone: {telephone} message = render_template(template, **context)
Email: {email}
"""
subject = "New Register" subject = "New Register"
email_admin = app.config.get("EMAIL_ADMIN") email_admin = app.config.get("EMAIL_ADMIN")

View File

@ -28,7 +28,4 @@ def send_email(
if html_body: if html_body:
msg.html = html_body msg.html = html_body
Thread( Thread(target=_send_async_email, args=(app._get_current_object(), msg)).start()
target=_send_async_email,
args=(app._get_current_object(), msg)
).start()

View File

@ -0,0 +1,4 @@
A new user has been registered. These are your data
Name: {{ name }}
Telephone: {{ telephone }}
Email: {{ email }}

View File

@ -0,0 +1,2 @@
Hello, you are register in Usody.com
Please for activate your account click in the next address: {{ url }}

View File

@ -91,7 +91,7 @@
</div> </div>
<div class="col-12"> <div class="col-12">
<p class="small mb-0"> <p class="small mb-0">
You have account? <a href="{{ url_for('core.login') }}">Create an account</a> You have account? <a href="{{ url_for('core.login') }}">do Login</a>
</p> </p>
</div> </div>
</form> </form>