diff .svn/pristine/1a/1ac4dbb6341375ce31f3dc814df9fd5800c3148d.svn-base @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.svn/pristine/1a/1ac4dbb6341375ce31f3dc814df9fd5800c3148d.svn-base	Fri Feb 24 19:09:32 2012 +0000
@@ -0,0 +1,45 @@
+# Mocks out OpenID
+#
+# http://www.northpub.com/articles/2007/04/02/testing-openid-support
+module OpenIdAuthentication
+
+  EXTENSION_FIELDS = {'email'    => 'user@somedomain.com',
+                      'nickname' => 'cool_user',
+                      'country'  => 'US',
+                      'postcode' => '12345',
+                      'fullname' => 'Cool User',
+                      'dob'      => '1970-04-01',
+                      'language' => 'en',
+                      'timezone' => 'America/New_York'}
+
+  protected
+
+    def authenticate_with_open_id(identity_url = params[:openid_url], options = {}) #:doc:
+      if User.find_by_identity_url(identity_url) || identity_url.include?('good')
+        # Don't process registration fields unless it is requested.
+        unless identity_url.include?('blank') || (options[:required].nil? && options[:optional].nil?)
+          extension_response_fields = {}
+
+          options[:required].each do |field|
+            extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
+          end unless options[:required].nil?
+
+          options[:optional].each do |field|
+            extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
+          end unless options[:optional].nil?
+        end
+
+        yield Result[:successful], identity_url , extension_response_fields
+      else
+        logger.info "OpenID authentication failed: #{identity_url}"
+        yield Result[:failed], identity_url, nil
+      end
+    end
+
+  private
+
+    def add_simple_registration_fields(open_id_response, fields)
+      open_id_response.add_extension_arg('sreg', 'required', [ fields[:required] ].flatten * ',') if fields[:required]
+      open_id_response.add_extension_arg('sreg', 'optional', [ fields[:optional] ].flatten * ',') if fields[:optional]
+    end
+end