From 8c99e3ac4d3d0787205a46a7404e63f080829232 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Thu, 14 Nov 2024 15:49:45 +0100
Subject: [PATCH] show  uncertain profile verification without token

---
 scipost_django/profiles/models.py                           | 1 +
 .../templates/profiles/_hx_profile_emails_table_row.html    | 6 ++++--
 scipost_django/profiles/views.py                            | 2 +-
 scipost_django/templates/bi/clock-fill.html                 | 4 ++--
 4 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/scipost_django/profiles/models.py b/scipost_django/profiles/models.py
index 7fd86184d..bbfa877a9 100644
--- a/scipost_django/profiles/models.py
+++ b/scipost_django/profiles/models.py
@@ -272,6 +272,7 @@ class ProfileEmail(models.Model):
         return self.email
 
     def reset_verification_token(self):
+        self.verified = False
         self.verification_token = secrets.token_urlsafe(40)
         self.token_expiration = timezone.now() + datetime.timedelta(hours=48)
         self.save()
diff --git a/scipost_django/profiles/templates/profiles/_hx_profile_emails_table_row.html b/scipost_django/profiles/templates/profiles/_hx_profile_emails_table_row.html
index c46368de1..b750d7580 100644
--- a/scipost_django/profiles/templates/profiles/_hx_profile_emails_table_row.html
+++ b/scipost_django/profiles/templates/profiles/_hx_profile_emails_table_row.html
@@ -18,8 +18,10 @@
   </td>
   <td>
 
-    {% if profile_mail.verified %}
+    {% if profile_mail.verified and profile_mail.verification_token %}
       <span class="text-success">{% include "bi/check-circle-fill.html" %}</span>
+    {% elif profile_mail.verified and not profile_mail.verification_token %}
+      <span class="text-warning">{% include "bi/question-circle-fill.html" %}</span>
     {% elif not profile_mail.has_token_expired %}
       <span class="text-warning">{% include "bi/clock-fill.html" %}</span>
     {% else %}
@@ -56,7 +58,7 @@
                 {% if not profile_mail.has_token_expired %}hx-confirm="Your previous verification code has not expired yet. Are you sure you want to resend the verification email?"{% endif %}
                 hx-confirm="This will send a verification email to the address. Are you sure?"
                 hx-patch="{% url 'profiles:_hx_profile_email_request_verification' profile_mail.id %}"
-                {% if profile_mail.verified %}disabled{% endif %}
+                {% if profile_mail.verified and profile_mail.verification_token %}disabled{% endif %}
                 >Verify</button>
       {% endif %}
 
diff --git a/scipost_django/profiles/views.py b/scipost_django/profiles/views.py
index 612aaaf56..d8158b7ca 100644
--- a/scipost_django/profiles/views.py
+++ b/scipost_django/profiles/views.py
@@ -595,7 +595,7 @@ def _hx_profile_email_request_verification(request, email_id):
             tag="danger",
         )
 
-    if not profile_email.verified:
+    if not (profile_email.verified and profile_email.verification_token is not None):
         profile_email.send_verification_email()
         messages.success(
             request,
diff --git a/scipost_django/templates/bi/clock-fill.html b/scipost_django/templates/bi/clock-fill.html
index d9bdcd85b..d61df73cd 100644
--- a/scipost_django/templates/bi/clock-fill.html
+++ b/scipost_django/templates/bi/clock-fill.html
@@ -1,6 +1,6 @@
 <svg xmlns="http://www.w3.org/2000/svg"
-     width="16"
-     height="16"
+     width="1em"
+     height="1em"
      fill="currentColor"
      class="bi bi-clock-fill"
      viewBox="0 0 16 16">
-- 
GitLab