-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addresses the following: - Adds view/URL to support the sending of the token - Adds view/URL to support the input/validation of the token - Small renaming of existing templates to suit the current application context - Adds some supplementary utility functions Contributes towards: #107
- Loading branch information
1 parent
cae9a35
commit f802944
Showing
3 changed files
with
150 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import datetime | ||
import random | ||
|
||
from django.conf import settings | ||
from django.utils import timezone | ||
|
||
from django_otp.util import hex_validator | ||
|
||
|
||
def generate_token() -> str: | ||
""" Generates a 6 digit random number including any leading zeros """ | ||
return str(random.randint(0, 999_999)).zfill(6) | ||
|
||
|
||
def get_challenge_expiration_timestamp(): | ||
""" Sets expiration timestamp at point in future as per the project setting """ | ||
return timezone.now() + datetime.timedelta(seconds=settings.EMAIL_TOKEN_EXPIRATION_IN_SECS) | ||
|
||
|
||
def token_validator(*args, **kwargs): | ||
""" Wraps hex_validator generator satisfying `makemigrations` """ | ||
return hex_validator()(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters