From 0750e3109aedc0b56f54ee44ee9dd26d708c82fc Mon Sep 17 00:00:00 2001
From: Christian Dresen <c.dresen@fh-muenster.de>
Date: Tue, 11 Oct 2016 19:30:22 +0200
Subject: [PATCH] [WarpAuth] Fixed missing card id error while changing profile
 ids

---
 .../warpauth/profile/information.html         |  2 +-
 www/web/warpauth/views/profile.py             | 20 +++++++++++++++----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/www/web/warpauth/templates/warpauth/profile/information.html b/www/web/warpauth/templates/warpauth/profile/information.html
index 6e5622a..bb9771a 100644
--- a/www/web/warpauth/templates/warpauth/profile/information.html
+++ b/www/web/warpauth/templates/warpauth/profile/information.html
@@ -7,7 +7,7 @@
     <div class="panel panel-default">
         <div class="panel-body">
         {% if error_info %}
-            <div class="alert alert-danger">{{ error_info }}</div><br>
+            <div class="alert alert-danger">{% trans error_info %}</div><br>
         {% endif %}
         {% if success_info %}
             <div class="alert alert-success">{% trans "information_changed_successfully" %}</div><br>
diff --git a/www/web/warpauth/views/profile.py b/www/web/warpauth/views/profile.py
index c4d3868..3505b7e 100644
--- a/www/web/warpauth/views/profile.py
+++ b/www/web/warpauth/views/profile.py
@@ -44,16 +44,28 @@ def change_information(request):
     if request.method != 'POST':
         return redirect("profile_index")
 
+
     user = LdapUser.objects.get(uid=str(request.user))
-    first_name = request.POST["first_name"]
-    last_name = request.POST["last_name"]
+    if "first_name" in request.POST:
+        first_name = request.POST["first_name"]
+    if "last_name" in request.POST:
+        last_name = request.POST["last_name"]
+    
+    if "card_id" in request.POST:
+        card_id = request.POST["card_id"]
+    else:
+        card_id = 0
+        
+    if "email" not in request.POST:
+        page_context["error_info"] = "err_invalid_email"
+        return HttpResponse(render(request, 'warpauth/profile.html', page_context))
+        
     email = request.POST["email"]
-    card_id = request.POST["card_id"]
     f = forms.EmailField()
     try:
         f.clean(email)
     except ValidationError as e:
-        page_context["error_info"] = "Invalid Email"
+        page_context["error_info"] = "err_invalid_email"
         return HttpResponse(render(request, 'warpauth/profile.html', page_context))
     cn = first_name + " " + last_name
     cn = cn.strip()
-- 
GitLab