Skip to content

Commit

Permalink
Extract get_confirmation_code from get_confirmation_url
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Mar 22, 2018
1 parent 1909b0f commit 62ab838
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Change log
"Google" because that is all that is supported right now.
- Added the possibility to use callables in ``ADMIN_OAUTH_PATTERNS``
instead of hard-coded staff email addresses.
- Extracted the confirmation code generation from
``get_confirmation_url`` as ``get_confirmation_code``.


`0.6`_ (2017-12-04)
Expand Down
23 changes: 17 additions & 6 deletions authlib/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ def get_last_login_timestamp(user):
return int(user.last_login.strftime('%s')) if user.last_login else 0


def get_confirmation_code(email, request, *, user=None):
"""
Returns the code for the confirmation URL
"""
code = [email, '', '']
if user:
code[1] = str(user.id)
code[2] = int_to_base36(get_last_login_timestamp(user))
return get_signer().sign(':'.join(code))


def get_confirmation_url(email, request, user=None,
name='email_registration_confirm'):
"""
Expand All @@ -81,12 +92,12 @@ def get_confirmation_url(email, request, user=None,
code[1] = str(user.id)
code[2] = int_to_base36(get_last_login_timestamp(user))

return request.build_absolute_uri(
reverse(
name,
kwargs={
'code': get_signer().sign(u':'.join(code)),
}))
return request.build_absolute_uri(reverse(
name,
kwargs={
'code': get_confirmation_code(email, request, user=user),
},
))


def send_registration_mail(email, *, request, user=None):
Expand Down

0 comments on commit 62ab838

Please sign in to comment.