loyal_devise 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +15 -0
  3. data/CHANGELOG.rdoc +881 -0
  4. data/CONTRIBUTING.md +12 -0
  5. data/Gemfile +31 -0
  6. data/Gemfile.lock +154 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +388 -0
  9. data/Rakefile +34 -0
  10. data/app/controllers/devise/confirmations_controller.rb +44 -0
  11. data/app/controllers/devise/omniauth_callbacks_controller.rb +31 -0
  12. data/app/controllers/devise/passwords_controller.rb +57 -0
  13. data/app/controllers/devise/registrations_controller.rb +120 -0
  14. data/app/controllers/devise/sessions_controller.rb +51 -0
  15. data/app/controllers/devise/unlocks_controller.rb +45 -0
  16. data/app/controllers/devise_controller.rb +193 -0
  17. data/app/helpers/devise_helper.rb +26 -0
  18. data/app/mailers/devise/mailer.rb +16 -0
  19. data/app/views/devise/_links.erb +3 -0
  20. data/app/views/devise/confirmations/new.html.erb +12 -0
  21. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  22. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  23. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  24. data/app/views/devise/passwords/edit.html.erb +16 -0
  25. data/app/views/devise/passwords/new.html.erb +12 -0
  26. data/app/views/devise/registrations/edit.html.erb +25 -0
  27. data/app/views/devise/registrations/new.html.erb +18 -0
  28. data/app/views/devise/sessions/new.html.erb +17 -0
  29. data/app/views/devise/shared/_links.erb +25 -0
  30. data/app/views/devise/unlocks/new.html.erb +12 -0
  31. data/config/locales/en.yml +59 -0
  32. data/devise.gemspec +26 -0
  33. data/gemfiles/Gemfile.rails-3.1.x +35 -0
  34. data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
  35. data/lib/devise/controllers/helpers.rb +273 -0
  36. data/lib/devise/controllers/rememberable.rb +53 -0
  37. data/lib/devise/controllers/scoped_views.rb +18 -0
  38. data/lib/devise/controllers/url_helpers.rb +68 -0
  39. data/lib/devise/delegator.rb +17 -0
  40. data/lib/devise/failure_app.rb +188 -0
  41. data/lib/devise/hooks/activatable.rb +12 -0
  42. data/lib/devise/hooks/forgetable.rb +10 -0
  43. data/lib/devise/hooks/lockable.rb +8 -0
  44. data/lib/devise/hooks/rememberable.rb +7 -0
  45. data/lib/devise/hooks/timeoutable.rb +26 -0
  46. data/lib/devise/hooks/trackable.rb +10 -0
  47. data/lib/devise/mailers/helpers.rb +92 -0
  48. data/lib/devise/mapping.rb +173 -0
  49. data/lib/devise/models/authenticatable.rb +269 -0
  50. data/lib/devise/models/confirmable.rb +271 -0
  51. data/lib/devise/models/database_authenticatable.rb +127 -0
  52. data/lib/devise/models/lockable.rb +194 -0
  53. data/lib/devise/models/omniauthable.rb +28 -0
  54. data/lib/devise/models/recoverable.rb +141 -0
  55. data/lib/devise/models/registerable.rb +26 -0
  56. data/lib/devise/models/rememberable.rb +126 -0
  57. data/lib/devise/models/timeoutable.rb +50 -0
  58. data/lib/devise/models/token_authenticatable.rb +90 -0
  59. data/lib/devise/models/trackable.rb +36 -0
  60. data/lib/devise/models/validatable.rb +67 -0
  61. data/lib/devise/models.rb +129 -0
  62. data/lib/devise/modules.rb +30 -0
  63. data/lib/devise/omniauth/config.rb +46 -0
  64. data/lib/devise/omniauth/url_helpers.rb +19 -0
  65. data/lib/devise/omniauth.rb +29 -0
  66. data/lib/devise/orm/active_record.rb +4 -0
  67. data/lib/devise/orm/mongoid.rb +4 -0
  68. data/lib/devise/param_filter.rb +42 -0
  69. data/lib/devise/rails/routes.rb +447 -0
  70. data/lib/devise/rails/warden_compat.rb +44 -0
  71. data/lib/devise/rails.rb +55 -0
  72. data/lib/devise/strategies/authenticatable.rb +177 -0
  73. data/lib/devise/strategies/base.rb +21 -0
  74. data/lib/devise/strategies/database_authenticatable.rb +21 -0
  75. data/lib/devise/strategies/rememberable.rb +56 -0
  76. data/lib/devise/strategies/token_authenticatable.rb +57 -0
  77. data/lib/devise/test_helpers.rb +132 -0
  78. data/lib/devise/time_inflector.rb +15 -0
  79. data/lib/devise/version.rb +4 -0
  80. data/lib/devise.rb +445 -0
  81. data/lib/generators/active_record/devise_generator.rb +80 -0
  82. data/lib/generators/active_record/templates/migration.rb +20 -0
  83. data/lib/generators/active_record/templates/migration_existing.rb +27 -0
  84. data/lib/generators/devise/devise_generator.rb +25 -0
  85. data/lib/generators/devise/install_generator.rb +25 -0
  86. data/lib/generators/devise/orm_helpers.rb +33 -0
  87. data/lib/generators/devise/views_generator.rb +117 -0
  88. data/lib/generators/mongoid/devise_generator.rb +58 -0
  89. data/lib/generators/templates/README +35 -0
  90. data/lib/generators/templates/devise.rb +241 -0
  91. data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  92. data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  93. data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  94. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
  95. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
  96. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
  97. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
  98. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
  99. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
  100. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
  101. data/test/controllers/custom_strategy_test.rb +63 -0
  102. data/test/controllers/helpers_test.rb +254 -0
  103. data/test/controllers/internal_helpers_test.rb +111 -0
  104. data/test/controllers/sessions_controller_test.rb +58 -0
  105. data/test/controllers/url_helpers_test.rb +60 -0
  106. data/test/delegator_test.rb +20 -0
  107. data/test/devise_test.rb +73 -0
  108. data/test/failure_app_test.rb +222 -0
  109. data/test/generators/active_record_generator_test.rb +76 -0
  110. data/test/generators/devise_generator_test.rb +40 -0
  111. data/test/generators/install_generator_test.rb +14 -0
  112. data/test/generators/mongoid_generator_test.rb +24 -0
  113. data/test/generators/views_generator_test.rb +53 -0
  114. data/test/helpers/devise_helper_test.rb +52 -0
  115. data/test/indifferent_hash.rb +34 -0
  116. data/test/integration/authenticatable_test.rb +634 -0
  117. data/test/integration/confirmable_test.rb +299 -0
  118. data/test/integration/database_authenticatable_test.rb +83 -0
  119. data/test/integration/http_authenticatable_test.rb +98 -0
  120. data/test/integration/lockable_test.rb +243 -0
  121. data/test/integration/omniauthable_test.rb +134 -0
  122. data/test/integration/recoverable_test.rb +307 -0
  123. data/test/integration/registerable_test.rb +346 -0
  124. data/test/integration/rememberable_test.rb +159 -0
  125. data/test/integration/timeoutable_test.rb +141 -0
  126. data/test/integration/token_authenticatable_test.rb +162 -0
  127. data/test/integration/trackable_test.rb +93 -0
  128. data/test/mailers/confirmation_instructions_test.rb +103 -0
  129. data/test/mailers/reset_password_instructions_test.rb +84 -0
  130. data/test/mailers/unlock_instructions_test.rb +78 -0
  131. data/test/mapping_test.rb +128 -0
  132. data/test/models/authenticatable_test.rb +8 -0
  133. data/test/models/confirmable_test.rb +392 -0
  134. data/test/models/database_authenticatable_test.rb +190 -0
  135. data/test/models/lockable_test.rb +274 -0
  136. data/test/models/omniauthable_test.rb +8 -0
  137. data/test/models/recoverable_test.rb +206 -0
  138. data/test/models/registerable_test.rb +8 -0
  139. data/test/models/rememberable_test.rb +175 -0
  140. data/test/models/serializable_test.rb +49 -0
  141. data/test/models/timeoutable_test.rb +47 -0
  142. data/test/models/token_authenticatable_test.rb +56 -0
  143. data/test/models/trackable_test.rb +14 -0
  144. data/test/models/validatable_test.rb +117 -0
  145. data/test/models_test.rb +180 -0
  146. data/test/omniauth/config_test.rb +58 -0
  147. data/test/omniauth/url_helpers_test.rb +52 -0
  148. data/test/orm/active_record.rb +10 -0
  149. data/test/orm/mongoid.rb +15 -0
  150. data/test/rails_app/Rakefile +10 -0
  151. data/test/rails_app/app/active_record/admin.rb +7 -0
  152. data/test/rails_app/app/active_record/shim.rb +3 -0
  153. data/test/rails_app/app/active_record/user.rb +7 -0
  154. data/test/rails_app/app/controllers/admins/sessions_controller.rb +7 -0
  155. data/test/rails_app/app/controllers/admins_controller.rb +12 -0
  156. data/test/rails_app/app/controllers/application_controller.rb +9 -0
  157. data/test/rails_app/app/controllers/home_controller.rb +26 -0
  158. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +3 -0
  159. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +3 -0
  160. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +15 -0
  161. data/test/rails_app/app/controllers/users_controller.rb +24 -0
  162. data/test/rails_app/app/helpers/application_helper.rb +4 -0
  163. data/test/rails_app/app/mailers/users/mailer.rb +9 -0
  164. data/test/rails_app/app/mongoid/admin.rb +28 -0
  165. data/test/rails_app/app/mongoid/shim.rb +25 -0
  166. data/test/rails_app/app/mongoid/user.rb +43 -0
  167. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  168. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  169. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
  170. data/test/rails_app/app/views/home/index.html.erb +1 -0
  171. data/test/rails_app/app/views/home/join.html.erb +1 -0
  172. data/test/rails_app/app/views/home/private.html.erb +1 -0
  173. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
  174. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  175. data/test/rails_app/app/views/users/index.html.erb +1 -0
  176. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  177. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  178. data/test/rails_app/config/application.rb +42 -0
  179. data/test/rails_app/config/boot.rb +9 -0
  180. data/test/rails_app/config/database.yml +18 -0
  181. data/test/rails_app/config/environment.rb +6 -0
  182. data/test/rails_app/config/environments/development.rb +19 -0
  183. data/test/rails_app/config/environments/production.rb +34 -0
  184. data/test/rails_app/config/environments/test.rb +34 -0
  185. data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
  186. data/test/rails_app/config/initializers/devise.rb +179 -0
  187. data/test/rails_app/config/initializers/inflections.rb +3 -0
  188. data/test/rails_app/config/initializers/secret_token.rb +3 -0
  189. data/test/rails_app/config/routes.rb +101 -0
  190. data/test/rails_app/config.ru +4 -0
  191. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +75 -0
  192. data/test/rails_app/db/schema.rb +53 -0
  193. data/test/rails_app/lib/shared_admin.rb +15 -0
  194. data/test/rails_app/lib/shared_user.rb +27 -0
  195. data/test/rails_app/public/404.html +26 -0
  196. data/test/rails_app/public/422.html +26 -0
  197. data/test/rails_app/public/500.html +26 -0
  198. data/test/rails_app/public/favicon.ico +0 -0
  199. data/test/rails_app/script/rails +10 -0
  200. data/test/routes_test.rb +249 -0
  201. data/test/support/assertions.rb +41 -0
  202. data/test/support/helpers.rb +92 -0
  203. data/test/support/integration.rb +93 -0
  204. data/test/support/locale/en.yml +4 -0
  205. data/test/support/webrat/integrations/rails.rb +25 -0
  206. data/test/test_helper.rb +28 -0
  207. data/test/test_helpers_test.rb +152 -0
  208. metadata +407 -0
