From 85d1368f772be139ffdba3bbb2f1bea88b68079d Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Mon, 27 Apr 2020 15:42:24 +0200
Subject: [PATCH] Add error message on login view (permission denied)

Close #211
---
 .../core/templates/two_factor/core/login.html | 51 +++++++++++--------
 1 file changed, 30 insertions(+), 21 deletions(-)

diff --git a/aleksis/core/templates/two_factor/core/login.html b/aleksis/core/templates/two_factor/core/login.html
index 3357221f0..6e0df1a4e 100644
--- a/aleksis/core/templates/two_factor/core/login.html
+++ b/aleksis/core/templates/two_factor/core/login.html
@@ -9,29 +9,38 @@
 {% block content %}
   <h4>{% trans "Login" %}</h4>
 
-  <div class="alert primary">
-    <p>
-      <i class="material-icons left">info</i>
+  {% if wizard.steps.current == "auth" and user.is_authenticated %}
+    <div class="alert warning">
+      <p>
+        <i class="material-icons left">warning</i>
+        {% blocktrans %}You have no permission to view this page. Please login with an other account.{% endblocktrans %}
+      </p>
+    </div>
+  {% else %}
+    <div class="alert primary">
+      <p>
+        <i class="material-icons left">info</i>
 
-      {% if wizard.steps.current == 'auth' %}
-        {% blocktrans %}Enter your credentials.{% endblocktrans %}
-      {% elif wizard.steps.current == 'token' %}
-        {% if device.method == 'call' %}
-          {% blocktrans %}We are calling your phone right now, please enter the
-            digits you hear.{% endblocktrans %}
-        {% elif device.method == 'sms' %}
-          {% blocktrans %}We sent you a text message, please enter the tokens we
-            sent.{% endblocktrans %}
-        {% else %}
-          {% blocktrans %}Please enter the tokens generated by your token
-            generator.{% endblocktrans %}
+        {% if wizard.steps.current == 'auth' %}
+          {% blocktrans %}Please login to see this page.{% endblocktrans %}
+        {% elif wizard.steps.current == 'token' %}
+          {% if device.method == 'call' %}
+            {% blocktrans %}We are calling your phone right now, please enter the
+              digits you hear.{% endblocktrans %}
+          {% elif device.method == 'sms' %}
+            {% blocktrans %}We sent you a text message, please enter the tokens we
+              sent.{% endblocktrans %}
+          {% else %}
+            {% blocktrans %}Please enter the tokens generated by your token
+              generator.{% endblocktrans %}
+          {% endif %}
+        {% elif wizard.steps.current == 'backup' %}
+          {% blocktrans %}Use this form for entering backup tokens for logging in.
+            These tokens have been generated for you to print and keep safe. Please
+            enter one of these backup tokens to login to your account.{% endblocktrans %}
         {% endif %}
-      {% elif wizard.steps.current == 'backup' %}
-        {% blocktrans %}Use this form for entering backup tokens for logging in.
-          These tokens have been generated for you to print and keep safe. Please
-          enter one of these backup tokens to login to your account.{% endblocktrans %}
-      {% endif %}
-  </div>
+    </div>
+  {% endif %}
 
 
   <form action="" method="post">
-- 
GitLab