aboutsummaryrefslogtreecommitdiff
path: root/app/auth/email.py
blob: 3510938fd55713bf25727303cf68d0e6a740bcde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-

# Author: G.J.J. van den Burg <gvandenburg@turing.ac.uk>
# License: See LICENSE file
# Copyright: 2020 (c) The Alan Turing Institute

from flask import current_app, render_template

from app.email import send_email


def send_password_reset_email(user):
    token = user.get_reset_password_token()
    send_email(
        "[AnnotateChange] Reset your password",
        sender=current_app.config["ADMINS"][0],
        recipients=[user.email],
        text_body=render_template(
            "email/reset_password.txt", user=user, token=token
        ),
        html_body=render_template(
            "email/reset_password.html", user=user, token=token
        ),
    )


def send_email_confirmation_email(user):
    token = user.get_email_confirmation_token()
    send_email(
        "[AnnotateChange] Confirm your email",
        sender=current_app.config["ADMINS"][0],
        recipients=[user.email],
        text_body=render_template(
            "email/confirm_email.txt", user=user, token=token
        ),
        html_body=render_template(
            "email/confirm_email.html", user=user, token=token
        ),
    )