Commits

Jannis Leidel committed fe50715 Merge
  • Participants
  • Parent commits 481f8ea, e9873b0

Comments (0)

Files changed (2)

File openid_provider/conf.py

 
 FILESTORE_PATH = getattr(settings, 'OPENID_PROVIDER_FILESTORE_PATH',
                          os.path.join(tempdir, 'openid-filestore'))
+
+SREG_DATA_CALLBACK = getattr(settings, 'OPENID_SREG_DATA_CALLBACK',
+                             'openid_provder.utils.get_default_sreg_data')

File openid_provider/utils.py

     package, module = path.rsplit('.', 1)
     return getattr(import_module(package), module)
 
-def add_sreg_data(request, orequest, oresponse):
-    sreg_req = sreg.SRegRequest.fromOpenIDRequest(orequest)
-    sreg_resp = sreg.SRegResponse.extractResponse(sreg_req, {
+def get_default_sreg_data(request, orequest):
+    return {
         'email': request.user.email,
         'nickname': request.user.username,
         'fullname': request.user.get_full_name(),
-    })
+    }
+
+def add_sreg_data(request, orequest, oresponse):
+    callback = get_sreg_callback()
+    if callback is None or not callable(callback):
+        return
+    sreg_data = callback(request, orequest)
+    sreg_req = sreg.SRegRequest.fromOpenIDRequest(orequest)
+    sreg_resp = sreg.SRegResponse.extractResponse(sreg_req, sreg_data)
     oresponse.addExtension(sreg_resp)
 
+def get_sreg_callback():
+    try:
+        return import_module_attr(conf.SREG_DATA_CALLBACK)
+    except (ImportError, AttributeError):
+        return None
+
 def get_store(request):
     try:
         store_class = import_module_attr(conf.STORE)