2012-09-28 22:29:48 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright: (c) 2008, Jarek Zgoda <jarek.zgoda@gmail.com>
|
|
|
|
|
|
|
|
__revision__ = '$Id: views.py 21 2008-12-05 09:21:03Z jarek.zgoda $'
|
|
|
|
|
|
|
|
|
2017-03-16 14:08:27 +01:00
|
|
|
from django.shortcuts import render
|
2012-09-28 22:29:48 +02:00
|
|
|
from django.template import RequestContext
|
|
|
|
from django.conf import settings
|
2016-06-03 03:47:17 +02:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
2012-09-28 22:29:48 +02:00
|
|
|
|
|
|
|
from confirmation.models import Confirmation
|
2016-09-12 07:51:02 +02:00
|
|
|
from zerver.models import PreregistrationUser
|
2013-06-17 18:01:22 +02:00
|
|
|
|
2012-09-28 22:29:48 +02:00
|
|
|
|
|
|
|
def confirm(request, confirmation_key):
|
2016-06-03 03:47:17 +02:00
|
|
|
# type: (HttpRequest, str) -> HttpResponse
|
2012-09-28 22:29:48 +02:00
|
|
|
confirmation_key = confirmation_key.lower()
|
|
|
|
obj = Confirmation.objects.confirm(confirmation_key)
|
|
|
|
confirmed = True
|
|
|
|
if not obj:
|
|
|
|
# confirmation failed
|
|
|
|
confirmed = False
|
|
|
|
try:
|
|
|
|
# try to get the object we was supposed to confirm
|
|
|
|
obj = Confirmation.objects.get(confirmation_key=confirmation_key)
|
|
|
|
except Confirmation.DoesNotExist:
|
|
|
|
pass
|
|
|
|
ctx = {
|
|
|
|
'object': obj,
|
|
|
|
'confirmed': confirmed,
|
|
|
|
'days': getattr(settings, 'EMAIL_CONFIRMATION_DAYS', 10),
|
2012-09-28 22:34:47 +02:00
|
|
|
'key': confirmation_key,
|
2013-11-05 22:13:59 +01:00
|
|
|
'full_name': request.GET.get("full_name", None),
|
2012-09-28 22:29:48 +02:00
|
|
|
}
|
|
|
|
templates = [
|
|
|
|
'confirmation/confirm.html',
|
|
|
|
]
|
2016-09-12 07:51:02 +02:00
|
|
|
if obj and isinstance(obj, (PreregistrationUser, Confirmation)):
|
2012-09-28 22:29:48 +02:00
|
|
|
# if we have an object, we can use specific template
|
2016-06-20 17:19:54 +02:00
|
|
|
templates.insert(0, 'confirmation/confirm_%s.html' % (obj._meta.model_name,))
|
2017-03-16 14:08:27 +01:00
|
|
|
return render(request, templates, context=ctx)
|