Anonymous avatar Anonymous committed aeb9bea

allow possibility to get needed sreg fields by setting OPENID_SREG in
settings.py.

Comments (0)

Files changed (2)

django_authopenid/views.py

         context[key] = callable(value) and value() or value
     return context    
     
-def ask_openid(request, openid_url, redirect_to, on_failure=None,
-        sreg_request=None):
+def ask_openid(request, openid_url, redirect_to, on_failure=None):
     """ basic function to ask openid and return response """
     on_failure = on_failure or signin_failure
     
     except DiscoveryFailure:
         msg = _("The OpenID %s was invalid" % openid_url)
         return on_failure(request, msg)
-
-    if sreg_request:
-        auth_request.addExtension(sreg_request)
+    
+    # set sreg extension
+    # we always ask for nickname and email
+    sreg_fields = getattr(settings, 'OPENID_SREG', {})
+    sreg_fields.update({ "optional": ['nickname', 'email'] })
+    auth_request.addExtension(sreg.SRegRequest(**sreg_fields))
+    
     redirect_url = auth_request.redirectURL(trust_root, redirect_to)
     return HttpResponseRedirect(redirect_url)
 
         if 'openid_url' in request.POST.keys():
             form1 = openid_form(data=request.POST)
             if form1.is_valid():
-                sreg_req = sreg.SRegRequest(optional=['nickname', 'email'])
                 redirect_url = "%s%s?%s" % (
                         get_url_host(request),
                         reverse('user_complete_signin'), 
                 return ask_openid(request, 
                         form1.cleaned_data['openid_url'], 
                         redirect_url, 
-                        on_failure=on_failure, 
-                        sreg_request=sreg_req)
+                        on_failure=on_failure)
         else:
             # perform normal django authentification
             form2 = auth_form(data=request.POST)
         'username': nickname,
     })
     
+    print openid_.sreg
     if request.POST:
         user_ = None
         if not redirect_to or '//' in redirect_to or ' ' in redirect_to:

example/settings.py

 LOGIN_REDIRECT_URL = '/'
 ACCOUNT_ACTIVATION_DAYS = 10
 
+OPENID_SREG = {
+    "required": ['fullname', 'country']
+}
+
 INSTALLED_APPS = (
     'django.contrib.auth',
     'django.contrib.contenttypes',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.