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
## 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()
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):