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
59
60
61
62
63
64
65
66
67
68
@render_to('openid/signin.html')
def signin(request, sreg=None, extension_args=None, on_failure=None):
on_failure = on_failure or default_on_failure
extension_args = extension_args or {}
openid_url = None
form_signin = OpenidSigninForm()
form_auth = OpenidAuthForm()
next = ''
if with_auth and request.user.is_authenticated():
if is_valid_next_url(request.GET.get('next')):
next = request.GET['next'].strip()
else:
next = getattr(settings, 'OPENID_REDIRECT_NEXT', '/')
return HttpResponseRedirect(next)
request_path = request.path
if request.GET.get('next'):
request_path += '?' + urllib.urlencode({
'next': request.GET['next']
})
if request.method == 'POST':
form = OpenidSigninForm(request.POST)
if form.is_valid():
# first remove email and nickname from sreg if the are in to prevent dup
if with_auth:
if sreg:
sreg = ','.join([arg for arg in sreg.split(',') if arg != 'nickname' or arg != 'email'])
extension_args['sreg.optional'] = 'email,nickname'
if sreg:
extension_args['sreg.optional'] += ',' + sreg
trust_root = getattr(settings, 'OPENID_TRUST_ROOT', get_url_host(request) + '/')
redirect_to = get_url_host(request) + reverse('openidconsumer.views.complete')
if request.GET.get('next') and is_valid_next_url(request.GET['next']):
redirect_to += "?" + urllib.urlencode({
'next': request.GET['next']
})
if xri.identifierScheme(form.cleaned_data['openid_url']) == 'XRI' and getattr(
settings, 'OPENID_DISALLOW_INAMES', False
):
return on_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 on_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()
return {
'form': form,
'action': request_path,
}