aboutsummaryrefslogtreecommitdiff
path: root/gn_auth
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-03-14 10:54:15 -0500
committerFrederick Muriuki Muriithi2025-03-14 10:54:15 -0500
commitc70188b307138dde2f618fb846ac57cd1cc418fb (patch)
treef2b102d5f80e4d4dec83c47844f55af691c0f529 /gn_auth
parentbb6a77dfcb553fcabfff8a3337a569f9e30b6f16 (diff)
downloadgn-auth-c70188b307138dde2f618fb846ac57cd1cc418fb.tar.gz
Make display of number of minutes more human-friendly.
Diffstat (limited to 'gn_auth')
-rw-r--r--gn_auth/auth/authorisation/users/views.py26
-rw-r--r--gn_auth/templates/emails/forgot-password.html2
-rw-r--r--gn_auth/templates/emails/forgot-password.txt2
-rw-r--r--gn_auth/templates/emails/verify-email.html2
-rw-r--r--gn_auth/templates/emails/verify-email.txt2
5 files changed, 29 insertions, 5 deletions
diff --git a/gn_auth/auth/authorisation/users/views.py b/gn_auth/auth/authorisation/users/views.py
index f2e89cc..469bfa1 100644
--- a/gn_auth/auth/authorisation/users/views.py
+++ b/gn_auth/auth/authorisation/users/views.py
@@ -114,6 +114,29 @@ def user_address(user: User) -> Address:
"""Compute the `email.headerregistry.Address` from a `User`"""
return Address(display_name=user.name, addr_spec=user.email)
+
+def display_minutes_for_humans(minutes):
+ """Convert minutes into human-readable display."""
+ _week_ = 10080 # minutes
+ _day_ = 1440 # minutes
+ _remainder_ = minutes
+
+ _human_readable_ = ""
+ if _remainder_ >= _week_:
+ _weeks_ = _remainder_ // _week_
+ _remainder_ = _remainder_ % _week_
+ _human_readable_ += f"{_weeks_} week" + ("s" if _weeks_ > 1 else "")
+
+ if _remainder_ >= _day_:
+ _days_ = _remainder_ // _day_
+ _remainder_ = _remainder_ % _day_
+ _human_readable_ += (" " if bool(_human_readable_) else "") + f"{_days_} day" + ("s" if _days_ > 1 else "")
+
+ if _remainder_ > 0:
+ _human_readable_ += (" " if bool(_human_readable_) else "") + f"{_remainder_} minutes"
+
+ return _human_readable_
+
def send_verification_email(
conn,
user: User,
@@ -137,7 +160,8 @@ def send_verification_email(
client_id=client_id,
redirect_uri=redirect_uri,
verificationcode=verification_code)),
- expiration_minutes=expiration_minutes)
+ expiration_minutes=display_minutes_for_humans(
+ expiration_minutes))
with db.cursor(conn) as cursor:
cursor.execute(
("INSERT INTO "
diff --git a/gn_auth/templates/emails/forgot-password.html b/gn_auth/templates/emails/forgot-password.html
index e40ebb8..5f16a02 100644
--- a/gn_auth/templates/emails/forgot-password.html
+++ b/gn_auth/templates/emails/forgot-password.html
@@ -24,7 +24,7 @@
</p>
<p style="font-weight: bold;color: #ee55ee;">
- The link will expire in <strong>{{expiration_minutes}}</strong> minutes.
+ The link will expire in <strong>{{expiration_minutes}}</strong>.
</p>
<hr />
diff --git a/gn_auth/templates/emails/forgot-password.txt b/gn_auth/templates/emails/forgot-password.txt
index 55a4b13..68abf16 100644
--- a/gn_auth/templates/emails/forgot-password.txt
+++ b/gn_auth/templates/emails/forgot-password.txt
@@ -7,6 +7,6 @@ You (or someone pretending to be you) made a request to change your password. Pl
If you did not request to change your password, simply ignore this email.
-The link will expire {{expiration_minutes}} minutes.
+The link will expire in {{expiration_minutes}}.
Note that if you requested to change your password multiple times, only the latest/newest token will be valid.
diff --git a/gn_auth/templates/emails/verify-email.html b/gn_auth/templates/emails/verify-email.html
index 7f85c1c..11ae575 100644
--- a/gn_auth/templates/emails/verify-email.html
+++ b/gn_auth/templates/emails/verify-email.html
@@ -20,7 +20,7 @@
<p style="font-weight: bold;color: #ee55ee;">
Please note that the verification code will expire in
- <strong>{{expiration_minutes}}</strong> minutes after it was generated.
+ <strong>{{expiration_minutes}}</strong> after it was generated.
</p>
</body>
</html>
diff --git a/gn_auth/templates/emails/verify-email.txt b/gn_auth/templates/emails/verify-email.txt
index 281d682..ecfbfc0 100644
--- a/gn_auth/templates/emails/verify-email.txt
+++ b/gn_auth/templates/emails/verify-email.txt
@@ -9,4 +9,4 @@ If that does not work, please log in to GeneNetwork and copy the verification co
{{verification_code}}
-Please note that the verification code will expire {{expiration_minutes}} minutes after it was generated.
+Please note that the verification code will expire {{expiration_minutes}} after it was generated.