fine-tuning login

This commit is contained in:
2020-05-10 13:51:54 -05:00
parent e6fcb847f0
commit 7fe0d9a9c5
8 changed files with 52 additions and 41 deletions

View File

@ -18,7 +18,7 @@ from capsulflask.db import get_model
bp = Blueprint("auth", __name__, url_prefix="/auth")
def account_required(view):
"""View decorator that redirects anonymous users to the login page."""
"""View decorator that redirects non-logged-in users to the login page."""
@functools.wraps(view)
def wrapped_view(**kwargs):
@ -36,31 +36,34 @@ def login():
error = None
if not email:
error = "Email is required."
error = "email is required"
elif not re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", email):
error = "Enter a valid email address."
error = "enter a valid email address"
if error is None:
token = get_model().login(email)
if token is None:
error = "too many logins. please use one of the existing login links that have been emailed to you"
else:
link = f"{current_app.config['BASE_URL']}/auth/magic/{token}"
link = f"{current_app.config['BASE_URL']}/auth/magic/{token}"
current_app.config["FLASK_MAIL_INSTANCE"].send(
Message(
"Click This Link to Login to Capsul",
body=f"""
Navigate to {link} to log into capsul.
current_app.config["FLASK_MAIL_INSTANCE"].send(
Message(
"Click This Link to Login to Capsul",
body=f"""
Navigate to {link} to log into capsul.
""",
html=f"""
Navigate to <a href="{link}">{link}</a> to log into capsul.
""",
sender=current_app.config['MAIL_DEFAULT_SENDER'],
recipients=[email]
If you didn't request this, ignore this message.
""",
html=f"""
<p>Navigate to <a href="{link}">{link}</a> to log into capsul.</p>
<p>If you didn't request this, ignore this message.</p>
""",
recipients=[email]
)
)
)
return render_template("check-your-email.html")
return render_template("login-landing.html", email=email)
flash(error)