render_to openid signin html def signin request sreg None extension_ar

 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
@render_to('openid/signin.html')
def signin(request, sreg=None, extension_args={}):
openid_url = None
if is_valid_next_url(request.GET.get('next')):
next = request.GET['next']
elif is_valid_next_url(get_address(request.META.get('HTTP_REFERER'), request)):
next = get_address(request.META['HTTP_REFERER'], request)
else:
next = getattr(settings, 'OPENID_REDIRECT_NEXT', '/')
def get_with_next(url, next):
if next:
return '%s?%s' % (url, urlencode({'next': next}))
else:
return url
if request.user.is_authenticated() and 'force' not in request.GET:
return HttpResponseRedirect(next)
request_path = get_with_next(request.path, next)
if request.method == 'POST':
form = OpenidSigninForm(request.POST, auto_id='id_%s')
if form.is_valid():
# first remove email and nickname from sreg if the are in to prevent dup
extension_args['sreg.optional'] = 'email,nickname'
if sreg:
sreg = ','.join([arg for arg in sreg.split(',') if arg not in extension_args['sreg.optional']])
extension_args['sreg.optional'] += ',' + sreg
trust_root = getattr(settings, 'OPENID_TRUST_ROOT', absolutize_uri(request, '/'))
redirect_to = get_with_next(absolutize_uri(request, reverse('openid_complete')), next)
if xri.identifierScheme(form.cleaned_data['openid_url']) == 'XRI' and getattr(
settings, 'OPENID_DISALLOW_INAMES', False):
return failure(request, _("i-names are not supported"))
consumer = Consumer(request.session, DjangoOpenIDStore())
try:
auth_request = consumer.begin(form.cleaned_data['openid_url'])
except DiscoveryFailure:
return failure(request, _("The OpenID was invalid"))
# Add extension args (for things like simple registration)
for name, value in extension_args.items():
namespace, key = name.split('.', 1)
auth_request.addExtensionArg(namespace, key, value)
redirect_url = auth_request.redirectURL(trust_root, redirect_to)
return HttpResponseRedirect(redirect_url)
else:
form = OpenidSigninForm(auto_id='id_%s')
return {
'form': form,
'action': request_path,
}