Revision 1698da77 accounts/views.py
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)
|
Also available in: Unified diff