1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import os
18 import random
19 import sys
20 import time
21 try:
22 from hashlib import md5 as _md5
23 except ImportError:
24 import md5
25 _md5 = md5.new
26
27 from django.conf import settings
28 from django.template.loader import render_to_string
29 from django.contrib.auth.models import User
30 from django.contrib.sites.models import Site
31 from django.db import models
32 from django.utils.translation import ugettext_lazy as _
33
34 from madrona.openid.signals import oid_associate
35
36 __all__ = ['Nonce', 'Association', 'UserAssociation']
37
38 -class Nonce(models.Model):
46
58
60 """
61 model to manage association between openid and user
62 """
63 openid_url = models.CharField(primary_key=True, blank=False,
64 max_length=255, verbose_name=_('OpenID URL'))
65 user = models.ForeignKey(User, verbose_name=_('User'))
66
69
70 - def save(self, send_email=True):
71 super(UserAssociation, self).save()
72 if send_email:
73 from django.core.mail import send_mail
74 current_site = Site.objects.get_current()
75 subject = render_to_string('authopenid/associate_email_subject.txt',
76 {'site': current_site,
77 'user': self.user})
78 message = render_to_string('authopenid/associate_email.txt',
79 {'site': current_site,
80 'user': self.user,
81 'openid': self.openid_url
82 })
83
84 send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
85 [self.user.email], fail_silently=True)
86 oid_associate.send(sender=self, user=self.user, openid=self.openid_url)
87
91