sorcery 0.8.2 → 0.8.6
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.
- checksums.yaml +7 -0
- data/.gitignore +55 -0
- data/.travis.yml +69 -1
- data/CHANGELOG.md +248 -0
- data/Gemfile +16 -22
- data/Gemfile.rails4 +22 -0
- data/README.md +320 -0
- data/Rakefile +3 -79
- data/VERSION +1 -1
- data/gemfiles/active_record-rails41.gemfile +6 -0
- data/gemfiles/mongo_mapper-rails41.gemfile +8 -0
- data/gemfiles/mongoid-rails41.gemfile +11 -0
- data/lib/generators/sorcery/helpers.rb +40 -0
- data/lib/generators/sorcery/install_generator.rb +21 -17
- data/lib/generators/sorcery/templates/initializer.rb +1 -1
- data/lib/generators/sorcery/templates/migration/activity_logging.rb +2 -11
- data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +1 -7
- data/lib/generators/sorcery/templates/migration/core.rb +5 -8
- data/lib/generators/sorcery/templates/migration/external.rb +1 -5
- data/lib/generators/sorcery/templates/migration/remember_me.rb +2 -9
- data/lib/generators/sorcery/templates/migration/reset_password.rb +2 -10
- data/lib/generators/sorcery/templates/migration/user_activation.rb +2 -10
- data/lib/sorcery/controller/submodules/external.rb +39 -20
- data/lib/sorcery/controller/submodules/remember_me.rb +1 -1
- data/lib/sorcery/controller/submodules/session_timeout.rb +2 -2
- data/lib/sorcery/controller.rb +18 -11
- data/lib/sorcery/model/adapters/active_record.rb +7 -2
- data/lib/sorcery/model/adapters/datamapper.rb +123 -0
- data/lib/sorcery/model/adapters/mongo_mapper.rb +8 -4
- data/lib/sorcery/model/adapters/mongoid.rb +8 -8
- data/lib/sorcery/model/submodules/activity_logging.rb +24 -0
- data/lib/sorcery/model/submodules/brute_force_protection.rb +22 -8
- data/lib/sorcery/model/submodules/remember_me.rb +19 -4
- data/lib/sorcery/model/submodules/reset_password.rb +35 -14
- data/lib/sorcery/model/submodules/user_activation.rb +69 -24
- data/lib/sorcery/model.rb +111 -73
- data/lib/sorcery/protocols/oauth.rb +42 -0
- data/lib/sorcery/protocols/oauth2.rb +47 -0
- data/lib/sorcery/providers/base.rb +27 -0
- data/lib/sorcery/providers/facebook.rb +63 -0
- data/lib/sorcery/providers/github.rb +51 -0
- data/lib/sorcery/providers/google.rb +51 -0
- data/lib/sorcery/providers/linkedin.rb +66 -0
- data/lib/sorcery/providers/liveid.rb +53 -0
- data/lib/sorcery/providers/twitter.rb +59 -0
- data/lib/sorcery/providers/vk.rb +61 -0
- data/lib/sorcery/providers/xing.rb +64 -0
- data/lib/sorcery/test_helpers/internal/rails.rb +17 -6
- data/lib/sorcery/test_helpers/internal.rb +23 -6
- data/lib/sorcery/test_helpers/rails/controller.rb +17 -0
- data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
- data/lib/sorcery/test_helpers/rails.rb +1 -10
- data/lib/sorcery.rb +20 -28
- data/sorcery.gemspec +21 -363
- data/spec/active_record/controller_activity_logging_spec.rb +29 -0
- data/spec/active_record/controller_brute_force_protection_spec.rb +158 -0
- data/spec/active_record/controller_http_basic_auth_spec.rb +65 -0
- data/spec/active_record/controller_oauth2_spec.rb +342 -0
- data/spec/{rails3/spec → active_record}/controller_oauth_spec.rb +69 -59
- data/spec/active_record/controller_remember_me_spec.rb +97 -0
- data/spec/active_record/controller_session_timeout_spec.rb +70 -0
- data/spec/active_record/controller_spec.rb +8 -0
- data/spec/{rails3/spec → active_record}/integration_spec.rb +3 -3
- data/spec/active_record/user_activation_spec.rb +18 -0
- data/spec/active_record/user_activity_logging_spec.rb +8 -0
- data/spec/{rails3/spec → active_record}/user_brute_force_protection_spec.rb +6 -5
- data/spec/{rails3/spec → active_record}/user_oauth_spec.rb +6 -5
- data/spec/{rails3/spec → active_record}/user_remember_me_spec.rb +5 -4
- data/spec/{rails3/spec → active_record}/user_reset_password_spec.rb +7 -7
- data/spec/active_record/user_spec.rb +37 -0
- data/spec/datamapper/controller_activity_logging_spec.rb +17 -0
- data/spec/datamapper/controller_spec.rb +8 -0
- data/spec/datamapper/user_activation_spec.rb +10 -0
- data/spec/datamapper/user_activity_logging_spec.rb +9 -0
- data/spec/datamapper/user_brute_force_protection_spec.rb +9 -0
- data/spec/datamapper/user_oauth_spec.rb +9 -0
- data/spec/datamapper/user_remember_me_spec.rb +8 -0
- data/spec/datamapper/user_reset_password_spec.rb +8 -0
- data/spec/datamapper/user_spec.rb +27 -0
- data/spec/mongo_mapper/controller_spec.rb +8 -0
- data/spec/mongo_mapper/user_activation_spec.rb +9 -0
- data/spec/mongo_mapper/user_activity_logging_spec.rb +8 -0
- data/spec/mongo_mapper/user_brute_force_protection_spec.rb +8 -0
- data/spec/mongo_mapper/user_oauth_spec.rb +8 -0
- data/spec/mongo_mapper/user_remember_me_spec.rb +8 -0
- data/spec/mongo_mapper/user_reset_password_spec.rb +8 -0
- data/spec/mongo_mapper/user_spec.rb +37 -0
- data/spec/mongoid/controller_activity_logging_spec.rb +16 -0
- data/spec/mongoid/controller_spec.rb +8 -0
- data/spec/mongoid/user_activation_spec.rb +9 -0
- data/spec/mongoid/user_activity_logging_spec.rb +8 -0
- data/spec/mongoid/user_brute_force_protection_spec.rb +8 -0
- data/spec/mongoid/user_oauth_spec.rb +8 -0
- data/spec/mongoid/user_remember_me_spec.rb +8 -0
- data/spec/mongoid/user_reset_password_spec.rb +8 -0
- data/spec/mongoid/user_spec.rb +38 -0
- data/spec/orm/active_record.rb +9 -0
- data/spec/orm/datamapper.rb +34 -0
- data/spec/orm/mongo_mapper.rb +11 -0
- data/spec/orm/mongoid.rb +18 -0
- data/spec/{rails3/app/models → rails_app/app/active_record}/user.rb +1 -2
- data/spec/rails_app/app/active_record/user_provider.rb +3 -0
- data/spec/rails_app/app/controllers/sorcery_controller.rb +224 -0
- data/spec/rails_app/app/datamapper/authentication.rb +8 -0
- data/spec/rails_app/app/datamapper/user.rb +7 -0
- data/spec/{rails3_mongoid/app/models → rails_app/app/mongoid}/user.rb +2 -0
- data/spec/{rails3_mongo_mapper → rails_app}/config/application.rb +13 -8
- data/spec/rails_app/config/boot.rb +4 -0
- data/spec/rails_app/config/database.yml +22 -0
- data/spec/{rails3_mongo_mapper → rails_app}/config/environments/test.rb +2 -0
- data/spec/{rails3_mongoid → rails_app}/config/initializers/session_store.rb +4 -0
- data/spec/rails_app/config/routes.rb +42 -0
- data/spec/{rails3_mongo_mapper → rails_app}/config.ru +1 -1
- data/spec/{rails3 → rails_app}/db/migrate/activation/20101224223622_add_activation_to_users.rb +3 -3
- data/spec/rails_app/db/migrate/external/20101224223628_create_authentications_and_user_providers.rb +22 -0
- data/spec/rails_app/log/development.log +1791 -0
- data/spec/shared_examples/controller_activity_logging_shared_examples.rb +125 -0
- data/spec/shared_examples/controller_oauth2_shared_examples.rb +32 -36
- data/spec/shared_examples/controller_oauth_shared_examples.rb +35 -28
- data/spec/shared_examples/controller_shared_examples.rb +203 -0
- data/spec/shared_examples/user_activation_shared_examples.rb +136 -97
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +10 -10
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +14 -13
- data/spec/shared_examples/user_oauth_shared_examples.rb +23 -15
- data/spec/shared_examples/user_remember_me_shared_examples.rb +32 -23
- data/spec/shared_examples/user_reset_password_shared_examples.rb +162 -129
- data/spec/shared_examples/user_shared_examples.rb +265 -190
- data/spec/sorcery_crypto_providers_spec.rb +74 -72
- data/spec/spec_helper.rb +47 -4
- metadata +277 -501
- data/Gemfile.lock +0 -175
- data/README.rdoc +0 -261
- data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -46
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -49
- data/lib/sorcery/controller/submodules/external/providers/base.rb +0 -21
- data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -98
- data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -92
- data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -91
- data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -102
- data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -92
- data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -93
- data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -100
- data/lib/sorcery/controller/submodules/external/providers/xing.rb +0 -97
- data/lib/sorcery/test_helpers.rb +0 -5
- data/spec/Gemfile +0 -12
- data/spec/Gemfile.lock +0 -129
- data/spec/README.md +0 -31
- data/spec/Rakefile +0 -12
- data/spec/rails3/.gitignore +0 -4
- data/spec/rails3/.rspec +0 -1
- data/spec/rails3/Gemfile +0 -15
- data/spec/rails3/Gemfile.lock +0 -162
- data/spec/rails3/README +0 -256
- data/spec/rails3/Rakefile +0 -11
- data/spec/rails3/app/controllers/application_controller.rb +0 -208
- data/spec/rails3/config/application.rb +0 -46
- data/spec/rails3/config/boot.rb +0 -13
- data/spec/rails3/config/database.yml +0 -27
- data/spec/rails3/config/environments/development.rb +0 -26
- data/spec/rails3/config/environments/in_memory.rb +0 -35
- data/spec/rails3/config/environments/production.rb +0 -49
- data/spec/rails3/config/environments/test.rb +0 -35
- data/spec/rails3/config/initializers/session_store.rb +0 -8
- data/spec/rails3/config/routes.rb +0 -59
- data/spec/rails3/config.ru +0 -4
- data/spec/rails3/db/migrate/external/20101224223628_create_authentications.rb +0 -14
- data/spec/rails3/public/stylesheets/.gitkeep +0 -0
- data/spec/rails3/script/rails +0 -6
- data/spec/rails3/spec/controller_activity_logging_spec.rb +0 -130
- data/spec/rails3/spec/controller_brute_force_protection_spec.rb +0 -96
- data/spec/rails3/spec/controller_http_basic_auth_spec.rb +0 -50
- data/spec/rails3/spec/controller_oauth2_spec.rb +0 -380
- data/spec/rails3/spec/controller_remember_me_spec.rb +0 -96
- data/spec/rails3/spec/controller_session_timeout_spec.rb +0 -55
- data/spec/rails3/spec/controller_spec.rb +0 -182
- data/spec/rails3/spec/spec.opts +0 -2
- data/spec/rails3/spec/spec_helper.orig.rb +0 -27
- data/spec/rails3/spec/spec_helper.rb +0 -71
- data/spec/rails3/spec/user_activation_spec.rb +0 -16
- data/spec/rails3/spec/user_activity_logging_spec.rb +0 -8
- data/spec/rails3/spec/user_spec.rb +0 -36
- data/spec/rails3/vendor/plugins/.gitkeep +0 -0
- data/spec/rails3_mongo_mapper/.gitignore +0 -4
- data/spec/rails3_mongo_mapper/.rspec +0 -1
- data/spec/rails3_mongo_mapper/Gemfile +0 -16
- data/spec/rails3_mongo_mapper/Gemfile.lock +0 -156
- data/spec/rails3_mongo_mapper/Rakefile +0 -11
- data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +0 -122
- data/spec/rails3_mongo_mapper/app/helpers/application_helper.rb +0 -2
- data/spec/rails3_mongo_mapper/app/mailers/sorcery_mailer.rb +0 -25
- data/spec/rails3_mongo_mapper/app/views/layouts/application.html.erb +0 -14
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.html.erb +0 -17
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.text.erb +0 -9
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.text.erb +0 -9
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.html.erb +0 -16
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.text.erb +0 -8
- data/spec/rails3_mongo_mapper/config/boot.rb +0 -13
- data/spec/rails3_mongo_mapper/config/environment.rb +0 -5
- data/spec/rails3_mongo_mapper/config/environments/development.rb +0 -30
- data/spec/rails3_mongo_mapper/config/environments/in_memory.rb +0 -0
- data/spec/rails3_mongo_mapper/config/environments/production.rb +0 -49
- data/spec/rails3_mongo_mapper/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails3_mongo_mapper/config/initializers/inflections.rb +0 -10
- data/spec/rails3_mongo_mapper/config/initializers/mime_types.rb +0 -5
- data/spec/rails3_mongo_mapper/config/initializers/mongo.rb +0 -2
- data/spec/rails3_mongo_mapper/config/initializers/secret_token.rb +0 -7
- data/spec/rails3_mongo_mapper/config/initializers/session_store.rb +0 -8
- data/spec/rails3_mongo_mapper/config/locales/en.yml +0 -5
- data/spec/rails3_mongo_mapper/config/routes.rb +0 -59
- data/spec/rails3_mongo_mapper/db/schema.rb +0 -23
- data/spec/rails3_mongo_mapper/db/seeds.rb +0 -7
- data/spec/rails3_mongo_mapper/lib/tasks/.gitkeep +0 -0
- data/spec/rails3_mongo_mapper/public/404.html +0 -26
- data/spec/rails3_mongo_mapper/public/422.html +0 -26
- data/spec/rails3_mongo_mapper/public/500.html +0 -26
- data/spec/rails3_mongo_mapper/public/favicon.ico +0 -0
- data/spec/rails3_mongo_mapper/public/images/rails.png +0 -0
- data/spec/rails3_mongo_mapper/public/javascripts/application.js +0 -2
- data/spec/rails3_mongo_mapper/public/javascripts/controls.js +0 -965
- data/spec/rails3_mongo_mapper/public/javascripts/dragdrop.js +0 -974
- data/spec/rails3_mongo_mapper/public/javascripts/effects.js +0 -1123
- data/spec/rails3_mongo_mapper/public/javascripts/prototype.js +0 -6001
- data/spec/rails3_mongo_mapper/public/javascripts/rails.js +0 -175
- data/spec/rails3_mongo_mapper/public/robots.txt +0 -5
- data/spec/rails3_mongo_mapper/public/stylesheets/.gitkeep +0 -0
- data/spec/rails3_mongo_mapper/script/rails +0 -6
- data/spec/rails3_mongo_mapper/spec/controller_spec.rb +0 -175
- data/spec/rails3_mongo_mapper/spec/spec.opts +0 -2
- data/spec/rails3_mongo_mapper/spec/spec_helper.orig.rb +0 -27
- data/spec/rails3_mongo_mapper/spec/spec_helper.rb +0 -55
- data/spec/rails3_mongo_mapper/spec/user_activation_spec.rb +0 -9
- data/spec/rails3_mongo_mapper/spec/user_activity_logging_spec.rb +0 -8
- data/spec/rails3_mongo_mapper/spec/user_brute_force_protection_spec.rb +0 -8
- data/spec/rails3_mongo_mapper/spec/user_oauth_spec.rb +0 -8
- data/spec/rails3_mongo_mapper/spec/user_remember_me_spec.rb +0 -8
- data/spec/rails3_mongo_mapper/spec/user_reset_password_spec.rb +0 -8
- data/spec/rails3_mongo_mapper/spec/user_spec.rb +0 -37
- data/spec/rails3_mongo_mapper/vendor/plugins/.gitkeep +0 -0
- data/spec/rails3_mongoid/.gitignore +0 -4
- data/spec/rails3_mongoid/.rspec +0 -1
- data/spec/rails3_mongoid/Gemfile +0 -15
- data/spec/rails3_mongoid/Gemfile.lock +0 -146
- data/spec/rails3_mongoid/Rakefile +0 -11
- data/spec/rails3_mongoid/app/controllers/application_controller.rb +0 -127
- data/spec/rails3_mongoid/app/helpers/application_helper.rb +0 -2
- data/spec/rails3_mongoid/app/mailers/sorcery_mailer.rb +0 -25
- data/spec/rails3_mongoid/app/views/layouts/application.html.erb +0 -14
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_email.html.erb +0 -17
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_email.text.erb +0 -9
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_success_email.html.erb +0 -17
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_success_email.text.erb +0 -9
- data/spec/rails3_mongoid/app/views/sorcery_mailer/reset_password_email.html.erb +0 -16
- data/spec/rails3_mongoid/app/views/sorcery_mailer/reset_password_email.text.erb +0 -8
- data/spec/rails3_mongoid/config/application.rb +0 -51
- data/spec/rails3_mongoid/config/boot.rb +0 -13
- data/spec/rails3_mongoid/config/environment.rb +0 -5
- data/spec/rails3_mongoid/config/environments/development.rb +0 -26
- data/spec/rails3_mongoid/config/environments/in_memory.rb +0 -0
- data/spec/rails3_mongoid/config/environments/production.rb +0 -49
- data/spec/rails3_mongoid/config/environments/test.rb +0 -35
- data/spec/rails3_mongoid/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails3_mongoid/config/initializers/inflections.rb +0 -10
- data/spec/rails3_mongoid/config/initializers/mime_types.rb +0 -5
- data/spec/rails3_mongoid/config/initializers/secret_token.rb +0 -7
- data/spec/rails3_mongoid/config/locales/en.yml +0 -5
- data/spec/rails3_mongoid/config/mongoid.yml +0 -7
- data/spec/rails3_mongoid/config/routes.rb +0 -59
- data/spec/rails3_mongoid/config.ru +0 -4
- data/spec/rails3_mongoid/db/schema.rb +0 -23
- data/spec/rails3_mongoid/db/seeds.rb +0 -7
- data/spec/rails3_mongoid/lib/tasks/.gitkeep +0 -0
- data/spec/rails3_mongoid/public/404.html +0 -26
- data/spec/rails3_mongoid/public/422.html +0 -26
- data/spec/rails3_mongoid/public/500.html +0 -26
- data/spec/rails3_mongoid/public/favicon.ico +0 -0
- data/spec/rails3_mongoid/public/images/rails.png +0 -0
- data/spec/rails3_mongoid/public/javascripts/application.js +0 -2
- data/spec/rails3_mongoid/public/javascripts/controls.js +0 -965
- data/spec/rails3_mongoid/public/javascripts/dragdrop.js +0 -974
- data/spec/rails3_mongoid/public/javascripts/effects.js +0 -1123
- data/spec/rails3_mongoid/public/javascripts/prototype.js +0 -6001
- data/spec/rails3_mongoid/public/javascripts/rails.js +0 -175
- data/spec/rails3_mongoid/public/robots.txt +0 -5
- data/spec/rails3_mongoid/public/stylesheets/.gitkeep +0 -0
- data/spec/rails3_mongoid/script/rails +0 -6
- data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +0 -111
- data/spec/rails3_mongoid/spec/controller_spec.rb +0 -186
- data/spec/rails3_mongoid/spec/spec.opts +0 -2
- data/spec/rails3_mongoid/spec/spec_helper.orig.rb +0 -27
- data/spec/rails3_mongoid/spec/spec_helper.rb +0 -55
- data/spec/rails3_mongoid/spec/user_activation_spec.rb +0 -9
- data/spec/rails3_mongoid/spec/user_activity_logging_spec.rb +0 -8
- data/spec/rails3_mongoid/spec/user_brute_force_protection_spec.rb +0 -8
- data/spec/rails3_mongoid/spec/user_oauth_spec.rb +0 -8
- data/spec/rails3_mongoid/spec/user_remember_me_spec.rb +0 -8
- data/spec/rails3_mongoid/spec/user_reset_password_spec.rb +0 -8
- data/spec/rails3_mongoid/spec/user_spec.rb +0 -38
- data/spec/rails3_mongoid/vendor/plugins/.gitkeep +0 -0
- /data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
- /data/spec/{rails3/app/models → rails_app/app/active_record}/authentication.rb +0 -0
- /data/spec/{rails3 → rails_app}/app/helpers/application_helper.rb +0 -0
- /data/spec/{rails3 → rails_app}/app/mailers/sorcery_mailer.rb +0 -0
- /data/spec/{rails3_mongo_mapper/app/models → rails_app/app/mongo_mapper}/authentication.rb +0 -0
- /data/spec/{rails3_mongo_mapper/app/models → rails_app/app/mongo_mapper}/user.rb +0 -0
- /data/spec/{rails3_mongoid/app/models → rails_app/app/mongoid}/authentication.rb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/application/index.html.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/layouts/application.html.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/activation_email.html.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/activation_email.text.erb +0 -0
- /data/spec/{rails3/app/views/sorcery_mailer/activation_success_email.html.erb → rails_app/app/views/sorcery_mailer/activation_needed_email.html.erb} +0 -0
- /data/spec/{rails3_mongo_mapper → rails_app}/app/views/sorcery_mailer/activation_success_email.html.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/activation_success_email.text.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/reset_password_email.html.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/reset_password_email.text.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/send_unlock_token_email.text.erb +0 -0
- /data/spec/{rails3 → rails_app}/config/environment.rb +0 -0
- /data/spec/{rails3 → rails_app}/config/initializers/backtrace_silencers.rb +0 -0
- /data/spec/{rails3 → rails_app}/config/initializers/inflections.rb +0 -0
- /data/spec/{rails3 → rails_app}/config/initializers/mime_types.rb +0 -0
- /data/spec/{rails3 → rails_app}/config/initializers/secret_token.rb +0 -0
- /data/spec/{rails3 → rails_app}/config/locales/en.yml +0 -0
- /data/spec/{rails3 → rails_app}/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -0
- /data/spec/{rails3 → rails_app}/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -0
- /data/spec/{rails3 → rails_app}/db/migrate/core/20101224223620_create_users.rb +0 -0
- /data/spec/{rails3 → rails_app}/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -0
- /data/spec/{rails3 → rails_app}/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -0
- /data/spec/{rails3 → rails_app}/db/schema.rb +0 -0
- /data/spec/{rails3 → rails_app}/db/seeds.rb +0 -0
- /data/spec/{rails3 → rails_app}/public/404.html +0 -0
- /data/spec/{rails3 → rails_app}/public/422.html +0 -0
- /data/spec/{rails3 → rails_app}/public/500.html +0 -0
- /data/spec/{rails3 → rails_app}/public/favicon.ico +0 -0
- /data/spec/{rails3 → rails_app}/public/images/rails.png +0 -0
- /data/spec/{rails3 → rails_app}/public/javascripts/application.js +0 -0
- /data/spec/{rails3 → rails_app}/public/javascripts/controls.js +0 -0
- /data/spec/{rails3 → rails_app}/public/javascripts/dragdrop.js +0 -0
- /data/spec/{rails3 → rails_app}/public/javascripts/effects.js +0 -0
- /data/spec/{rails3 → rails_app}/public/javascripts/prototype.js +0 -0
- /data/spec/{rails3 → rails_app}/public/javascripts/rails.js +0 -0
- /data/spec/{rails3 → rails_app}/public/robots.txt +0 -0
- /data/spec/{rails3/lib/tasks → rails_app/public/stylesheets}/.gitkeep +0 -0
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
class SorceryResetPassword < ActiveRecord::Migration
|
|
2
|
-
def
|
|
2
|
+
def change
|
|
3
3
|
add_column :<%= model_class_name.tableize %>, :reset_password_token, :string, :default => nil
|
|
4
4
|
add_column :<%= model_class_name.tableize %>, :reset_password_token_expires_at, :datetime, :default => nil
|
|
5
5
|
add_column :<%= model_class_name.tableize %>, :reset_password_email_sent_at, :datetime, :default => nil
|
|
6
|
-
|
|
7
|
-
add_index :<%= model_class_name.tableize %>, :reset_password_token
|
|
8
|
-
end
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
remove_index :<%= model_class_name.tableize %>, :reset_password_token
|
|
12
|
-
|
|
13
|
-
remove_column :<%= model_class_name.tableize %>, :reset_password_email_sent_at
|
|
14
|
-
remove_column :<%= model_class_name.tableize %>, :reset_password_token_expires_at
|
|
15
|
-
remove_column :<%= model_class_name.tableize %>, :reset_password_token
|
|
7
|
+
add_index :<%= model_class_name.tableize %>, :reset_password_token
|
|
16
8
|
end
|
|
17
9
|
end
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
class SorceryUserActivation < ActiveRecord::Migration
|
|
2
|
-
def
|
|
2
|
+
def change
|
|
3
3
|
add_column :<%= model_class_name.tableize %>, :activation_state, :string, :default => nil
|
|
4
4
|
add_column :<%= model_class_name.tableize %>, :activation_token, :string, :default => nil
|
|
5
5
|
add_column :<%= model_class_name.tableize %>, :activation_token_expires_at, :datetime, :default => nil
|
|
6
|
-
|
|
7
|
-
add_index :<%= model_class_name.tableize %>, :activation_token
|
|
8
|
-
end
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
remove_index :<%= model_class_name.tableize %>, :activation_token
|
|
12
|
-
|
|
13
|
-
remove_column :<%= model_class_name.tableize %>, :activation_token_expires_at
|
|
14
|
-
remove_column :<%= model_class_name.tableize %>, :activation_token
|
|
15
|
-
remove_column :<%= model_class_name.tableize %>, :activation_state
|
|
7
|
+
add_index :<%= model_class_name.tableize %>, :activation_token
|
|
16
8
|
end
|
|
17
9
|
end
|
|
@@ -6,21 +6,38 @@ module Sorcery
|
|
|
6
6
|
module External
|
|
7
7
|
def self.included(base)
|
|
8
8
|
base.send(:include, InstanceMethods)
|
|
9
|
+
|
|
10
|
+
require 'sorcery/providers/base'
|
|
11
|
+
require 'sorcery/providers/facebook'
|
|
12
|
+
require 'sorcery/providers/twitter'
|
|
13
|
+
require 'sorcery/providers/vk'
|
|
14
|
+
require 'sorcery/providers/linkedin'
|
|
15
|
+
require 'sorcery/providers/liveid'
|
|
16
|
+
require 'sorcery/providers/xing'
|
|
17
|
+
require 'sorcery/providers/github'
|
|
18
|
+
require 'sorcery/providers/google'
|
|
19
|
+
|
|
9
20
|
Config.module_eval do
|
|
10
21
|
class << self
|
|
11
|
-
attr_reader :external_providers
|
|
12
|
-
attr_accessor :ca_file
|
|
13
|
-
|
|
14
|
-
def merge_external_defaults!
|
|
15
|
-
@defaults.merge!(:@external_providers => [],
|
|
16
|
-
:@ca_file => File.join(File.expand_path(File.dirname(__FILE__)), 'external/protocols/certs/ca-bundle.crt'))
|
|
17
|
-
end
|
|
22
|
+
attr_reader :external_providers
|
|
23
|
+
attr_accessor :ca_file
|
|
18
24
|
|
|
19
25
|
def external_providers=(providers)
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
@external_providers = providers
|
|
27
|
+
|
|
28
|
+
providers.each do |name|
|
|
29
|
+
class_eval <<-E
|
|
30
|
+
def self.#{name}
|
|
31
|
+
@#{name} ||= Sorcery::Providers.const_get('#{name}'.to_s.capitalize).new
|
|
32
|
+
end
|
|
33
|
+
E
|
|
22
34
|
end
|
|
23
35
|
end
|
|
36
|
+
|
|
37
|
+
def merge_external_defaults!
|
|
38
|
+
@defaults.merge!(:@external_providers => [],
|
|
39
|
+
:@ca_file => File.join(File.expand_path(File.dirname(__FILE__)), '../../protocols/certs/ca-bundle.crt'))
|
|
40
|
+
end
|
|
24
41
|
end
|
|
25
42
|
merge_external_defaults!
|
|
26
43
|
end
|
|
@@ -31,15 +48,17 @@ module Sorcery
|
|
|
31
48
|
|
|
32
49
|
# save the singleton ProviderClient instance into @provider
|
|
33
50
|
def sorcery_get_provider(provider_name)
|
|
51
|
+
return unless Config.external_providers.include?(provider_name.to_sym)
|
|
34
52
|
Config.send(provider_name.to_sym)
|
|
35
53
|
end
|
|
36
54
|
|
|
37
55
|
# get the login URL from the provider, if applicable. Returns nil if the provider
|
|
38
56
|
# does not provide a login URL. (as of v0.8.1 all providers provide a login URL)
|
|
39
|
-
def sorcery_login_url(provider_name)
|
|
57
|
+
def sorcery_login_url(provider_name, args = {})
|
|
40
58
|
@provider = sorcery_get_provider provider_name
|
|
41
59
|
sorcery_fixup_callback_url @provider
|
|
42
60
|
if @provider.respond_to?(:login_url) && @provider.has_callback?
|
|
61
|
+
@provider.state = args[:state] if args[:state]
|
|
43
62
|
return @provider.login_url(params, session)
|
|
44
63
|
else
|
|
45
64
|
return nil
|
|
@@ -86,22 +105,22 @@ module Sorcery
|
|
|
86
105
|
# sends user to authenticate at the provider's website.
|
|
87
106
|
# after authentication the user is redirected to the callback defined in the provider config
|
|
88
107
|
def login_at(provider_name, args = {})
|
|
89
|
-
redirect_to sorcery_login_url(provider_name)
|
|
108
|
+
redirect_to sorcery_login_url(provider_name, args)
|
|
90
109
|
end
|
|
91
110
|
|
|
92
111
|
# tries to login the user from provider's callback
|
|
93
|
-
def login_from(provider_name)
|
|
112
|
+
def login_from(provider_name, should_remember = false)
|
|
94
113
|
sorcery_fetch_user_hash provider_name
|
|
95
|
-
|
|
114
|
+
|
|
96
115
|
if user = user_class.load_from_provider(provider_name, @user_hash[:uid].to_s)
|
|
97
116
|
# we found the user.
|
|
98
117
|
# clear the session
|
|
99
118
|
return_to_url = session[:return_to_url]
|
|
100
|
-
|
|
119
|
+
reset_sorcery_session
|
|
101
120
|
session[:return_to_url] = return_to_url
|
|
102
121
|
|
|
103
122
|
# sign in the user
|
|
104
|
-
auto_login(user)
|
|
123
|
+
auto_login(user, should_remember)
|
|
105
124
|
after_login!(user)
|
|
106
125
|
|
|
107
126
|
# return the user
|
|
@@ -115,9 +134,9 @@ module Sorcery
|
|
|
115
134
|
config = user_class.sorcery_config
|
|
116
135
|
|
|
117
136
|
# first check to see if user has a particular authentication already
|
|
118
|
-
unless (current_user.send(config.authentications_class.
|
|
119
|
-
user = current_user.send(config.authentications_class.
|
|
120
|
-
user.
|
|
137
|
+
unless (current_user.send(config.authentications_class.name.underscore.pluralize).send("find_by_#{config.provider_attribute_name}_and_#{config.provider_uid_attribute_name}", provider_name, @user_hash[:uid].to_s))
|
|
138
|
+
user = current_user.send(config.authentications_class.name.underscore.pluralize).build(config.provider_uid_attribute_name => @user_hash[:uid], config.provider_attribute_name => provider_name.to_s)
|
|
139
|
+
user.sorcery_save(:validate => false)
|
|
121
140
|
else
|
|
122
141
|
user = false
|
|
123
142
|
end
|
|
@@ -140,7 +159,7 @@ module Sorcery
|
|
|
140
159
|
session[:incomplete_user] = {
|
|
141
160
|
:provider => {config.provider_uid_attribute_name => @user_hash[:uid], config.provider_attribute_name => provider_name},
|
|
142
161
|
:user_hash => attrs
|
|
143
|
-
} unless user.
|
|
162
|
+
} unless user.sorcery_save
|
|
144
163
|
|
|
145
164
|
return user
|
|
146
165
|
end
|
|
@@ -177,7 +196,7 @@ module Sorcery
|
|
|
177
196
|
return false unless yield @user
|
|
178
197
|
end
|
|
179
198
|
|
|
180
|
-
@user.
|
|
199
|
+
@user.sorcery_save(:validate => false)
|
|
181
200
|
user_class.sorcery_config.authentications_class.create!({config.authentications_user_id_attribute_name => @user.id, config.provider_attribute_name => provider_name, config.provider_uid_attribute_name => @user_hash[:uid]})
|
|
182
201
|
end
|
|
183
202
|
@user
|
|
@@ -37,8 +37,8 @@ module Sorcery
|
|
|
37
37
|
# To be used as a before_filter, before require_login
|
|
38
38
|
def validate_session
|
|
39
39
|
session_to_use = Config.session_timeout_from_last_action ? session[:last_action_time] : session[:login_time]
|
|
40
|
-
if session_to_use && (Time.now.in_time_zone - session_to_use > Config.session_timeout)
|
|
41
|
-
|
|
40
|
+
if session_to_use && (Time.now.in_time_zone - session_to_use.to_time > Config.session_timeout)
|
|
41
|
+
reset_sorcery_session
|
|
42
42
|
@current_user = nil
|
|
43
43
|
else
|
|
44
44
|
session[:last_action_time] = Time.now.in_time_zone
|
data/lib/sorcery/controller.rb
CHANGED
|
@@ -5,7 +5,7 @@ module Sorcery
|
|
|
5
5
|
include InstanceMethods
|
|
6
6
|
Config.submodules.each do |mod|
|
|
7
7
|
begin
|
|
8
|
-
include Submodules.const_get(mod.to_s.split(
|
|
8
|
+
include Submodules.const_get(mod.to_s.split('_').map { |p| p.capitalize }.join)
|
|
9
9
|
rescue NameError
|
|
10
10
|
# don't stop on a missing submodule.
|
|
11
11
|
end
|
|
@@ -33,7 +33,7 @@ module Sorcery
|
|
|
33
33
|
user = user_class.authenticate(*credentials)
|
|
34
34
|
if user
|
|
35
35
|
old_session = session.dup.to_hash
|
|
36
|
-
|
|
36
|
+
reset_sorcery_session
|
|
37
37
|
old_session.each_pair do |k,v|
|
|
38
38
|
session[k.to_sym] = v
|
|
39
39
|
end
|
|
@@ -48,12 +48,20 @@ module Sorcery
|
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
# put this into the catch block to rescue undefined method `destroy_session'
|
|
52
|
+
# hotfix for https://github.com/NoamB/sorcery/issues/464
|
|
53
|
+
# can be removed when Rails 4.1 is out
|
|
54
|
+
def reset_sorcery_session
|
|
55
|
+
reset_session # protect from session fixation attacks
|
|
56
|
+
rescue NoMethodError
|
|
57
|
+
end
|
|
58
|
+
|
|
51
59
|
# Resets the session and runs hooks before and after.
|
|
52
60
|
def logout
|
|
53
61
|
if logged_in?
|
|
54
62
|
@current_user = current_user if @current_user.nil?
|
|
55
63
|
before_logout!(@current_user)
|
|
56
|
-
|
|
64
|
+
reset_sorcery_session
|
|
57
65
|
after_logout!
|
|
58
66
|
@current_user = nil
|
|
59
67
|
end
|
|
@@ -64,9 +72,12 @@ module Sorcery
|
|
|
64
72
|
end
|
|
65
73
|
|
|
66
74
|
# attempts to auto-login from the sources defined (session, basic_auth, cookie, etc.)
|
|
67
|
-
# returns the logged in user if found,
|
|
75
|
+
# returns the logged in user if found, nil if not
|
|
68
76
|
def current_user
|
|
69
|
-
|
|
77
|
+
unless defined?(@current_user)
|
|
78
|
+
@current_user = login_from_session || login_from_other_sources || nil
|
|
79
|
+
end
|
|
80
|
+
@current_user
|
|
70
81
|
end
|
|
71
82
|
|
|
72
83
|
def current_user=(user)
|
|
@@ -91,7 +102,7 @@ module Sorcery
|
|
|
91
102
|
#
|
|
92
103
|
# @param [<User-Model>] user the user instance.
|
|
93
104
|
# @return - do not depend on the return value.
|
|
94
|
-
def auto_login(user)
|
|
105
|
+
def auto_login(user, should_remember = false)
|
|
95
106
|
session[:user_id] = user.id
|
|
96
107
|
@current_user = user
|
|
97
108
|
end
|
|
@@ -115,11 +126,7 @@ module Sorcery
|
|
|
115
126
|
end
|
|
116
127
|
|
|
117
128
|
def login_from_session
|
|
118
|
-
@current_user = (user_class.
|
|
119
|
-
rescue => exception
|
|
120
|
-
return false if defined?(Mongoid) and exception.is_a?(Mongoid::Errors::DocumentNotFound)
|
|
121
|
-
return false if defined?(ActiveRecord) and exception.is_a?(ActiveRecord::RecordNotFound)
|
|
122
|
-
raise exception
|
|
129
|
+
@current_user = (user_class.find_by_id(session[:user_id]) if session[:user_id]) || nil
|
|
123
130
|
end
|
|
124
131
|
|
|
125
132
|
def after_login!(user, credentials = [])
|
|
@@ -19,12 +19,17 @@ module Sorcery
|
|
|
19
19
|
def update_single_attribute(name, value)
|
|
20
20
|
update_many_attributes(name => value)
|
|
21
21
|
end
|
|
22
|
+
|
|
23
|
+
def sorcery_save(options = {})
|
|
24
|
+
mthd = options.delete(:raise_on_failure) ? :save! : :save
|
|
25
|
+
self.send(mthd, options)
|
|
26
|
+
end
|
|
22
27
|
end
|
|
23
28
|
|
|
24
29
|
module ClassMethods
|
|
25
30
|
def column_name(attribute)
|
|
26
31
|
return "LOWER(#{attribute})" if (@sorcery_config.downcase_username_before_authenticating)
|
|
27
|
-
|
|
32
|
+
attribute.to_s
|
|
28
33
|
end
|
|
29
34
|
|
|
30
35
|
def find_by_credentials(credentials)
|
|
@@ -37,7 +42,7 @@ module Sorcery
|
|
|
37
42
|
end
|
|
38
43
|
|
|
39
44
|
def get_current_users
|
|
40
|
-
config = sorcery_config
|
|
45
|
+
config = @sorcery_config
|
|
41
46
|
where("#{config.last_activity_at_attribute_name} IS NOT NULL") \
|
|
42
47
|
.where("#{config.last_logout_at_attribute_name} IS NULL OR #{config.last_activity_at_attribute_name} > #{config.last_logout_at_attribute_name}") \
|
|
43
48
|
.where("#{config.last_activity_at_attribute_name} > ? ", config.activity_timeout.seconds.ago.utc.to_s(:db))
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
module Sorcery
|
|
2
|
+
module Model
|
|
3
|
+
module Adapters
|
|
4
|
+
module DataMapper
|
|
5
|
+
def self.included(klass)
|
|
6
|
+
klass.extend ClassMethods
|
|
7
|
+
klass.send(:include, InstanceMethods)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
module InstanceMethods
|
|
11
|
+
def increment(attr)
|
|
12
|
+
self[attr] ||= 0
|
|
13
|
+
self[attr] += 1
|
|
14
|
+
self
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def update_many_attributes(attrs)
|
|
18
|
+
attrs.each do |name, value|
|
|
19
|
+
value = value.utc if value.is_a?(ActiveSupport::TimeWithZone)
|
|
20
|
+
self.send(:"#{name}=", value)
|
|
21
|
+
end
|
|
22
|
+
self.class.get(self.id).update(attrs)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def update_single_attribute(name, value)
|
|
26
|
+
update_many_attributes(name => value)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def sorcery_save(options = {})
|
|
30
|
+
if options.key?(:validate) && ! options[:validate]
|
|
31
|
+
save!
|
|
32
|
+
else
|
|
33
|
+
save
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
module ClassMethods
|
|
39
|
+
def find(id)
|
|
40
|
+
get(id)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def delete_all
|
|
44
|
+
destroy
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# NOTE
|
|
48
|
+
# DM Adapter dependent
|
|
49
|
+
# DM creates MySQL tables case insensitive by default
|
|
50
|
+
# http://datamapper.lighthouseapp.com/projects/20609-datamapper/tickets/1105
|
|
51
|
+
def find_by_credentials(credentials)
|
|
52
|
+
credential = credentials[0].dup
|
|
53
|
+
credential.downcase! if @sorcery_config.downcase_username_before_authenticating
|
|
54
|
+
@sorcery_config.username_attribute_names.each do |name|
|
|
55
|
+
@user = first(name => credential)
|
|
56
|
+
break if @user
|
|
57
|
+
end
|
|
58
|
+
!!@user ? get(@user.id) : nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def find_by_provider_and_uid(provider, uid)
|
|
62
|
+
@user_klass ||= ::Sorcery::Controller::Config.user_class.to_s.constantize
|
|
63
|
+
user = first(@user_klass.sorcery_config.provider_attribute_name => provider, @user_klass.sorcery_config.provider_uid_attribute_name => uid)
|
|
64
|
+
!!user ? get(user.id) : nil
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def find_by_id(id)
|
|
68
|
+
find(id)
|
|
69
|
+
rescue ::DataMapper::ObjectNotFoundError
|
|
70
|
+
nil
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def find_by_activation_token(token)
|
|
74
|
+
user = first(sorcery_config.activation_token_attribute_name => token)
|
|
75
|
+
!!user ? get(user.id) : nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def find_by_remember_me_token(token)
|
|
79
|
+
user = first(sorcery_config.remember_me_token_attribute_name => token)
|
|
80
|
+
!!user ? get(user.id) : nil
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def find_by_username(username)
|
|
84
|
+
user = nil
|
|
85
|
+
sorcery_config.username_attribute_names.each do |name|
|
|
86
|
+
user = first(name => username)
|
|
87
|
+
break if user
|
|
88
|
+
end
|
|
89
|
+
!!user ? get(user.id) : nil
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def transaction(&blk)
|
|
93
|
+
tap(&blk)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def find_by_sorcery_token(token_attr_name, token)
|
|
97
|
+
user = first(token_attr_name => token)
|
|
98
|
+
!!user ? get(user.id) : nil
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def find_by_email(email)
|
|
102
|
+
user = first(sorcery_config.email_attribute_name => email)
|
|
103
|
+
!!user ? get(user.id) : nil
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# NOTE
|
|
107
|
+
# DM Adapter dependent
|
|
108
|
+
def get_current_users
|
|
109
|
+
unless self.repository.adapter.is_a?(::DataMapper::Adapters::MysqlAdapter)
|
|
110
|
+
raise 'Unsupported DataMapper Adapter'
|
|
111
|
+
end
|
|
112
|
+
config = sorcery_config
|
|
113
|
+
ret = all(config.last_logout_at_attribute_name => nil) |
|
|
114
|
+
all(config.last_activity_at_attribute_name.gt => config.last_logout_at_attribute_name)
|
|
115
|
+
ret = ret.all(config.last_activity_at_attribute_name.not => nil)
|
|
116
|
+
ret = ret.all(config.last_activity_at_attribute_name.gt => config.activity_timeout.seconds.ago.utc)
|
|
117
|
+
ret
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
@@ -5,15 +5,19 @@ module Sorcery
|
|
|
5
5
|
extend ActiveSupport::Concern
|
|
6
6
|
|
|
7
7
|
included do
|
|
8
|
-
|
|
8
|
+
extend Sorcery::Model
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def increment(attr)
|
|
12
12
|
self.class.increment(id, attr => 1)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def
|
|
16
|
-
|
|
15
|
+
def sorcery_save(options = {})
|
|
16
|
+
if options.delete(:raise_on_failure) && options[:validate] != false
|
|
17
|
+
save! options
|
|
18
|
+
else
|
|
19
|
+
save options
|
|
20
|
+
end
|
|
17
21
|
end
|
|
18
22
|
|
|
19
23
|
def update_many_attributes(attrs)
|
|
@@ -22,7 +26,7 @@ module Sorcery
|
|
|
22
26
|
|
|
23
27
|
module ClassMethods
|
|
24
28
|
def credential_regex(credential)
|
|
25
|
-
return { :$regex => /^#{credential}$/i } if (@sorcery_config.downcase_username_before_authenticating)
|
|
29
|
+
return { :$regex => /^#{Regexp.escape(credential)}$/i } if (@sorcery_config.downcase_username_before_authenticating)
|
|
26
30
|
return credential
|
|
27
31
|
end
|
|
28
32
|
|
|
@@ -2,14 +2,9 @@ module Sorcery
|
|
|
2
2
|
module Model
|
|
3
3
|
module Adapters
|
|
4
4
|
module Mongoid
|
|
5
|
-
def self.included(klass)
|
|
6
|
-
klass.extend ClassMethods
|
|
7
|
-
klass.send(:include, InstanceMethods)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
5
|
module InstanceMethods
|
|
11
6
|
def increment(attr)
|
|
12
|
-
self.inc(attr,1)
|
|
7
|
+
self.inc(attr, 1)
|
|
13
8
|
end
|
|
14
9
|
|
|
15
10
|
def update_many_attributes(attrs)
|
|
@@ -23,12 +18,17 @@ module Sorcery
|
|
|
23
18
|
def update_single_attribute(name, value)
|
|
24
19
|
update_many_attributes(name => value)
|
|
25
20
|
end
|
|
21
|
+
|
|
22
|
+
def sorcery_save(options = {})
|
|
23
|
+
mthd = options.delete(:raise_on_failure) ? :save! : :save
|
|
24
|
+
self.send(mthd, options)
|
|
25
|
+
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
module ClassMethods
|
|
29
29
|
def credential_regex(credential)
|
|
30
|
-
return { :$regex => /^#{credential}$/i }
|
|
31
|
-
|
|
30
|
+
return { :$regex => /^#{Regexp.escape(credential)}$/i } if (@sorcery_config.downcase_username_before_authenticating)
|
|
31
|
+
credential
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def find_by_credentials(credentials)
|
|
@@ -29,6 +29,13 @@ module Sorcery
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
base.sorcery_config.after_config << :define_activity_logging_mongoid_fields if defined?(Mongoid) and base.ancestors.include?(Mongoid::Document)
|
|
32
|
+
if defined?(DataMapper) and base.ancestors.include?(DataMapper::Resource)
|
|
33
|
+
# NOTE raise exception if data-store is not supported
|
|
34
|
+
unless base.repository.adapter.is_a?(DataMapper::Adapters::MysqlAdapter)
|
|
35
|
+
raise 'Unsupported DataMapper Adapter'
|
|
36
|
+
end
|
|
37
|
+
base.sorcery_config.after_config << :define_activity_logging_datamapper_fields
|
|
38
|
+
end
|
|
32
39
|
end
|
|
33
40
|
|
|
34
41
|
module ClassMethods
|
|
@@ -46,6 +53,23 @@ module Sorcery
|
|
|
46
53
|
field sorcery_config.last_activity_at_attribute_name, :type => Time
|
|
47
54
|
field sorcery_config.last_login_from_ip_address_name, :type => String
|
|
48
55
|
end
|
|
56
|
+
|
|
57
|
+
def define_activity_logging_datamapper_fields
|
|
58
|
+
property sorcery_config.last_login_at_attribute_name, Time
|
|
59
|
+
property sorcery_config.last_logout_at_attribute_name, Time
|
|
60
|
+
property sorcery_config.last_activity_at_attribute_name, Time
|
|
61
|
+
property sorcery_config.last_login_from_ip_address_name, String
|
|
62
|
+
# Workaround local timezone retrieval problem NOTE dm-core issue #193
|
|
63
|
+
[sorcery_config.last_login_at_attribute_name,
|
|
64
|
+
sorcery_config.last_logout_at_attribute_name,
|
|
65
|
+
sorcery_config.last_activity_at_attribute_name].each do |sym|
|
|
66
|
+
alias_method "orig_#{sym}", sym
|
|
67
|
+
define_method(sym) do
|
|
68
|
+
t = send("orig_#{sym}")
|
|
69
|
+
t && Time.new(t.year, t.month, t.day, t.hour, t.min, t.sec, 0)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
49
73
|
end
|
|
50
74
|
end
|
|
51
75
|
end
|
|
@@ -39,6 +39,9 @@ module Sorcery
|
|
|
39
39
|
if defined?(MongoMapper) and base.ancestors.include?(MongoMapper::Document)
|
|
40
40
|
base.sorcery_config.after_config << :define_brute_force_protection_mongo_mapper_fields
|
|
41
41
|
end
|
|
42
|
+
if defined?(DataMapper) and base.ancestors.include?(DataMapper::Resource)
|
|
43
|
+
base.sorcery_config.after_config << :define_brute_force_protection_datamapper_fields
|
|
44
|
+
end
|
|
42
45
|
base.extend(ClassMethods)
|
|
43
46
|
base.send(:include, InstanceMethods)
|
|
44
47
|
end
|
|
@@ -63,6 +66,19 @@ module Sorcery
|
|
|
63
66
|
key sorcery_config.lock_expires_at_attribute_name, Time
|
|
64
67
|
key sorcery_config.unlock_token_attribute_name, String
|
|
65
68
|
end
|
|
69
|
+
|
|
70
|
+
def define_brute_force_protection_datamapper_fields
|
|
71
|
+
property sorcery_config.failed_logins_count_attribute_name, Integer, :default => 0
|
|
72
|
+
property sorcery_config.lock_expires_at_attribute_name, Time
|
|
73
|
+
property sorcery_config.unlock_token_attribute_name, String
|
|
74
|
+
[sorcery_config.lock_expires_at_attribute_name].each do |sym|
|
|
75
|
+
alias_method "orig_#{sym}", sym
|
|
76
|
+
define_method(sym) do
|
|
77
|
+
t = send("orig_#{sym}")
|
|
78
|
+
t && Time.new(t.year, t.month, t.day, t.hour, t.min, t.sec, 0)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
66
82
|
end
|
|
67
83
|
|
|
68
84
|
module InstanceMethods
|
|
@@ -82,8 +98,8 @@ module Sorcery
|
|
|
82
98
|
def unlock!
|
|
83
99
|
config = sorcery_config
|
|
84
100
|
attributes = {config.lock_expires_at_attribute_name => nil,
|
|
85
|
-
config.failed_logins_count_attribute_name => 0
|
|
86
|
-
|
|
101
|
+
config.failed_logins_count_attribute_name => 0,
|
|
102
|
+
config.unlock_token_attribute_name => nil}
|
|
87
103
|
self.update_many_attributes(attributes)
|
|
88
104
|
end
|
|
89
105
|
|
|
@@ -91,14 +107,12 @@ module Sorcery
|
|
|
91
107
|
|
|
92
108
|
def lock!
|
|
93
109
|
config = sorcery_config
|
|
94
|
-
attributes = {config.lock_expires_at_attribute_name => Time.now.in_time_zone + config.login_lock_time_period
|
|
110
|
+
attributes = {config.lock_expires_at_attribute_name => Time.now.in_time_zone + config.login_lock_time_period,
|
|
111
|
+
config.unlock_token_attribute_name => TemporaryToken.generate_random_token}
|
|
112
|
+
self.update_many_attributes(attributes)
|
|
95
113
|
|
|
96
114
|
unless config.unlock_token_mailer_disabled || config.unlock_token_mailer.nil?
|
|
97
|
-
attributes[config.unlock_token_attribute_name] = TemporaryToken.generate_random_token
|
|
98
|
-
self.update_many_attributes(attributes)
|
|
99
115
|
send_unlock_token_email!
|
|
100
|
-
else
|
|
101
|
-
self.update_many_attributes(attributes)
|
|
102
116
|
end
|
|
103
117
|
end
|
|
104
118
|
|
|
@@ -108,7 +122,7 @@ module Sorcery
|
|
|
108
122
|
end
|
|
109
123
|
|
|
110
124
|
def send_unlock_token_email!
|
|
111
|
-
generic_send_email(:unlock_token_email_method_name, :unlock_token_mailer) unless sorcery_config.unlock_token_email_method_name.nil?
|
|
125
|
+
generic_send_email(:unlock_token_email_method_name, :unlock_token_mailer) unless sorcery_config.unlock_token_email_method_name.nil?
|
|
112
126
|
end
|
|
113
127
|
|
|
114
128
|
# Prevents a locked user from logging in, and unlocks users that expired their lock time.
|
|
@@ -12,7 +12,7 @@ module Sorcery
|
|
|
12
12
|
:remember_me_for # how long in seconds to remember.
|
|
13
13
|
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
base.sorcery_config.instance_eval do
|
|
17
17
|
@defaults.merge!(:@remember_me_token_attribute_name => :remember_me_token,
|
|
18
18
|
:@remember_me_token_expires_at_attribute_name => :remember_me_token_expires_at,
|
|
@@ -20,14 +20,17 @@ module Sorcery
|
|
|
20
20
|
|
|
21
21
|
reset!
|
|
22
22
|
end
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
base.send(:include, InstanceMethods)
|
|
25
25
|
|
|
26
26
|
base.sorcery_config.after_config << :define_remember_me_mongoid_fields if defined?(Mongoid) and base.ancestors.include?(Mongoid::Document)
|
|
27
27
|
if defined?(MongoMapper) and base.ancestors.include?(MongoMapper::Document)
|
|
28
28
|
base.sorcery_config.after_config << :define_remember_me_mongo_mapper_fields
|
|
29
29
|
end
|
|
30
|
-
|
|
30
|
+
if defined?(DataMapper) and base.ancestors.include?(DataMapper::Resource)
|
|
31
|
+
base.sorcery_config.after_config << :define_remember_me_datamapper_fields
|
|
32
|
+
end
|
|
33
|
+
|
|
31
34
|
base.extend(ClassMethods)
|
|
32
35
|
end
|
|
33
36
|
|
|
@@ -43,6 +46,18 @@ module Sorcery
|
|
|
43
46
|
key sorcery_config.remember_me_token_attribute_name, String
|
|
44
47
|
key sorcery_config.remember_me_token_expires_at_attribute_name, Time
|
|
45
48
|
end
|
|
49
|
+
|
|
50
|
+
def define_remember_me_datamapper_fields
|
|
51
|
+
property sorcery_config.remember_me_token_attribute_name, String
|
|
52
|
+
property sorcery_config.remember_me_token_expires_at_attribute_name, Time
|
|
53
|
+
[sorcery_config.remember_me_token_expires_at_attribute_name].each do |sym|
|
|
54
|
+
alias_method "orig_#{sym}", sym
|
|
55
|
+
define_method(sym) do
|
|
56
|
+
t = send("orig_#{sym}")
|
|
57
|
+
t && Time.new(t.year, t.month, t.day, t.hour, t.min, t.sec, 0)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
46
61
|
end
|
|
47
62
|
|
|
48
63
|
module InstanceMethods
|
|
@@ -63,4 +78,4 @@ module Sorcery
|
|
|
63
78
|
end
|
|
64
79
|
end
|
|
65
80
|
end
|
|
66
|
-
end
|
|
81
|
+
end
|