1 from unfold.loginrequired import FreeAccessView
3 from manifold.core.query import Query
4 from manifoldapi.manifoldapi import execute_query, execute_admin_query
5 from portal.actions import manifold_update_user, manifold_update_account, manifold_add_account, manifold_delete_account, sfa_update_user, authority_get_pi_emails, authority_get_pis
7 from unfold.page import Page
8 from ui.topmenu import topmenu_items_live, the_user
10 from django.http import HttpResponse, HttpResponseRedirect
11 from django.contrib import messages
12 from django.contrib.auth.decorators import login_required
13 from myslice.theme import ThemeView
14 from portal.models import PendingUser
15 from django.core.mail import EmailMultiAlternatives, send_mail
16 from django.contrib.sites.models import Site
17 from django.contrib.auth.models import User
19 import json, os, re, itertools
22 class ActivateEmailView(FreeAccessView, ThemeView):
23 template_name = "email_activation.html"
24 def dispatch(self, *args, **kwargs):
25 return super(ActivateEmailView, self).dispatch(*args, **kwargs)
28 def get_context_data(self, **kwargs):
30 page = Page(self.request)
31 #page.add_js_files ( [ "js/jquery.validate.js", "js/my_account.register.js", "js/my_account.edit_profile.js" ] )
32 #page.add_css_files ( [ "css/onelab.css", "css/account_view.css","css/plugin.css" ] )
34 for key, value in kwargs.iteritems():
35 #print "%s = %s" % (key, value)
36 if key == "hash_code":
39 if PendingUser.objects.filter(email_hash__iexact = hash_code):
40 #get_user = PendingUser.objects.filter(email_hash__iexact = hash_code)
41 #get_user.status= 'True'
43 #for user in PendingUser.objects.all():
44 # first_name = user.first_name
45 # last_name = user.last_name
46 # authority_hrn = user.authority_hrn
47 # public_key = user.public_key
49 # user_hrn = user.user_hrn
50 PendingUser.objects.filter(email_hash__iexact = hash_code).update(status='True')
51 activation = 'success'
52 # sending email after activation success
54 request = PendingUser.objects.filter(email_hash= hash_code)
55 split_authority_hrn = request[0].authority_hrn.split('.')[0]
56 pis = authority_get_pis(request, split_authority_hrn)
59 for e in x['pi_users']:
61 y = User.Objects.get(username = u)
62 if y.username.count("@") != 0:
63 if y.username.split("@")[1] == request[0].user_hrn.split("@")[1]:
64 pi_emails += [y.email]
65 subject = 'User email activated'
66 msg = 'The user %s has validated his/her email. Now you can validate his/her account' % (request[0].login)
67 send_mail(subject, msg, 'support@fibre.org.br', pi_emails, fail_silently = False)
69 print "error sending the email!"
71 # Send an email: the recipients are the PI of the authority
72 # If No PI is defined for this Authority, send to a default email (different for each theme)
73 # recipients = authority_get_pi_emails(wsgi_request, authority_hrn)
74 # theme.template_name = 'user_request_email.html'
75 # html_content = render_to_string(theme.template, request)
76 # theme.template_name = 'user_request_email.txt'
77 # text_content = render_to_string(theme.template, request)
78 # theme.template_name = 'user_request_email_subject.txt'
79 # subject = render_to_string(theme.template, request)
80 # subject = subject.replace('\n', '')
81 # theme.template_name = 'email_default_sender.txt'
82 # sender = render_to_string(theme.template, request)
83 # sender = sender.replace('\n', '')
84 # msg = EmailMultiAlternatives(subject, text_content, sender, recipients)
85 # msg.attach_alternative(html_content, "text/html")
87 # except Exception, e:
88 # print "Failed to send email, please check the mail templates and the SMTP configuration of your server"
90 # traceback.print_exc()
96 current_site = Site.objects.get_current()
97 current_site = current_site.domain
100 context = super(ActivateEmailView, self).get_context_data(**kwargs)
101 context['activation_status'] = activation
102 # XXX This is repeated in all pages
103 # more general variables expected in the template
104 context['title'] = 'Platforms connected to MySlice'
105 # the menu items on the top
106 context['topmenu_items'] = topmenu_items_live('My Account', page)
107 # so we can sho who is logged
108 context['username'] = the_user(self.request)
109 #context['first_name'] = first_name
110 #context['last_name'] = last_name
111 #context['authority_hrn'] = authority_hrn
112 #context['public_key'] = public_key
113 #context['email'] = email
114 #context['user_hrn'] = user_hrn
115 #context['current_site'] = current_site
116 context['theme'] = self.theme
117 # context ['firstname'] = config['firstname']
118 prelude_env = page.prelude_env()
119 context.update(prelude_env)