ask the PI to click save
[plstackapi.git] / planetstack / core / dashboard / views / tenant.py
index 762409e..5a45033 100644 (file)
@@ -4,6 +4,7 @@ import functools
 from django.contrib.auth.models import BaseUserManager
 from django.core import serializers
 from django.core.mail import EmailMultiAlternatives
+import json
 
 BLESSED_DEPLOYMENTS = ["US-MaxPlanck", "US-GeorgiaTech", "US-Princeton", "US-Washington", "US-Stanford"]
 
@@ -13,11 +14,29 @@ class RequestAccessView(View):
        firstname = request.POST.get("firstname", "0")
        lastname = request.POST.get("lastname", "0")
        site = request.POST.get("site","0")
+        # see if it already exists
+        user=User.objects.filter(email=BaseUserManager.normalize_email(email))
+        if (user):
+             user = user[0]
+             if user.is_active:
+                 # force a new email to be sent
+                 user.is_registering=True
+                 user.save()
+                 return HttpResponse(json.dumps({"error": "already_approved"}), content_type='application/javascript')
+             else:
+                 return HttpResponse(json.dumps({"error": "already_pending"}), content_type='application/javascript')
+
+        user=User.deleted_objects.filter(email=BaseUserManager.normalize_email(email))
+        if (user):
+            return HttpResponse(json.dumps({"error": "is_deleted"}), content_type='application/javascript')
+
        user = User(
             email=BaseUserManager.normalize_email(email),
             firstname=firstname,
             lastname=lastname,
-           is_active=False
+           is_active=False,
+            is_admin=False,
+            is_registering=True
         )
         user.save()
        user.site=Site.objects.get(name=site)
@@ -29,7 +48,7 @@ class RequestAccessView(View):
                subject, from_email, to = 'Authorize OpenCloud User Account', 'support@opencloud.us', str(sp.user)
                text_content = 'This is an important message.'
                html_content = """<p>Please authorize the following user on site """+site+""": <br><br>User: """+firstname+""" """+lastname+"""<br>Email: """+email+"""<br><br>
-Check the checkbox next to Is Active property at <a href="""+userUrl+"""> this link</a> to authorize the user. If you do not recognize this individual, or otherwise do not want to approve this account, please ignore this email. If you do not approve this request in 48 hours, the account will automatically be deleted.</p>"""
+Check the checkbox next to Is Active property at <a href="""+userUrl+"""> this link</a> to authorize the user, and then click the Save button. If you do not recognize this individual, or otherwise do not want to approve this account, please ignore this email. If you do not approve this request in 48 hours, the account will automatically be deleted.</p>"""
                msg = EmailMultiAlternatives(subject,text_content, from_email, [to])
                msg.attach_alternative(html_content, "text/html")
                msg.send()