+BLESSED_DEPLOYMENTS = ["US-MaxPlanck", "US-GeorgiaTech", "US-Princeton", "US-Washington", "US-Stanford"]
+
+class RequestAccessView(View):
+ def post(self, request, *args, **kwargs):
+ email = request.POST.get("email", "0")
+ firstname = request.POST.get("firstname", "0")
+ lastname = request.POST.get("lastname", "0")
+ site = request.POST.get("site","0")
+ user = User(
+ email=BaseUserManager.normalize_email(email),
+ firstname=firstname,
+ lastname=lastname,
+ is_active=False
+ )
+ user.save()
+ user.site=Site.objects.get(name=site)
+ user.save(update_fields=['site'])
+ sitePriv = SitePrivilege.objects.filter(site=user.site)
+ userId = user.id
+ userUrl = "http://"+request.get_host()+"/admin/core/user/"+str(userId)
+ for sp in sitePriv:
+ 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>"""
+ msg = EmailMultiAlternatives(subject,text_content, from_email, [to])
+ msg.attach_alternative(html_content, "text/html")
+ msg.send()
+ return HttpResponse(serializers.serialize("json",[user,]), content_type='application/javascript')