-def send_validation_email(user):
- hash = ValidationHash.objects.create_new(user, 'email', [user.email])
- send_email(_("Email Validation"), [(user.username, user.email)], "auth/email_validation.html", {
- 'validation_code': hash,
- 'user': user
- })
+def send_validation_email(request):
+ if not request.user.is_authenticated():
+ return HttpResponseUnauthorized(request)
+ else:
+ # We check if there are some old validation hashes. If there are -- we delete them.
+ try:
+ hash = ValidationHash.objects.get(user=request.user, type='email')
+ hash.delete()
+ except:
+ pass
+
+ # We don't care if there are previous cashes in the database... In every case we have to create a new one
+ hash = ValidationHash.objects.create_new(request.user, 'email', [request.user.email])
+
+ additional_get_params = urllib.urlencode(dict([k, v.encode('utf-8')] for k, v in request.GET.items()))
+ send_template_email([request.user], "auth/mail_validation.html", {
+ 'validation_code': hash,
+ 'additional_get_params' : additional_get_params
+ })
+
+ request.user.message_set.create(message=_("A message with an email validation link was just sent to your address."))
+ return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
+
+