Revision 1698da77
b/accounts/views.py | ||
---|---|---|
5 | 5 |
from django.template.context import RequestContext |
6 | 6 |
from django.template.loader import render_to_string |
7 | 7 |
from django.utils.translation import ugettext_lazy as _ |
8 |
|
|
8 |
from flowspy.accounts.models import * |
|
9 |
from flowspy.peers.models import * |
|
10 |
from flowspy.flowspec.forms import * |
|
9 | 11 |
from registration.models import RegistrationProfile |
10 | 12 |
from registration.views import activate as registration_activate |
13 |
from django.views.decorators.cache import never_cache |
|
11 | 14 |
|
15 |
@never_cache |
|
12 | 16 |
def activate(request, activation_key): |
13 |
activation_key = activation_key.lower() # Normalize before trying anything with it. |
|
14 |
account = RegistrationProfile.objects.activate_user(activation_key) |
|
15 |
context = RequestContext(request) |
|
16 |
|
|
17 |
if account: |
|
18 |
# A user has been activated |
|
19 |
email = render_to_string("registration/activation_complete.txt", |
|
20 |
{"site": Site.objects.get_current(), |
|
21 |
"user": account}) |
|
22 |
send_mail(_("%sUser account activated") % settings.EMAIL_SUBJECT_PREFIX, |
|
17 |
account = None |
|
18 |
if request.method == "GET": |
|
19 |
activation_key = activation_key.lower() # Normalize before trying anything with it. |
|
20 |
context = RequestContext(request) |
|
21 |
try: |
|
22 |
rp = RegistrationProfile.objects.get(activation_key=activation_key) |
|
23 |
|
|
24 |
except RegistrationProfile.DoesNotExist: |
|
25 |
return render_to_response("registration/activate.html", |
|
26 |
{ 'account': account, |
|
27 |
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS }, |
|
28 |
context_instance=context) |
|
29 |
try: |
|
30 |
userProfile = rp.user.get_profile() |
|
31 |
except UserProfile.DoesNotExist: |
|
32 |
return render_to_response("registration/activate.html", |
|
33 |
{ 'account': account, |
|
34 |
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS }, |
|
35 |
context_instance=context) |
|
36 |
|
|
37 |
form = UserProfileForm(instance=userProfile) |
|
38 |
form.fields['user'] = forms.ModelChoiceField(queryset=User.objects.filter(pk=rp.user.pk), empty_label=None) |
|
39 |
form.fields['peer'] = forms.ModelChoiceField(queryset=Peer.objects.all(), empty_label=None) |
|
40 |
|
|
41 |
return render_to_response("registration/activate_edit.html", |
|
42 |
{ 'account': account, |
|
43 |
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS, |
|
44 |
'form': form }, |
|
45 |
context_instance=context) |
|
46 |
|
|
47 |
if request.method == "POST": |
|
48 |
context = RequestContext(request) |
|
49 |
request_data = request.POST.copy() |
|
50 |
try: |
|
51 |
user = User.objects.get(pk=request_data['user']) |
|
52 |
up = user.get_profile() |
|
53 |
up.peer = Peer.objects.get(pk=request_data['peer']) |
|
54 |
up.save() |
|
55 |
|
|
56 |
except: |
|
57 |
return render_to_response("registration/activate_edit.html", |
|
58 |
{ 'account': account, |
|
59 |
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS |
|
60 |
}, |
|
61 |
context_instance=context) |
|
62 |
activation_key = activation_key.lower() # Normalize before trying anything with it. |
|
63 |
try: |
|
64 |
rp = RegistrationProfile.objects.get(activation_key=activation_key) |
|
65 |
account = RegistrationProfile.objects.activate_user(activation_key) |
|
66 |
except Exception as e: |
|
67 |
pass |
|
68 |
|
|
69 |
if account: |
|
70 |
# A user has been activated |
|
71 |
email = render_to_string("registration/activation_complete.txt", |
|
72 |
{"site": Site.objects.get_current(), |
|
73 |
"user": account}) |
|
74 |
send_mail(_("%sUser account activated") % settings.EMAIL_SUBJECT_PREFIX, |
|
23 | 75 |
email, settings.SERVER_EMAIL, [account.email]) |
24 |
|
|
25 |
return render_to_response("registration/activate.html", |
|
26 |
{ 'account': account, |
|
27 |
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS }, |
|
28 |
context_instance=context) |
|
76 |
context = RequestContext(request) |
|
77 |
return render_to_response("registration/activate.html",
|
|
78 |
{ 'account': account,
|
|
79 |
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS },
|
|
80 |
context_instance=context)
|
b/flowspec/forms.py | ||
---|---|---|
5 | 5 |
from django.template.defaultfilters import filesizeformat |
6 | 6 |
from flowspy.flowspec.models import * |
7 | 7 |
from flowspy.peers.models import * |
8 |
from flowspy.accounts.models import * |
|
8 | 9 |
from ipaddr import * |
9 | 10 |
from django.core.urlresolvers import reverse |
10 | 11 |
from django.contrib.auth.models import User |
... | ... | |
12 | 13 |
import datetime |
13 | 14 |
from django.core.mail import mail_admins, mail_managers, send_mail |
14 | 15 |
|
16 |
class UserProfileForm(forms.ModelForm): |
|
17 |
class Meta: |
|
18 |
model = UserProfile |
|
15 | 19 |
|
16 | 20 |
class RouteForm(forms.ModelForm): |
17 | 21 |
# name = forms.CharField(help_text=ugettext_lazy("A unique route name," |
b/flowspec/views.py | ||
---|---|---|
291 | 291 |
lastname = lookupShibAttr(settings.SHIB_LASTNAME, request.META) |
292 | 292 |
mail = lookupShibAttr(settings.SHIB_MAIL, request.META) |
293 | 293 |
entitlement = lookupShibAttr(settings.SHIB_ENTITLEMENT, request.META) |
294 |
organization = request.META['HTTP_SHIB_HOMEORGANIZATION'] |
|
294 |
#organization = request.META['HTTP_SHIB_HOMEORGANIZATION']
|
|
295 | 295 |
|
296 | 296 |
if settings.SHIB_AUTH_ENTITLEMENT in entitlement.split(";"): |
297 | 297 |
has_entitlement = True |
298 | 298 |
if not has_entitlement: |
299 | 299 |
error_entitlement = True |
300 |
if not organization: |
|
301 |
error_orgname = True |
|
300 |
# if not organization:
|
|
301 |
# error_orgname = True
|
|
302 | 302 |
if not mail: |
303 | 303 |
error_mail = True |
304 | 304 |
if error_username: |
305 | 305 |
error = _("Your idP should release the HTTP_EPPN attribute towards this service<br>") |
306 |
if error_orgname: |
|
307 |
error = error + _("Your idP should release the HTTP_SHIB_HOMEORGANIZATION attribute towards this service<br>") |
|
306 |
# if error_orgname:
|
|
307 |
# error = error + _("Your idP should release the HTTP_SHIB_HOMEORGANIZATION attribute towards this service<br>")
|
|
308 | 308 |
if error_entitlement: |
309 | 309 |
error = error + _("Your idP should release an appropriate HTTP_SHIB_EP_ENTITLEMENT attribute towards this service<br>") |
310 | 310 |
if error_mail: |
... | ... | |
324 | 324 |
user = authenticate(username=username, firstname=firstname, lastname=lastname, mail=mail, authsource='shibboleth') |
325 | 325 |
if user is not None: |
326 | 326 |
try: |
327 |
peer = Peer.objects.get(domain_name=organization) |
|
328 |
up = UserProfile.objects.get_or_create(user=user,peer=peer) |
|
327 |
peer = user.get_profile().peer |
|
328 |
# peer = Peer.objects.get(domain_name=organization) |
|
329 |
# up = UserProfile.objects.get_or_create(user=user,peer=peer) |
|
329 | 330 |
except: |
330 |
error = _("Your organization's domain name does not match our peers' domain names<br>Please contact Helpdesk to resolve this issue") |
|
331 |
return render_to_response('error.html', {'error': error}, context_instance=RequestContext(request)) |
|
331 |
form = UserProfileForm() |
|
332 |
form.fields['user'] = forms.ModelChoiceField(queryset=User.objects.filter(pk=user.pk), empty_label=None) |
|
333 |
form.fields['peer'] = forms.ModelChoiceField(queryset=Peer.objects.all(), empty_label=None) |
|
334 |
return render_to_response('registration/select_institution.html', {'form': form}, context_instance=RequestContext(request)) |
|
332 | 335 |
if not user_exists: |
333 | 336 |
user_activation_notify(user) |
334 | 337 |
if user.is_active: |
... | ... | |
407 | 410 |
return render_to_response('add_port.html', {'form': form,}, |
408 | 411 |
context_instance=RequestContext(request)) |
409 | 412 |
|
413 |
@never_cache |
|
414 |
def selectinst(request): |
|
415 |
if request.method == 'POST': |
|
416 |
request_data = request.POST.copy() |
|
417 |
user = request_data['user'] |
|
418 |
try: |
|
419 |
existingProfile = UserProfile.objects.get(user=user) |
|
420 |
error = _("Violation warning: User account is already associated with an institution.The event has been logged and our administrators will be notified about it") |
|
421 |
return render_to_response('error.html', {'error': error, 'inactive': True}, |
|
422 |
context_instance=RequestContext(request)) |
|
423 |
except UserProfile.DoesNotExist: |
|
424 |
pass |
|
425 |
|
|
426 |
form = UserProfileForm(request_data) |
|
427 |
if form.is_valid(): |
|
428 |
userprofile = form.save() |
|
429 |
user_activation_notify(userprofile.user) |
|
430 |
error = _("User account <strong>%s</strong> is pending activation. Administrators have been notified and will activate this account within the next days. <br>If this account has remained inactive for a long time contact your technical coordinator or GRNET Helpdesk") %userprofile.user.username |
|
431 |
return render_to_response('error.html', {'error': error, 'inactive': True}, |
|
432 |
context_instance=RequestContext(request)) |
|
433 |
else: |
|
434 |
form.fields['user'] = forms.ModelChoiceField(queryset=User.objects.filter(pk=user.pk), empty_label=None) |
|
435 |
form.fields['institution'] = forms.ModelChoiceField(queryset=Peer.objects.all(), empty_label=None) |
|
436 |
return render_to_response('registration/select_institution.html', {'form': form}, context_instance=RequestContext(request)) |
|
437 |
|
|
410 | 438 |
@login_required |
411 | 439 |
@never_cache |
412 | 440 |
def user_logout(request): |
b/templates/registration/activate_edit.html | ||
---|---|---|
1 |
{% extends "base.html" %} |
|
2 |
{% load i18n %} |
|
3 |
|
|
4 |
|
|
5 |
{% block content %} |
|
6 |
<div class="container-fluid"> |
|
7 |
<div class="row-fluid"> |
|
8 |
<div class="span2"> |
|
9 |
</div><!--/span--> |
|
10 |
|
|
11 |
<div class="span10"> |
|
12 |
<div class="row-fluid"> |
|
13 |
<!--/span--> |
|
14 |
<h3 class="muted">{% trans "Activate User" %}</h3> |
|
15 |
<hr> |
|
16 |
<div class="span10"> |
|
17 |
<form method="POST" class="form-horizontal"> |
|
18 |
{% csrf_token %} |
|
19 |
{% if form.non_field_errors %} |
|
20 |
<p class="error"> |
|
21 |
{{ form.non_field_errors}} |
|
22 |
</p> |
|
23 |
{% endif %} |
|
24 |
<div class="control-group {% if form.user.errors %} error {% endif %}"> |
|
25 |
<label class="control-label" for="id_user"><b>{% trans "User" %}</b></label> |
|
26 |
<div class="controls"> |
|
27 |
{{ form.user }} |
|
28 |
{% if form.user.errors %} <span class="help-inline"> {{ form.user.errors|join:", " }} </span> |
|
29 |
{% endif %} <span class="help-block"> {{ form.user.help_text }}</span> |
|
30 |
</div> |
|
31 |
</div> |
|
32 |
<div class="control-group {% if form.peer.errors %} error {% endif %}"> |
|
33 |
<label class="control-label" for="id_peer"><b>{% trans "Institution" %}</b></label> |
|
34 |
<div class="controls"> |
|
35 |
{{ form.peer }} |
|
36 |
{% if form.peer.errors %} <span class="help-inline"> {{ form.peer.errors|join:", " }} </span> |
|
37 |
{% endif %} <span class="help-block"> {{ form.peer.help_text }}</span> |
|
38 |
</div> |
|
39 |
</div> |
|
40 |
|
|
41 |
<div class="control-group"> |
|
42 |
<div class="controls"> |
|
43 |
<button type="submit" id="applybutton" value="Apply" class="btn btn-primary"/> |
|
44 |
{% trans "Activate" %}</button> |
|
45 |
</div> |
|
46 |
</div> |
|
47 |
</form> |
|
48 |
</div> |
|
49 |
<!--/span--> |
|
50 |
</div><!--/row--> |
|
51 |
</div><!--/span--> |
|
52 |
|
|
53 |
</div><!--/span--> |
|
54 |
</div><!--/.fluid-container--> |
|
55 |
{% endblock %} |
|
56 |
|
|
57 |
|
b/templates/registration/select_institution.html | ||
---|---|---|
1 |
{% extends "base.html" %} |
|
2 |
{% load i18n %} |
|
3 |
|
|
4 |
|
|
5 |
{% block content %} |
|
6 |
<div class="container-fluid"> |
|
7 |
<div class="row-fluid"> |
|
8 |
<div class="span2"> |
|
9 |
</div><!--/span--> |
|
10 |
|
|
11 |
<div class="span10"> |
|
12 |
<div class="row-fluid"> |
|
13 |
<!--/span--> |
|
14 |
<h3 class="muted">{% trans "Select your institution" %}</h3> |
|
15 |
<hr> |
|
16 |
<div class="span10 alert alert-info">Excellent! You are a step away from joining the service. Select your institution from the dropdown list.</div> |
|
17 |
<div class="span10"> |
|
18 |
<form method="POST" class="form-horizontal" action="{% url selectinst %}"> |
|
19 |
{% csrf_token %} {% if form.non_field_errors %} |
|
20 |
<p class="error">{{ form.non_field_errors}}</p> |
|
21 |
{% endif %} |
|
22 |
<div style="display: none">{{form.user}}</div> |
|
23 |
<div |
|
24 |
class="control-group {% if form.peer.errors %} error {% endif %}"> |
|
25 |
<label class="control-label" for="id_peer"><b>{% trans "Institution" %}</b></label> |
|
26 |
<div class="controls"> |
|
27 |
{{ form.peer }} {% if form.peer.errors %} <span |
|
28 |
class="help-inline"> {{ form.peer.errors|join:", " }} </span> |
|
29 |
{% endif %} <span class="help-block"> {{form.peer.help_text }}</span> |
|
30 |
</div> |
|
31 |
</div> |
|
32 |
|
|
33 |
<div class="control-group"> |
|
34 |
<div class="controls"> |
|
35 |
<button type="submit" id="applybutton" value="Apply" |
|
36 |
class="btn btn-primary" /> |
|
37 |
{% trans "Apply" %} |
|
38 |
</button> |
|
39 |
</div> |
|
40 |
</div> |
|
41 |
</form> |
|
42 |
</div> |
|
43 |
<!--/span--> |
|
44 |
</div><!--/row--> |
|
45 |
</div><!--/span--> |
|
46 |
|
|
47 |
</div><!--/span--> |
|
48 |
</div><!--/.fluid-container--> |
|
49 |
{% endblock %} |
|
50 |
|
|
51 |
|
Also available in: Unified diff