openid_registrable 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +52 -0
- data/Rakefile +31 -0
- data/lib/openid_registrable.rb +3 -0
- data/lib/openid_registrable/openid_registrable.rb +94 -0
- data/lib/openid_registrable/version.rb +3 -0
- data/openid_registrable.gemspec +23 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/user.rb +14 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +22 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +26 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/db/migrate/20110331093359_create_users.rb +18 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/javascripts/application.js +2 -0
- data/test/dummy/public/javascripts/controls.js +965 -0
- data/test/dummy/public/javascripts/dragdrop.js +974 -0
- data/test/dummy/public/javascripts/effects.js +1123 -0
- data/test/dummy/public/javascripts/prototype.js +6001 -0
- data/test/dummy/public/javascripts/rails.js +191 -0
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/integration/navigation_test.rb +7 -0
- data/test/support/integration_case.rb +4 -0
- data/test/test_helper.rb +20 -0
- data/test/unit/openid_registrable_test.rb +84 -0
- metadata +167 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
= OpenidRegistrable
|
2
|
+
|
3
|
+
OpenidRegistrable is gem for Rails. It makes possible define required and optional fields for registration via OpenID and to map them to fields of your model.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
class User < ActiveRecord::Base
|
8
|
+
openid_registrable :required_fields => {
|
9
|
+
:email => 'http://axschema.org/contact/email',
|
10
|
+
},
|
11
|
+
:optional_fields => {
|
12
|
+
:first_name => 'http://axschema.org/namePerson/first',
|
13
|
+
:last_name => 'http://axschema.org/namePerson/last',
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
User.openid_required_fields => ['http://axschema.org/contact/email']
|
18
|
+
User.openid_optional_fields => ['http://axschema.org/namePerson/first', 'http://axschema.org/namePerson/last']
|
19
|
+
|
20
|
+
User.openid_fields_to_model_fields_mapping =>
|
21
|
+
|
22
|
+
{:email => 'http://axschema.org/contact/email'
|
23
|
+
:first_name => 'http://axschema.org/namePerson/first',
|
24
|
+
:last_name => 'http://axschema.org/namePerson/last'
|
25
|
+
}
|
26
|
+
|
27
|
+
# assign fields
|
28
|
+
@user = User.new
|
29
|
+
@user.assign_openid_fields(openid_ax_data)
|
30
|
+
@user.save
|
31
|
+
|
32
|
+
=== Usage with open_id_authentication
|
33
|
+
https://github.com/Velir/open_id_authentication
|
34
|
+
|
35
|
+
authenticate_with_open_id(@openid_identifier, :required => User.openid_required_fields, :optional => User.openid_optional_fields) do |result, identity_url, sreg_data, ax_data|
|
36
|
+
if result.successful?
|
37
|
+
if self.current_user = User.find_by_identity_url(identity_url)
|
38
|
+
current_user.assign_openid_fields(ax_data, [:username])
|
39
|
+
|
40
|
+
current_user.changes.empty? ? successful_login : successful_login(edit_user_path(:user => current_user.attributes))
|
41
|
+
else
|
42
|
+
self.current_user = User.new(:identity_url => identity_url)
|
43
|
+
current_user.assign_openid_fields(ax_data)
|
44
|
+
|
45
|
+
successful_login(registration_via_openid_path(:user => current_user.attributes))
|
46
|
+
end
|
47
|
+
else
|
48
|
+
failed_login result.message
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Copyright (c) 2011 Vít Krchov, KRAXNET s.r.o., released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
Bundler::GemHelper.install_tasks
|
10
|
+
|
11
|
+
require 'rake'
|
12
|
+
require 'rake/rdoctask'
|
13
|
+
|
14
|
+
require 'rake/testtask'
|
15
|
+
|
16
|
+
Rake::TestTask.new(:test) do |t|
|
17
|
+
t.libs << 'lib'
|
18
|
+
t.libs << 'test'
|
19
|
+
t.pattern = 'test/**/*_test.rb'
|
20
|
+
t.verbose = false
|
21
|
+
end
|
22
|
+
|
23
|
+
task :default => :test
|
24
|
+
|
25
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
26
|
+
rdoc.rdoc_dir = 'rdoc'
|
27
|
+
rdoc.title = 'OpenidRegistrable'
|
28
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
29
|
+
rdoc.rdoc_files.include('README.rdoc')
|
30
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
31
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# Makes possible define required and optional fields for registration via OpenID
|
2
|
+
# and to map them to fields of your model.
|
3
|
+
|
4
|
+
module OpenidRegistrable
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
|
11
|
+
# Using:
|
12
|
+
#
|
13
|
+
# class User < ActiveRecord::Base
|
14
|
+
# openid_registrable :required_fields => {
|
15
|
+
# :email => 'http://axschema.org/contact/email',
|
16
|
+
# },
|
17
|
+
# :optional_fields => {
|
18
|
+
# :first_name => 'http://axschema.org/namePerson/first',
|
19
|
+
# :last_name => 'http://axschema.org/namePerson/last',
|
20
|
+
# }
|
21
|
+
# end
|
22
|
+
|
23
|
+
def openid_registrable(options)
|
24
|
+
[:required_fields, :optional_fields].each do |fields|
|
25
|
+
unless options[fields].empty?
|
26
|
+
(class << self; self; end).instance_eval do
|
27
|
+
# define methods openid_require_fields and openid_optional_fields
|
28
|
+
# methods returns array generated from options given in #openid_registrable, e.g.:
|
29
|
+
# => ['http://axschema.org/namePerson/first', 'http://axschema.org/namePerson/last']
|
30
|
+
define_method "openid_#{fields}" do
|
31
|
+
options[fields].values
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# define method :openid_fields_to_model_fields_mapping
|
38
|
+
# method returns hash genered from options given in #openid_registrable, e.g.:
|
39
|
+
# => {:first_name=>"http://axschema.org/namePerson/first",
|
40
|
+
# :last_name=>"http://axschema.org/namePerson/last"}
|
41
|
+
|
42
|
+
if options[:required_fields] or options[:optional_fields]
|
43
|
+
(class << self; self; end).instance_eval do
|
44
|
+
define_method :openid_fields_to_model_fields_mapping do
|
45
|
+
mapping = {}
|
46
|
+
mapping.merge!(options[:required_fields]) if options[:required_fields]
|
47
|
+
mapping.merge!(options[:optional_fields]) if options[:optional_fields]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
send :include, InstanceMethods
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module InstanceMethods
|
57
|
+
|
58
|
+
# Using with open_id_authentication (https://github.com/Velir/open_id_authentication)
|
59
|
+
#
|
60
|
+
# authenticate_with_open_id(@openid_identifier, :required => User.openid_required_fields, :optional => User.openid_optional_fields) do |result, identity_url, sreg_data, ax_data|
|
61
|
+
# if result.successful?
|
62
|
+
# if self.current_user = User.find_by_identity_url(identity_url)
|
63
|
+
# current_user.assign_openid_fields(ax_data, [:username])
|
64
|
+
#
|
65
|
+
# current_user.changes.empty? ? successful_login : successful_login(edit_user_path(:user => current_user.attributes))
|
66
|
+
# else
|
67
|
+
# self.current_user = User.new(:identity_url => identity_url)
|
68
|
+
# current_user.assign_openid_fields(ax_data)
|
69
|
+
#
|
70
|
+
# successful_login(registration_via_openid_path(:user => current_user.attributes))
|
71
|
+
# end
|
72
|
+
# else
|
73
|
+
# failed_login result.message
|
74
|
+
# end
|
75
|
+
# end
|
76
|
+
|
77
|
+
def assign_openid_fields(openid_fields, ignored_fields=[])
|
78
|
+
if self.class.respond_to?(:openid_fields_to_model_fields_mapping)
|
79
|
+
self.class.openid_fields_to_model_fields_mapping.each do |model_field, openid_field|
|
80
|
+
|
81
|
+
if openid_fields[openid_field].kind_of?(Array)
|
82
|
+
value = openid_fields[openid_field].first
|
83
|
+
else
|
84
|
+
value = openid_fields[openid_field]
|
85
|
+
end
|
86
|
+
|
87
|
+
if value.present? and not ignored_fields.include?(model_field)
|
88
|
+
self.send("#{model_field}=", value)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../lib/openid_registrable/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "openid_registrable"
|
5
|
+
s.summary = "Adds to ActiveRecord model method for defining required and optional fields for registration via OpenID."
|
6
|
+
s.description = "OpenidRegistrable is gem for Rails. It makes possible define required and optional fields for registration via OpenID and to map them to fields of your model."
|
7
|
+
s.authors = ['Vít Krchov']
|
8
|
+
s.email = 'vit.krchov@gmail.com'
|
9
|
+
s.homepage = 'https://github.com/vita/openid_registrable'
|
10
|
+
|
11
|
+
s.version = OpenidRegistrable::VERSION
|
12
|
+
s.platform = Gem::Platform::RUBY
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
16
|
+
s.require_path = 'lib'
|
17
|
+
|
18
|
+
s.add_dependency 'rails'
|
19
|
+
|
20
|
+
s.add_development_dependency 'turn'
|
21
|
+
s.add_development_dependency 'shoulda'
|
22
|
+
s.add_development_dependency 'sqlite3'
|
23
|
+
end
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
openid_registrable :required_fields => {
|
3
|
+
:email => 'http://axschema.org/contact/email',
|
4
|
+
:username => 'http://axschema.org/namePerson/friendly',
|
5
|
+
},
|
6
|
+
:optional_fields => {
|
7
|
+
:first_name => 'http://axschema.org/namePerson/first',
|
8
|
+
:last_name => 'http://axschema.org/namePerson/last',
|
9
|
+
:address => 'http://axschema.org/contact/postalAddress/home',
|
10
|
+
:city => 'http://axschema.org/contact/city/home',
|
11
|
+
:zip => 'http://axschema.org/contact/postalCode/home',
|
12
|
+
:phone => 'http://axschema.org/contact/phone/default'
|
13
|
+
}
|
14
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "active_model/railtie"
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_view/railtie"
|
7
|
+
require "action_mailer/railtie"
|
8
|
+
|
9
|
+
Bundler.require
|
10
|
+
require "openid_registrable"
|
11
|
+
|
12
|
+
module Dummy
|
13
|
+
class Application < Rails::Application
|
14
|
+
# Settings in config/environments/* take precedence over those specified here.
|
15
|
+
# Application configuration should go into files in config/initializers
|
16
|
+
# -- all .rb files in that directory are automatically loaded.
|
17
|
+
|
18
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
19
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
20
|
+
|
21
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
22
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
23
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
24
|
+
|
25
|
+
# Activate observers that should always be running.
|
26
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
27
|
+
|
28
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
29
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
30
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
31
|
+
|
32
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
33
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
34
|
+
# config.i18n.default_locale = :de
|
35
|
+
|
36
|
+
# JavaScript files you want as :defaults (application.js is always included).
|
37
|
+
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
38
|
+
|
39
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
40
|
+
config.encoding = "utf-8"
|
41
|
+
|
42
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
43
|
+
config.filter_parameters += [:password]
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
development:
|
4
|
+
adapter: sqlite3
|
5
|
+
database: db/development.sqlite3
|
6
|
+
pool: 5
|
7
|
+
timeout: 5000
|
8
|
+
|
9
|
+
# Warning: The database defined as "test" will be erased and
|
10
|
+
# re-generated from your development database when you run "rake".
|
11
|
+
# Do not set this db to the same as development or production.
|
12
|
+
test:
|
13
|
+
adapter: sqlite3
|
14
|
+
database: db/test.sqlite3
|
15
|
+
pool: 5
|
16
|
+
timeout: 5000
|
17
|
+
|
18
|
+
production:
|
19
|
+
adapter: sqlite3
|
20
|
+
database: db/production.sqlite3
|
21
|
+
pool: 5
|
22
|
+
timeout: 5000
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_view.debug_rjs = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Don't care if the mailer can't send
|
18
|
+
config.action_mailer.raise_delivery_errors = false
|
19
|
+
|
20
|
+
# Print deprecation notices to the Rails logger
|
21
|
+
config.active_support.deprecation = :log
|
22
|
+
|
23
|
+
# Only use best-standards-support built into browsers
|
24
|
+
config.action_dispatch.best_standards_support = :builtin
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The production environment is meant for finished, "live" apps.
|
5
|
+
# Code is not reloaded between requests
|
6
|
+
config.cache_classes = true
|
7
|
+
|
8
|
+
# Full error reports are disabled and caching is turned on
|
9
|
+
config.consider_all_requests_local = false
|
10
|
+
config.action_controller.perform_caching = true
|
11
|
+
|
12
|
+
# Specifies the header that your server uses for sending files
|
13
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
+
|
15
|
+
# For nginx:
|
16
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
+
|
18
|
+
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
+
# just comment this out and Rails will serve the files
|
20
|
+
|
21
|
+
# See everything in the log (default is :info)
|
22
|
+
# config.log_level = :debug
|
23
|
+
|
24
|
+
# Use a different logger for distributed setups
|
25
|
+
# config.logger = SyslogLogger.new
|
26
|
+
|
27
|
+
# Use a different cache store in production
|
28
|
+
# config.cache_store = :mem_cache_store
|
29
|
+
|
30
|
+
# Disable Rails's static asset server
|
31
|
+
# In production, Apache or nginx will already do this
|
32
|
+
config.serve_static_assets = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
+
|
37
|
+
# Disable delivery errors, bad email addresses will be ignored
|
38
|
+
# config.action_mailer.raise_delivery_errors = false
|
39
|
+
|
40
|
+
# Enable threaded mode
|
41
|
+
# config.threadsafe!
|
42
|
+
|
43
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
+
# the I18n.default_locale when a translation can not be found)
|
45
|
+
config.i18n.fallbacks = true
|
46
|
+
|
47
|
+
# Send deprecation notices to registered listeners
|
48
|
+
config.active_support.deprecation = :notify
|
49
|
+
end
|