User validated email: updated as timur suggested
[myslice.git] / portal / actions.py
index 0569644..ea87918 100644 (file)
@@ -4,7 +4,8 @@ from manifoldapi.manifoldapi    import execute_query,execute_admin_query
 from portal.models              import PendingUser, PendingSlice, PendingAuthority
 import json
 
-from django.contrib.auth.models import User
+from django.contrib.auth.models  import User
+from django.contrib.sites.models import Site
 from django.contrib.auth        import get_user_model
 from django.template.loader     import render_to_string
 from django.core.mail           import EmailMultiAlternatives, send_mail
@@ -425,8 +426,13 @@ def portal_reject_request(wsgi_request, request_ids):
                 ## RAW SQL queries on Django DB- https://docs.djangoproject.com/en/dev/topics/db/sql/
                 for user in PendingUser.objects.raw('SELECT id,email FROM portal_pendinguser WHERE id = %s', [request['id']]):
                     user_email= user.email
+
+                # get the domain url
+                current_site = Site.objects.get_current()
+                current_site = current_site.domain
+
                 subject = 'User validation denied.'
-                msg = 'You have recently registered to OneLab portal. We are sorry to inform you that, a manager of your institution has rejected your request. Please contact your manager or contact us for further information.'
+                msg = 'You have recently registered to ' + current_site + '. We are sorry to inform you that, a manager of your institution has rejected your request. Please contact the manager of your institution for further information. For any other queries, contact us by replying to this email.'
                 send_mail(subject, msg, 'support@onelab.eu',[user_email], fail_silently=False)
                 # removing from Django auth_user
                 UserModel = get_user_model()
@@ -648,9 +654,25 @@ def sfa_create_user(wsgi_request, request, namespace = None, as_admin = False):
     if not results:
         raise Exception, "Could not create %s. Already exists ?" % sfa_user_params['user_hrn']
     else:
-        subject = 'User validated'
-        msg = 'A manager of your institution has validated your account. You have now full user access to the portal.'
-        send_mail(subject, msg, 'support@onelab.eu',[request['email']], fail_silently=False)       
+        try:
+            theme.template_name = 'user_request_validated.txt'
+            text_content = render_to_string(theme.template, request)
+            theme.template_name = 'user_request_validated.html'
+            html_content = render_to_string(theme.template, request)
+        
+            theme.template_name = 'email_default_sender.txt'
+            sender =  render_to_string(theme.template, request)
+            sender = sender.replace('\n', '')
+
+
+            subject = 'User validated'
+
+            msg = EmailMultiAlternatives(subject, text_content, sender, [request['email']])
+            msg.attach_alternative(html_content, "text/html")
+            msg.send()
+        except Exception, e:
+            print "Failed to send email, please check the mail templates and the SMTP configuration of your server"
+
     return results
 
 def create_user(wsgi_request, request, namespace = None, as_admin = False):