root / accounts / views.py @ 2d2808e2
History | View | Annotate | Download (1.5 kB)
1 |
from django.conf import settings |
---|---|
2 |
from django.core.mail import send_mail |
3 |
from django.contrib.sites.models import Site |
4 |
from django.shortcuts import render_to_response |
5 |
from django.template.context import RequestContext |
6 |
from django.template.loader import render_to_string |
7 |
from django.utils.translation import ugettext_lazy as _ |
8 |
from tastypie.models import ApiKey |
9 |
from registration.models import RegistrationProfile |
10 |
from registration.views import activate as registration_activate |
11 |
|
12 |
def activate(request, activation_key): |
13 |
account = None
|
14 |
activation_key = activation_key.lower() # Normalize before trying anything with it.
|
15 |
try:
|
16 |
rp = RegistrationProfile.objects.get(activation_key=activation_key) |
17 |
account = RegistrationProfile.objects.activate_user(activation_key) |
18 |
api_key = ApiKey(user=rp.user) |
19 |
api_key.save() |
20 |
except:
|
21 |
pass
|
22 |
|
23 |
if account:
|
24 |
# A user has been activated
|
25 |
email = render_to_string("registration/activation_complete.txt",
|
26 |
{"site": Site.objects.get_current(),
|
27 |
"user": account})
|
28 |
send_mail(_("%sUser account activated") % settings.EMAIL_SUBJECT_PREFIX,
|
29 |
email, settings.SERVER_EMAIL, [account.email]) |
30 |
context = RequestContext(request) |
31 |
return render_to_response("registration/activate.html", |
32 |
{ 'account': account,
|
33 |
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS },
|
34 |
context_instance=context) |