@@ -0,0 +1,67 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Devise
3
+ module Models
4
+ # Validatable creates all needed validations for a user email and password.
5
+ # It's optional, given you may want to create the validations by yourself.
6
+ # Automatically validate if the email is present, unique and its format is
7
+ # valid. Also tests presence of password, confirmation and length.
8
+ #
9
+ # == Options
10
+ #
11
+ # Validatable adds the following options to devise_for:
12
+ #
13
+ # * +email_regexp+: the regular expression used to validate e-mails;
14
+ # * +password_length+: a range expressing password length. Defaults to 8..128.
15
+ #
16
+ module Validatable
17
+ # All validations used by this module.
18
+ VALIDATIONS = [ :validates_presence_of, :validates_uniqueness_of, :validates_format_of,
19
+ :validates_confirmation_of, :validates_length_of ].freeze
20
+
21
+ def self.required_fields(klass)
22
+ []
23
+ end
24
+
25
+ def self.included(base)
26
+ base.extend ClassMethods
27
+ assert_validations_api!(base)
28
+
29
+ base.class_eval do
30
+ validates_presence_of :email, :if => :email_required?
31
+ validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed?
32
+ validates_format_of :email, :with => email_regexp, :allow_blank => true, :if => :email_changed?
33
+
34
+ validates_presence_of :password, :if => :password_required?
35
+ validates_confirmation_of :password, :if => :password_required?
36
+ validates_length_of :password, :within => password_length, :allow_blank => true
37
+ end
38
+ end
39
+
40
+ def self.assert_validations_api!(base) #:nodoc:
41
+ unavailable_validations = VALIDATIONS.select { |v| !base.respond_to?(v) }
42
+
43
+ unless unavailable_validations.empty?
44
+ raise "Could not use :validatable module since #{base} does not respond " <<
45
+ "to the following methods: #{unavailable_validations.to_sentence}."
46
+ end
47
+ end
48
+
49
+ protected
50
+
51
+ # Checks whether a password is needed or not. For validations only.
52
+ # Passwords are always required if it's a new record, or if the password
53
+ # or confirmation are being set somewhere.
54
+ def password_required?
55
+ !persisted? || !password.nil? || !password_confirmation.nil?
56
+ end
57
+
58
+ def email_required?
59
+ true
60
+ end
61
+
62
+ module ClassMethods
63
+ Devise::Models.config(self, :email_regexp, :password_length)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,129 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Devise
3
+ module Models
4
+ class MissingAttribute < StandardError
5
+ def initialize(attributes)
6
+ @attributes = attributes
7
+ end
8
+
9
+ def message
10
+ "The following attribute(s) is (are) missing on your model: #{@attributes.join(", ")}"
11
+ end
12
+ end
13
+
14
+ # Creates configuration values for Devise and for the given module.
15
+ #
16
+ # Devise::Models.config(Devise::Authenticatable, :stretches, 10)
17
+ #
18
+ # The line above creates:
19
+ #
20
+ # 1) An accessor called Devise.stretches, which value is used by default;
21
+ #
22
+ # 2) Some class methods for your model Model.stretches and Model.stretches=
23
+ # which have higher priority than Devise.stretches;
24
+ #
25
+ # 3) And an instance method stretches.
26
+ #
27
+ # To add the class methods you need to have a module ClassMethods defined
28
+ # inside the given class.
29
+ #
30
+ def self.config(mod, *accessors) #:nodoc:
31
+ class << mod; attr_accessor :available_configs; end
32
+ mod.available_configs = accessors
33
+
34
+ accessors.each do |accessor|
35
+ mod.class_eval <<-METHOD, __FILE__, __LINE__ + 1
36
+ def #{accessor}
37
+ if defined?(@#{accessor})
38
+ @#{accessor}
39
+ elsif superclass.respond_to?(:#{accessor})
40
+ superclass.#{accessor}
41
+ else
42
+ Devise.#{accessor}
43
+ end
44
+ end
45
+
46
+ def #{accessor}=(value)
47
+ @#{accessor} = value
48
+ end
49
+ METHOD
50
+ end
51
+ end
52
+
53
+ def self.check_fields!(klass)
54
+ failed_attributes = []
55
+ instance = klass.new
56
+
57
+ klass.devise_modules.each do |mod|
58
+ constant = const_get(mod.to_s.classify)
59
+
60
+ if constant.respond_to?(:required_fields)
61
+ constant.required_fields(klass).each do |field|
62
+ failed_attributes << field unless instance.respond_to?(field)
63
+ end
64
+ else
65
+ ActiveSupport::Deprecation.warn "The module #{mod} doesn't implement self.required_fields(klass). " \
66
+ "Devise uses required_fields to warn developers of any missing fields in their models. " \
67
+ "Please implement #{mod}.required_fields(klass) that returns an array of symbols with the required fields."
68
+ end
69
+ end
70
+
71
+ if failed_attributes.any?
72
+ fail Devise::Models::MissingAttribute.new(failed_attributes)
73
+ end
74
+ end
75
+
76
+ # Include the chosen devise modules in your model:
77
+ #
78
+ # devise :database_authenticatable, :confirmable, :recoverable
79
+ #
80
+ # You can also give any of the devise configuration values in form of a hash,
81
+ # with specific values for this model. Please check your Devise initializer
82
+ # for a complete description on those values.
83
+ #
84
+ def devise(*modules)
85
+ options = modules.extract_options!.dup
86
+
87
+ selected_modules = modules.map(&:to_sym).uniq.sort_by do |s|
88
+ Devise::ALL.index(s) || -1 # follow Devise::ALL order
89
+ end
90
+
91
+ devise_modules_hook! do
92
+ include Devise::Models::Authenticatable
93
+ selected_modules.each do |m|
94
+ if m == :encryptable && !(defined?(Devise::Models::Encryptable))
95
+ warn "[DEVISE] You're trying to include :encryptable in your model but it is not bundled with the Devise gem anymore. Please add `devise-encryptable` to your Gemfile to proceed.\n"
96
+ end
97
+
98
+ mod = Devise::Models.const_get(m.to_s.classify)
99
+
100
+ if mod.const_defined?("ClassMethods")
101
+ class_mod = mod.const_get("ClassMethods")
102
+ extend class_mod
103
+
104
+ if class_mod.respond_to?(:available_configs)
105
+ available_configs = class_mod.available_configs
106
+ available_configs.each do |config|
107
+ next unless options.key?(config)
108
+ send(:"#{config}=", options.delete(config))
109
+ end
110
+ end
111
+ end
112
+
113
+ include mod
114
+ end
115
+
116
+ self.devise_modules |= selected_modules
117
+ options.each { |key, value| send(:"#{key}=", value) }
118
+ end
119
+ end
120
+
121
+ # The hook which is called inside devise.
122
+ # So your ORM can include devise compatibility stuff.
123
+ def devise_modules_hook!
124
+ yield
125
+ end
126
+ end
127
+ end
128
+
129
+ require 'devise/models/authenticatable'
@@ -0,0 +1,30 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'active_support/core_ext/object/with_options'
3
+
4
+ Devise.with_options :model => true do |d|
5
+ # Strategies first
6
+ d.with_options :strategy => true do |s|
7
+ routes = [nil, :new, :destroy]
8
+ s.add_module :database_authenticatable, :controller => :sessions, :route => { :session => routes }
9
+ s.add_module :token_authenticatable, :controller => :sessions, :route => { :session => routes }, :no_input => true
10
+ s.add_module :rememberable, :no_input => true
11
+ end
12
+
13
+ # Other authentications
14
+ d.add_module :omniauthable, :controller => :omniauth_callbacks, :route => :omniauth_callback
15
+
16
+ # Misc after
17
+ routes = [nil, :new, :edit]
18
+ d.add_module :recoverable, :controller => :passwords, :route => { :password => routes }
19
+ d.add_module :registerable, :controller => :registrations, :route => { :registration => (routes << :cancel) }
20
+ d.add_module :validatable
21
+
22
+ # The ones which can sign out after
23
+ routes = [nil, :new]
24
+ d.add_module :confirmable, :controller => :confirmations, :route => { :confirmation => routes }
25
+ d.add_module :lockable, :controller => :unlocks, :route => { :unlock => routes }
26
+ d.add_module :timeoutable
27
+
28
+ # Stats for last, so we make sure the user is really signed in
29
+ d.add_module :trackable
30
+ end
@@ -0,0 +1,46 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Devise
3
+ module OmniAuth
4
+ class StrategyNotFound < NameError
5
+ def initialize(strategy)
6
+ @strategy = strategy
7
+ super("Could not find a strategy with name `#{strategy}'. " \
8
+ "Please ensure it is required or explicitly set it using the :strategy_class option.")
9
+ end
10
+ end
11
+
12
+ class Config
13
+ attr_accessor :strategy
14
+ attr_reader :args, :options, :provider, :strategy_name
15
+
16
+ def initialize(provider, args)
17
+ @provider = provider
18
+ @args = args
19
+ @options = @args.last.is_a?(Hash) ? @args.last : {}
20
+ @strategy = nil
21
+ @strategy_name = options[:name] || @provider
22
+ @strategy_class = options.delete(:strategy_class)
23
+ end
24
+
25
+ def strategy_class
26
+ @strategy_class ||= find_strategy || autoload_strategy
27
+ end
28
+
29
+ def find_strategy
30
+ ::OmniAuth.strategies.find do |strategy_class|
31
+ strategy_class.to_s =~ /#{::OmniAuth::Utils.camelize(strategy_name)}$/ ||
32
+ strategy_class.default_options[:name] == strategy_name
33
+ end
34
+ end
35
+
36
+ def autoload_strategy
37
+ name = ::OmniAuth::Utils.camelize(provider.to_s)
38
+ if ::OmniAuth::Strategies.const_defined?(name)
39
+ ::OmniAuth::Strategies.const_get(name)
40
+ else
41
+ raise StrategyNotFound, name
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Devise
3
+ module OmniAuth
4
+ module UrlHelpers
5
+ def self.define_helpers(mapping)
6
+ end
7
+
8
+ def omniauth_authorize_path(resource_or_scope, *args)
9
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
10
+ send("#{scope}_omniauth_authorize_path", *args)
11
+ end
12
+
13
+ def omniauth_callback_path(resource_or_scope, *args)
14
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
15
+ send("#{scope}_omniauth_callback_path", *args)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding : utf-8 -*-
2
+ begin
3
+ require "omniauth"
4
+ require "omniauth/version"
5
+ rescue LoadError
6
+ warn "Could not load 'omniauth'. Please ensure you have the omniauth gem >= 1.0.0 installed and listed in your Gemfile."
7
+ raise
8
+ end
9
+
10
+ unless OmniAuth::VERSION =~ /^1\./
11
+ raise "You are using an old OmniAuth version, please ensure you have 1.0.0.pr2 version or later installed."
12
+ end
13
+
14
+ # Clean up the default path_prefix. It will be automatically set by Devise.
15
+ OmniAuth.config.path_prefix = nil
16
+
17
+ OmniAuth.config.on_failure = Proc.new do |env|
18
+ env['devise.mapping'] = Devise::Mapping.find_by_path!(env['PATH_INFO'], :path)
19
+ controller_name = ActiveSupport::Inflector.camelize(env['devise.mapping'].controllers[:omniauth_callbacks])
20
+ controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
21
+ controller_klass.action(:failure).call(env)
22
+ end
23
+
24
+ module Devise
25
+ module OmniAuth
26
+ autoload :Config, "devise/omniauth/config"
27
+ autoload :UrlHelpers, "devise/omniauth/url_helpers"
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'orm_adapter/adapters/active_record'
3
+
4
+ ActiveRecord::Base.extend Devise::Models
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'orm_adapter/adapters/mongoid'
3
+
4
+ Mongoid::Document::ClassMethods.send :include, Devise::Models
@@ -0,0 +1,42 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Devise
3
+ class ParamFilter
4
+ def initialize(case_insensitive_keys, strip_whitespace_keys)
5
+ @case_insensitive_keys = case_insensitive_keys || []
6
+ @strip_whitespace_keys = strip_whitespace_keys || []
7
+ end
8
+
9
+ def filter(conditions)
10
+ conditions = stringify_params(conditions.dup)
11
+
12
+ @case_insensitive_keys.each do |k|
13
+ value = conditions[k]
14
+ next unless value.respond_to?(:downcase)
15
+ conditions[k] = value.downcase
16
+ end
17
+
18
+ @strip_whitespace_keys.each do |k|
19
+ value = conditions[k]
20
+ next unless value.respond_to?(:strip)
21
+ conditions[k] = value.strip
22
+ end
23
+
24
+ conditions
25
+ end
26
+
27
+ # Force keys to be string to avoid injection on mongoid related database.
28
+ def stringify_params(conditions)
29
+ return conditions unless conditions.is_a?(Hash)
30
+ conditions.each do |k, v|
31
+ conditions[k] = v.to_s if param_requires_string_conversion?(v)
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ # Determine which values should be transformed to string or passed as-is to the query builder underneath
38
+ def param_requires_string_conversion?(value)
39
+ [Fixnum, TrueClass, FalseClass, Regexp].none? {|clz| value.is_a? clz }
40
+ end
41
+ end
42
+ end