|
33 | 33 | from itsdangerous import BadSignature |
34 | 34 | from itsdangerous import SignatureExpired |
35 | 35 | 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 | + |
36 | 42 | from PyMatcha import redis |
37 | 43 | from PyMatcha import REFRESH_TOKEN_EXPIRES |
38 | 44 | from PyMatcha.models.user import get_user |
|
50 | 56 | from PyMatcha.utils.success import SuccessOutput |
51 | 57 | from PyMatcha.utils.success import SuccessOutputMessage |
52 | 58 |
|
| 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 | + |
53 | 67 |
|
54 | 68 | REQUIRED_KEYS_USER_CREATION = {"username": str, "email": str, "password": str, "first_name": str, "last_name": str} |
55 | 69 | REQUIRED_KEYS_PASSWORD_FORGOT = {"email": str} |
@@ -80,12 +94,30 @@ def api_create_user(): |
80 | 94 | raise e |
81 | 95 | else: |
82 | 96 | 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 |
87 | 106 | ) |
88 | 107 | 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) |
89 | 121 | return SuccessOutputMessage("email", new_user.email, "New user successfully created.") |
90 | 122 |
|
91 | 123 |
|
|
0 commit comments