-1

I'm working to modify a cookiecutter Flask app. I'm trying to follow https://realpython.com/blog/python/handling-email-confirmation-in-flask/ to add email authorization.

My original page captures just the email. I then want to ask interested users to fill out a larger form to complete registration.

To do this I send an email that contains the email in the token and looks like:

Welcome! Please follow this link to complete registration:

http://127.0.0.1:5000/register/?token=ImNsdWVtYXJpbmUxQG1haWxpbmF0b3IuY29tIg.CafSGw.5f9hjRwQDeDWmQu4--jYVgbzezw

I then want to capture the token and complete registration doing something like:

@blueprint.route("/register/<token>", methods=['GET', 'POST'])
def register(token):
    form = RegisterForm(request.form, csrf_enabled=False)
    email = confirm_token(token) # decodes email from token
    # look up email here and save registration info to same user object as email
    if form.validate_on_submit():

However first things first and I need to capture the token. Why doesn't the link work to pass the token to the register method

user1592380
  • 34,265
  • 92
  • 284
  • 515

1 Answers1

2

A route of "/register/<token>" would require your link to be in the form of "http://127.0.0.1:5000/register/ImNsdWV...", where the token is a path element, not a query parameter.

If you want to use a query parameter so the url you've given as example works, you need to use a route of "/register/" and then access the token as request.args['token'] instead of it being passed as argument to the function.

mata
  • 67,110
  • 10
  • 163
  • 162