class AuthForm Form openid_url CharField label OpenID max_length 200 r

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class AuthForm(Form):
openid_url = CharField(label='OpenID', max_length=200, required=True)
def __init__(self, session, *args, **kwargs):
Form.__init__(self, *args, **kwargs)
self.session = session
def _site_url(self):
from django.contrib.sites.models import Site
site = Site.objects.get_current()
return 'http://' + site.domain
def clean_openid_url(self):
from cicero.auth import create_request, OpenIdError
try:
self.request = create_request(self.cleaned_data['openid_url'], self.session)
except OpenIdError, e:
raise ValidationError(e)
return self.cleaned_data['openid_url']
def auth_redirect(self, target, view_name, acquire=None, args=[], kwargs={}):
from django.core.urlresolvers import reverse
site_url = self._site_url()
trust_url = settings.OPENID_TRUST_URL or (site_url + '/')
return_to = site_url + reverse(view_name, args=args, kwargs=kwargs)
self.request.return_to_args['redirect'] = target
if acquire:
self.request.return_to_args['acquire_article'] = str(acquire.id)
return self.request.redirectURL(trust_url, return_to)