authlogic 1.4.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of authlogic might be problematic. Click here for more details.

Files changed (131) hide show
  1. data/CHANGELOG.rdoc +19 -0
  2. data/Manifest.txt +111 -0
  3. data/README.rdoc +116 -389
  4. data/Rakefile +14 -7
  5. data/lib/authlogic.rb +33 -35
  6. data/lib/authlogic/acts_as_authentic/base.rb +91 -0
  7. data/lib/authlogic/acts_as_authentic/email.rb +77 -0
  8. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +54 -0
  9. data/lib/authlogic/acts_as_authentic/login.rb +65 -0
  10. data/lib/authlogic/acts_as_authentic/magic_columns.rb +24 -0
  11. data/lib/authlogic/acts_as_authentic/password.rb +215 -0
  12. data/lib/authlogic/acts_as_authentic/perishable_token.rb +100 -0
  13. data/lib/authlogic/acts_as_authentic/persistence_token.rb +66 -0
  14. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +60 -0
  15. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +127 -0
  16. data/lib/authlogic/acts_as_authentic/single_access_token.rb +58 -0
  17. data/lib/authlogic/acts_as_authentic/validations_scope.rb +32 -0
  18. data/lib/authlogic/{session/authenticates_many_association.rb → authenticates_many/association.rb} +10 -6
  19. data/lib/authlogic/authenticates_many/base.rb +55 -0
  20. data/lib/authlogic/controller_adapters/abstract_adapter.rb +2 -3
  21. data/lib/authlogic/controller_adapters/merb_adapter.rb +0 -4
  22. data/lib/authlogic/controller_adapters/rails_adapter.rb +0 -4
  23. data/lib/authlogic/crypto_providers/aes256.rb +0 -2
  24. data/lib/authlogic/crypto_providers/bcrypt.rb +0 -2
  25. data/lib/authlogic/crypto_providers/md5.rb +34 -0
  26. data/lib/authlogic/crypto_providers/sha1.rb +0 -2
  27. data/lib/authlogic/crypto_providers/sha512.rb +1 -3
  28. data/lib/authlogic/i18n.rb +1 -4
  29. data/lib/authlogic/random.rb +33 -0
  30. data/lib/authlogic/session/activation.rb +56 -0
  31. data/lib/authlogic/session/active_record_trickery.rb +15 -7
  32. data/lib/authlogic/session/base.rb +31 -456
  33. data/lib/authlogic/session/brute_force_protection.rb +50 -27
  34. data/lib/authlogic/session/callbacks.rb +24 -15
  35. data/lib/authlogic/session/cookies.rb +108 -22
  36. data/lib/authlogic/session/existence.rb +89 -0
  37. data/lib/authlogic/session/foundation.rb +63 -0
  38. data/lib/authlogic/session/http_auth.rb +23 -0
  39. data/lib/authlogic/session/id.rb +41 -0
  40. data/lib/authlogic/session/klass.rb +75 -0
  41. data/lib/authlogic/session/magic_columns.rb +75 -0
  42. data/lib/authlogic/session/magic_states.rb +58 -0
  43. data/lib/authlogic/session/params.rb +82 -19
  44. data/lib/authlogic/session/password.rb +156 -0
  45. data/lib/authlogic/session/{perishability.rb → perishable_token.rb} +4 -4
  46. data/lib/authlogic/session/persistence.rb +70 -0
  47. data/lib/authlogic/session/priority_record.rb +34 -0
  48. data/lib/authlogic/session/scopes.rb +57 -53
  49. data/lib/authlogic/session/session.rb +46 -31
  50. data/lib/authlogic/session/timeout.rb +65 -31
  51. data/lib/authlogic/session/unauthorized_record.rb +50 -0
  52. data/lib/authlogic/session/validation.rb +76 -0
  53. data/lib/authlogic/testing/test_unit_helpers.rb +3 -3
  54. data/lib/authlogic/version.rb +3 -3
  55. data/test/acts_as_authentic_test/base_test.rb +12 -0
  56. data/test/acts_as_authentic_test/email_test.rb +79 -0
  57. data/test/acts_as_authentic_test/logged_in_status_test.rb +36 -0
  58. data/test/acts_as_authentic_test/login_test.rb +79 -0
  59. data/test/acts_as_authentic_test/magic_columns_test.rb +27 -0
  60. data/test/acts_as_authentic_test/password_test.rb +212 -0
  61. data/test/acts_as_authentic_test/perishable_token_test.rb +56 -0
  62. data/test/acts_as_authentic_test/persistence_token_test.rb +55 -0
  63. data/test/acts_as_authentic_test/session_maintenance_test.rb +68 -0
  64. data/test/acts_as_authentic_test/single_access_test.rb +39 -0
  65. data/test/authenticates_many_test.rb +16 -0
  66. data/test/{crypto_provider_tests → crypto_provider_test}/aes256_test.rb +1 -1
  67. data/test/{crypto_provider_tests → crypto_provider_test}/bcrypt_test.rb +1 -1
  68. data/test/{crypto_provider_tests → crypto_provider_test}/sha1_test.rb +1 -1
  69. data/test/{crypto_provider_tests → crypto_provider_test}/sha512_test.rb +1 -1
  70. data/test/fixtures/employees.yml +4 -4
  71. data/test/fixtures/users.yml +6 -6
  72. data/test/libs/company.rb +6 -0
  73. data/test/libs/employee.rb +7 -0
  74. data/test/libs/employee_session.rb +2 -0
  75. data/test/libs/project.rb +3 -0
  76. data/test/libs/user_session.rb +2 -0
  77. data/test/random_test.rb +49 -0
  78. data/test/session_test/activation_test.rb +43 -0
  79. data/test/session_test/active_record_trickery_test.rb +26 -0
  80. data/test/session_test/brute_force_protection_test.rb +76 -0
  81. data/test/session_test/callbacks_test.rb +6 -0
  82. data/test/session_test/cookies_test.rb +107 -0
  83. data/test/session_test/credentials_test.rb +0 -0
  84. data/test/session_test/existence_test.rb +64 -0
  85. data/test/session_test/http_auth_test.rb +16 -0
  86. data/test/session_test/id_test.rb +17 -0
  87. data/test/session_test/klass_test.rb +35 -0
  88. data/test/session_test/magic_columns_test.rb +59 -0
  89. data/test/session_test/magic_states_test.rb +60 -0
  90. data/test/session_test/params_test.rb +53 -0
  91. data/test/session_test/password_test.rb +84 -0
  92. data/test/{session_tests → session_test}/perishability_test.rb +1 -1
  93. data/test/session_test/persistence_test.rb +21 -0
  94. data/test/{session_tests → session_test}/scopes_test.rb +2 -3
  95. data/test/session_test/session_test.rb +59 -0
  96. data/test/session_test/timeout_test.rb +43 -0
  97. data/test/session_test/unauthorized_record_test.rb +13 -0
  98. data/test/session_test/validation_test.rb +23 -0
  99. data/test/test_helper.rb +14 -29
  100. metadata +120 -112
  101. data/Manifest +0 -76
  102. data/authlogic.gemspec +0 -38
  103. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/base.rb +0 -22
  104. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb +0 -238
  105. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb +0 -155
  106. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb +0 -51
  107. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/perishability.rb +0 -71
  108. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb +0 -94
  109. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb +0 -87
  110. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb +0 -61
  111. data/lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb +0 -58
  112. data/lib/authlogic/session/config.rb +0 -421
  113. data/lib/authlogic/session/errors.rb +0 -18
  114. data/lib/authlogic/session/record_info.rb +0 -24
  115. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb +0 -154
  116. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb +0 -157
  117. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb +0 -24
  118. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/perishability_test.rb +0 -41
  119. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb +0 -54
  120. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb +0 -62
  121. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb +0 -41
  122. data/test/orm_adapters_tests/active_record_adapter_tests/authenticates_many_test.rb +0 -32
  123. data/test/session_tests/active_record_trickery_test.rb +0 -14
  124. data/test/session_tests/authenticates_many_association_test.rb +0 -28
  125. data/test/session_tests/base_test.rb +0 -307
  126. data/test/session_tests/brute_force_protection_test.rb +0 -53
  127. data/test/session_tests/config_test.rb +0 -184
  128. data/test/session_tests/cookies_test.rb +0 -32
  129. data/test/session_tests/params_test.rb +0 -32
  130. data/test/session_tests/session_test.rb +0 -45
  131. data/test/session_tests/timeout_test.rb +0 -71
data/Manifest DELETED
@@ -1,76 +0,0 @@
1
- CHANGELOG.rdoc
2
- generators/session/session_generator.rb
3
- generators/session/templates/session.rb
4
- init.rb
5
- lib/authlogic/controller_adapters/abstract_adapter.rb
6
- lib/authlogic/controller_adapters/merb_adapter.rb
7
- lib/authlogic/controller_adapters/rails_adapter.rb
8
- lib/authlogic/crypto_providers/aes256.rb
9
- lib/authlogic/crypto_providers/bcrypt.rb
10
- lib/authlogic/crypto_providers/sha1.rb
11
- lib/authlogic/crypto_providers/sha512.rb
12
- lib/authlogic/i18n.rb
13
- lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/base.rb
14
- lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb
15
- lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb
16
- lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb
17
- lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/perishability.rb
18
- lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb
19
- lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb
20
- lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb
21
- lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb
22
- lib/authlogic/session/active_record_trickery.rb
23
- lib/authlogic/session/authenticates_many_association.rb
24
- lib/authlogic/session/base.rb
25
- lib/authlogic/session/brute_force_protection.rb
26
- lib/authlogic/session/callbacks.rb
27
- lib/authlogic/session/config.rb
28
- lib/authlogic/session/cookies.rb
29
- lib/authlogic/session/errors.rb
30
- lib/authlogic/session/params.rb
31
- lib/authlogic/session/perishability.rb
32
- lib/authlogic/session/record_info.rb
33
- lib/authlogic/session/scopes.rb
34
- lib/authlogic/session/session.rb
35
- lib/authlogic/session/timeout.rb
36
- lib/authlogic/testing/test_unit_helpers.rb
37
- lib/authlogic/version.rb
38
- lib/authlogic.rb
39
- Manifest
40
- MIT-LICENSE
41
- Rakefile
42
- README.rdoc
43
- shoulda_macros/authlogic.rb
44
- test/crypto_provider_tests/aes256_test.rb
45
- test/crypto_provider_tests/bcrypt_test.rb
46
- test/crypto_provider_tests/sha1_test.rb
47
- test/crypto_provider_tests/sha512_test.rb
48
- test/fixtures/companies.yml
49
- test/fixtures/employees.yml
50
- test/fixtures/projects.yml
51
- test/fixtures/users.yml
52
- test/libs/mock_controller.rb
53
- test/libs/mock_cookie_jar.rb
54
- test/libs/mock_request.rb
55
- test/libs/ordered_hash.rb
56
- test/libs/user.rb
57
- test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb
58
- test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb
59
- test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb
60
- test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/perishability_test.rb
61
- test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb
62
- test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb
63
- test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb
64
- test/orm_adapters_tests/active_record_adapter_tests/authenticates_many_test.rb
65
- test/session_tests/active_record_trickery_test.rb
66
- test/session_tests/authenticates_many_association_test.rb
67
- test/session_tests/base_test.rb
68
- test/session_tests/brute_force_protection_test.rb
69
- test/session_tests/config_test.rb
70
- test/session_tests/cookies_test.rb
71
- test/session_tests/params_test.rb
72
- test/session_tests/perishability_test.rb
73
- test/session_tests/scopes_test.rb
74
- test/session_tests/session_test.rb
75
- test/session_tests/timeout_test.rb
76
- test/test_helper.rb
data/authlogic.gemspec DELETED
@@ -1,38 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{authlogic}
5
- s.version = "1.4.3"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Ben Johnson of Binary Logic"]
9
- s.date = %q{2009-02-22}
10
- s.description = %q{A clean, simple, and unobtrusive ruby authentication solution.}
11
- s.email = %q{bjohnson@binarylogic.com}
12
- s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/authlogic/controller_adapters/abstract_adapter.rb", "lib/authlogic/controller_adapters/merb_adapter.rb", "lib/authlogic/controller_adapters/rails_adapter.rb", "lib/authlogic/crypto_providers/aes256.rb", "lib/authlogic/crypto_providers/bcrypt.rb", "lib/authlogic/crypto_providers/sha1.rb", "lib/authlogic/crypto_providers/sha512.rb", "lib/authlogic/i18n.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/base.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/perishability.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb", "lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb", "lib/authlogic/session/active_record_trickery.rb", "lib/authlogic/session/authenticates_many_association.rb", "lib/authlogic/session/base.rb", "lib/authlogic/session/brute_force_protection.rb", "lib/authlogic/session/callbacks.rb", "lib/authlogic/session/config.rb", "lib/authlogic/session/cookies.rb", "lib/authlogic/session/errors.rb", "lib/authlogic/session/params.rb", "lib/authlogic/session/perishability.rb", "lib/authlogic/session/record_info.rb", "lib/authlogic/session/scopes.rb", "lib/authlogic/session/session.rb", "lib/authlogic/session/timeout.rb", "lib/authlogic/testing/test_unit_helpers.rb", "lib/authlogic/version.rb", "lib/authlogic.rb", "README.rdoc"]
13
- s.files = ["CHANGELOG.rdoc", "generators/session/session_generator.rb", "generators/session/templates/session.rb", "init.rb", "lib/authlogic/controller_adapters/abstract_adapter.rb", "lib/authlogic/controller_adapters/merb_adapter.rb", "lib/authlogic/controller_adapters/rails_adapter.rb", "lib/authlogic/crypto_providers/aes256.rb", "lib/authlogic/crypto_providers/bcrypt.rb", "lib/authlogic/crypto_providers/sha1.rb", "lib/authlogic/crypto_providers/sha512.rb", "lib/authlogic/i18n.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/base.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/perishability.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb", "lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb", "lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb", "lib/authlogic/session/active_record_trickery.rb", "lib/authlogic/session/authenticates_many_association.rb", "lib/authlogic/session/base.rb", "lib/authlogic/session/brute_force_protection.rb", "lib/authlogic/session/callbacks.rb", "lib/authlogic/session/config.rb", "lib/authlogic/session/cookies.rb", "lib/authlogic/session/errors.rb", "lib/authlogic/session/params.rb", "lib/authlogic/session/perishability.rb", "lib/authlogic/session/record_info.rb", "lib/authlogic/session/scopes.rb", "lib/authlogic/session/session.rb", "lib/authlogic/session/timeout.rb", "lib/authlogic/testing/test_unit_helpers.rb", "lib/authlogic/version.rb", "lib/authlogic.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README.rdoc", "shoulda_macros/authlogic.rb", "test/crypto_provider_tests/aes256_test.rb", "test/crypto_provider_tests/bcrypt_test.rb", "test/crypto_provider_tests/sha1_test.rb", "test/crypto_provider_tests/sha512_test.rb", "test/fixtures/companies.yml", "test/fixtures/employees.yml", "test/fixtures/projects.yml", "test/fixtures/users.yml", "test/libs/mock_controller.rb", "test/libs/mock_cookie_jar.rb", "test/libs/mock_request.rb", "test/libs/ordered_hash.rb", "test/libs/user.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/perishability_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/authenticates_many_test.rb", "test/session_tests/active_record_trickery_test.rb", "test/session_tests/authenticates_many_association_test.rb", "test/session_tests/base_test.rb", "test/session_tests/brute_force_protection_test.rb", "test/session_tests/config_test.rb", "test/session_tests/cookies_test.rb", "test/session_tests/params_test.rb", "test/session_tests/perishability_test.rb", "test/session_tests/scopes_test.rb", "test/session_tests/session_test.rb", "test/session_tests/timeout_test.rb", "test/test_helper.rb", "authlogic.gemspec"]
14
- s.has_rdoc = true
15
- s.homepage = %q{http://github.com/binarylogic/authlogic}
16
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Authlogic", "--main", "README.rdoc"]
17
- s.require_paths = ["lib"]
18
- s.rubyforge_project = %q{authlogic}
19
- s.rubygems_version = %q{1.3.1}
20
- s.summary = %q{A clean, simple, and unobtrusive ruby authentication solution.}
21
- s.test_files = ["test/crypto_provider_tests/aes256_test.rb", "test/crypto_provider_tests/bcrypt_test.rb", "test/crypto_provider_tests/sha1_test.rb", "test/crypto_provider_tests/sha512_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/perishability_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb", "test/orm_adapters_tests/active_record_adapter_tests/authenticates_many_test.rb", "test/session_tests/active_record_trickery_test.rb", "test/session_tests/authenticates_many_association_test.rb", "test/session_tests/base_test.rb", "test/session_tests/brute_force_protection_test.rb", "test/session_tests/config_test.rb", "test/session_tests/cookies_test.rb", "test/session_tests/params_test.rb", "test/session_tests/perishability_test.rb", "test/session_tests/scopes_test.rb", "test/session_tests/session_test.rb", "test/session_tests/timeout_test.rb", "test/test_helper.rb"]
22
-
23
- if s.respond_to? :specification_version then
24
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
- s.specification_version = 2
26
-
27
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
29
- s.add_runtime_dependency(%q<echoe>, [">= 0"])
30
- else
31
- s.add_dependency(%q<activesupport>, [">= 0"])
32
- s.add_dependency(%q<echoe>, [">= 0"])
33
- end
34
- else
35
- s.add_dependency(%q<activesupport>, [">= 0"])
36
- s.add_dependency(%q<echoe>, [">= 0"])
37
- end
38
- end
@@ -1,22 +0,0 @@
1
- module Authlogic
2
- module ORMAdapters # :nodoc:
3
- module ActiveRecordAdapter # :nodoc:
4
- # = Acts As Authentic
5
- #
6
- # Provides the acts_as_authentic method to include in your models to help with authentication. You can include it as follows:
7
- #
8
- # class User < ActiveRecord::Base
9
- # acts_as_authentic :option => "value"
10
- # end
11
- #
12
- # For a list of configuration options see the ActsAsAuthentic::Config module.
13
- module ActsAsAuthentic
14
- # All logic for this method is split up into sub modules. See sub modules for more details.
15
- def acts_as_authentic(options = {})
16
- end
17
- end
18
- end
19
- end
20
- end
21
-
22
- ActiveRecord::Base.extend Authlogic::ORMAdapters::ActiveRecordAdapter::ActsAsAuthentic
@@ -1,238 +0,0 @@
1
- module Authlogic
2
- module ORMAdapters
3
- module ActiveRecordAdapter
4
- module ActsAsAuthentic
5
- # = Config
6
- #
7
- # Allows you to set various configuration when calling acts_as_authentic. Pass your configuration like the following:
8
- #
9
- # class User < ActiveRecord::Base
10
- # acts_as_authentic :my_option => "my value"
11
- # end
12
- #
13
- # === Class Methods
14
- #
15
- # * <tt>acts_as_authentic_config</tt> - returns a hash of the acts_as_authentic configuration, including the defaults
16
- #
17
- # === General Options
18
- #
19
- # * <tt>session_class</tt> - default: "#{name}Session",
20
- # This is the related session class. A lot of the configuration will be based off of the configuration values of this class.
21
- #
22
- # * <tt>crypto_provider</tt> - default: Authlogic::CryptoProviders::Sha512,
23
- # This is the class that provides your encryption. By default Authlogic provides its own crypto provider that uses Sha512 encrypton.
24
- #
25
- # * <tt>transition_from_crypto_provider</tt> - default: nil,
26
- # This will transition your users to a new encryption algorithm. Let's say you are using Sha1 and you want to transition to Sha512. Just set the
27
- # :crypto_provider option to Authlogic::CryptoProviders::Sha512 and then set this option to Authlogic::CryptoProviders::Sha1. Every time a user
28
- # logs in their password will be resaved with the new algorithm and all new registrations will use the new algorithm as well.
29
- #
30
- # * <tt>act_like_restful_authentication</tt> - default: false,
31
- # If you are migrating from restful_authentication you will want to set this to true, this way your users will still be able to log in and it will seems as
32
- # if nothing has changed. If you don't do this none of your users will be able to log in. If you are starting a new project I do not recommend enabling this
33
- # as the password encryption algorithm used in restful_authentication (Sha1) is not as secure as the one used in authlogic (Sha512). IF you REALLY want to be secure
34
- # checkout Authlogic::CryptoProviders::BCrypt.
35
- #
36
- # * <tt>transition_from_restful_authentication</tt> - default: false,
37
- # This works just like :transition_from_crypto_provider, but it makes some special exceptions so that your users will transition from restful_authentication, since
38
- # restful_authentication does things a little different than Authlogic.
39
- #
40
- # * <tt>login_field</tt> - default: :login, :username, or :email, depending on which column is present, if none are present defaults to :login
41
- # The name of the field used for logging in. Only specify if you aren't using any of the defaults.
42
- #
43
- # * <tt>login_field_type</tt> - default: options[:login_field] == :email ? :email : :login,
44
- # Tells authlogic how to validation the field, what regex to use, etc. If the field name is email it will automatically use :email,
45
- # otherwise it uses :login.
46
- #
47
- # * <tt>password_field</tt> - default: :password,
48
- # This is the name of the field to set the password, *NOT* the field the encrypted password is stored. Defaults the what the configuration
49
- #
50
- # * <tt>crypted_password_field</tt> - default: :crypted_password, :encrypted_password, :password_hash, :pw_hash, depends on which columns are present, if none are present defaults to nil
51
- # The name of the database field where your encrypted password is stored.
52
- #
53
- # * <tt>password_salt_field</tt> - default: :password_salt, :pw_salt, or :salt, depending on which column is present, defaults to :password_salt if none are present,
54
- # This is the name of the field in your database that stores your password salt.
55
- #
56
- # * <tt>email_field</tt> - default: :email, depending on if it is present, if :email is not present defaults to nil
57
- # The name of the field used to store the email address. Only specify this if you arent using this as your :login_field.
58
- #
59
- # * <tt>single_access_token_field</tt> - default: :single_access_token, :feed_token, or :feeds_token, depending on which column is present, if none are present defaults to nil
60
- # This is the name of the field to login with single access, mainly used for private feed access. Only specify if the name of the field is different
61
- # then the defaults. See the "Single Access" section in the README for more details on how single access works.
62
- #
63
- # * <tt>change_single_access_token_with_password</tt> - default: false,
64
- # When a user changes their password do you want the single access token to change as well? That's what this configuration option is all about.
65
- #
66
- # * <tt>perishable_token_field</tt> - default: :perishable_token, :password_reset_token, :pw_reset_token, :reset_password_token, or :reset_pw_token, depending on which column is present, if none are present defaults to nil
67
- # This is the name of the field in your database that stores your perishable token. The token you should use to confirm your users or allow a password reset. Authlogic takes care
68
- # of maintaining this for you and making sure it changes when needed. Use this token for whatever you want, but keep in mind it is temporary, hence the term "perishable".
69
- #
70
- # * <tt>perishable_token_valid_for</tt> - default: 10.minutes,
71
- # Authlogic gives you a sepcial method for finding records by the perishable token (see Authlogic::ORMAdapters::ActiveRecordAdapter::ActcsAsAuthentic::Perishability). In this method
72
- # it checks for the age of the token. If the token is older than whatever you specify here, a record will NOT be returned. This way the tokens are perishable, thus making this system much
73
- # more secure.
74
- #
75
- # * <tt>disable_perishble_token_maintenance</tt> - default: false,
76
- # Authlogic automatically maintains when to reset the perishable_token. This token should reset frequently because it is "perishable", but how frequent depends on your app.
77
- # By default it tries to reset this token as much as possible, which is done via a before_validation callback. If for some reason you want to maintain this yourself just
78
- # set this to true and use the reset_perishable_token and reset_perishable_token! methods to maintain it yourself.
79
- #
80
- # * <tt>persistence_token_field</tt> - default: :persistence_token, :remember_token, or :cookie_tokien, depending on which column is present,
81
- # defaults to :persistence_token if none are present,
82
- # This is the name of the field your persistence token is stored. The persistence token is a unique token that is stored in the users cookie and
83
- # session. This way you have complete control of when sessions expire and you don't have to change passwords to expire sessions. This also
84
- # ensures that stale sessions can not be persisted. By stale, I mean sessions that are logged in using an outdated password.
85
- #
86
- # * <tt>logged_in_timeout</tt> - default: 10.minutes,
87
- # This is a nifty feature to tell if a user is logged in or not. It's based on activity. So if the user in inactive longer than
88
- # the value passed here they are assumed "logged out". This uses the last_request_at field, this field must be present for this option to take effect.
89
- #
90
- # * <tt>session_ids</tt> - default: [nil],
91
- # The sessions that we want to automatically reset when a user is created or updated so you don't have to worry about this. Set to [] to disable.
92
- # Should be an array of ids. See the Authlogic::Session documentation for information on ids. The order is important.
93
- # The first id should be your main session, the session they need to log into first. This is generally nil. When you don't specify an id
94
- # in your session you are really just inexplicitly saying you want to use the id of nil.
95
- #
96
- # === Validation Options
97
- #
98
- # * <tt>validate_fields</tt> - default: true,
99
- # Tells Authlogic if it should validate ANY of the fields: login_field, email_field, and password_field. If set to false, no validations will be set for any of these fields.
100
- #
101
- # * <tt>validate_login_field</tt> - default: true,
102
- # Tells authlogic if it should validate the :login_field. If set to false, no validations will be set for this field at all.
103
- #
104
- # * <tt>validate_email_field</tt> - default: true,
105
- # Tells Authlogic if it should validate the email field. If set to false, no validations will be set for this field at all.
106
- #
107
- # * <tt>validate_password_field</tt> - default: :password,
108
- # Tells authlogic if it should validate the :password_field. If set to false, no validations will be set for this field at all.
109
- #
110
- # * <tt>scope</tt> - default: nil,
111
- # This scopes validations. If all of your users belong to an account you might want to scope everything to the account. Just pass :account_id
112
- #
113
- # * <tt>validation_options</tt> - default: {},
114
- # Options to pass to ALL validations. These are the options ActiveRecord supplies with their validation methods, see the ActiveRecord documentation for more details.
115
- #
116
- # * <tt>login_field_validation_options</tt> - default: {},
117
- # The same as :validation_options but these are only applied to validations that pertain to the :login_field
118
- #
119
- # * <tt>login_field_validates_length_of_options</tt> - default: :login_field_type == :email ? {:within => 6..100} : {:within => 2..100},
120
- # These options are applied to the validates_length_of call for the :login_field
121
- #
122
- # * <tt>login_field_validates_format_of_options</tt> - default: :login_field_type == :email ? {:with => standard_email_regex, :message => "should look like an email address."} : {:with => standard_login_regex, :message => "should use only letters, numbers, spaces, and .-_@ please."},
123
- # These options are applied to the validates_format_of call for the :login_field
124
- #
125
- # * <tt>login_field_validates_uniqueness_of_options</tt> - default: {:allow_blank => true},
126
- # These options are applied to the validates_uniqueness_of call for the :login_field, the :allow_blank => true just prevents the error message when you have options login fields
127
- # such as an OpenID field. The other validations will make sure the field is not actaully blank.
128
- #
129
- # * <tt>password_field_validation_options</tt> - default: {},
130
- # The same as :validation_options but these are only applied to validations that pertain to the :password_field
131
- #
132
- # * <tt>password_field_validates_length_of_options</tt> - default: {:minimum => 4},
133
- # These options are applied to the validates_length_of call for the :password_field
134
- #
135
- # * <tt>password_field_validates_confirmation_of_options</tt> - default: {},
136
- # These options are applied to the validates_confirmation_of call for the :password_field
137
- #
138
- # * <tt>password_confirmation_field_validates_presence_of_options</tt> - default: {},
139
- # These options are applied to the validates_presence_of call for the :password_confirmation_field.
140
- #
141
- # * <tt>email_field_validation_options</tt> - default: {},
142
- # The same as :validation_options but these are only applied to validations that pertain to the :email_field
143
- #
144
- # * <tt>email_field_validates_length_of_options</tt> - default: same as :login_field if :login_field_type == :email,
145
- # These options are applied to the validates_length_of call for the :email_field
146
- #
147
- # * <tt>email_field_validates_format_of_options</tt> - default: same as :login_field if :login_field_type == :email,
148
- # These options are applied to the validates_format_of call for the :email_field
149
- #
150
- # * <tt>email_field_validates_uniqueness_of_options</tt> - default: same as :login_field if :login_field_type == :email,
151
- # These options are applied to the validates_uniqueness_of call for the :email_field
152
- module Config
153
- def acts_as_authentic_with_config(options = {})
154
- # Stop all configuration if the DB is not set up
155
- begin
156
- column_names
157
- rescue Exception
158
- return
159
- end
160
-
161
- # Base configuration
162
- options[:session_class] ||= "#{name}Session"
163
- options[:crypto_provider] ||= CryptoProviders::Sha512
164
- options[:login_field] ||= first_column_to_exist(:login, :username, :email)
165
- options[:login_field_type] ||= options[:login_field] == :email ? :email : :login
166
- options[:password_field] ||= :password
167
- options[:crypted_password_field] ||= first_column_to_exist(:crypted_password, :encrypted_password, :password_hash, :pw_hash)
168
- options[:password_salt_field] ||= first_column_to_exist(:password_salt, :pw_salt, :salt)
169
-
170
- options[:email_field] = first_column_to_exist(nil, :email) unless options.key?(:email_field)
171
- options[:email_field] = nil if options[:email_field] == options[:login_field]
172
- options[:persistence_token_field] ||= options[:remember_token_field] || first_column_to_exist(:persistence_token, :remember_token, :cookie_token)
173
- options[:single_access_token_field] ||= first_column_to_exist(nil, :single_access_token, :feed_token, :feeds_token)
174
- options[:perishable_token_field] ||= options[:password_reset_token_field] || first_column_to_exist(nil, :perishable_token, :password_reset_token, :pw_reset_token, :reset_password_token, :reset_pw_token, :activation_token)
175
- options[:perishable_token_valid_for] ||= 10.minutes
176
- options[:perishable_token_valid_for] = options[:perishable_token_valid_for].to_i
177
- options[:logged_in_timeout] ||= 10.minutes
178
- options[:logged_in_timeout] = options[:logged_in_timeout].to_i
179
- options[:session_ids] ||= [nil]
180
-
181
- # Validation configuration
182
- options[:validate_fields] = true unless options.key?(:validate_fields)
183
- options[:validate_login_field] = true unless options.key?(:validate_login_field)
184
- options[:validate_password_field] = true unless options.key?(:validate_password_field)
185
- options[:validate_email_field] = true unless options.key?(:validate_email_field)
186
-
187
- options[:validation_options] ||= {}
188
-
189
- [:login, :password, :email].each do |field_name|
190
- field_key = "#{field_name}_field_validation_options".to_sym
191
- options[field_key] = options[:validation_options].merge(options[field_key] || {})
192
-
193
- validation_types = field_name == :password ? [:length, :confirmation] : [:length, :format, :uniqueness]
194
- validation_types.each do |validation_type|
195
- validation_key = "#{field_name}_field_validates_#{validation_type}_of_options".to_sym
196
- options[validation_key] = options[field_key].merge(options[validation_key] || {})
197
- end
198
- end
199
-
200
- options[:password_confirmation_field_validates_presence_of_options] ||= {}
201
-
202
- if options[:scope]
203
- options[:login_field_validates_uniqueness_of_options][:scope] ||= options[:scope]
204
- options[:email_field_validates_uniqueness_of_options][:scope] ||= options[:scope]
205
- end
206
-
207
- if options[:act_like_restful_authentication] || options[:transition_from_restful_authentication]
208
- crypto_provider_key = options[:act_like_restful_authentication] ? :crypto_provider : :transition_from_crypto_provider
209
- options[crypto_provider_key] = CryptoProviders::Sha1
210
- if !defined?(REST_AUTH_SITE_KEY) || REST_AUTH_SITE_KEY.nil?
211
- class_eval("::REST_AUTH_SITE_KEY = nil") unless defined?(REST_AUTH_SITE_KEY)
212
- options[crypto_provider_key].stretches = 1
213
- end
214
- end
215
-
216
- options[:transition_from_crypto_provider] = [options[:transition_from_crypto_provider]].compact unless options[:transition_from_crypto_provider].is_a?(Array)
217
-
218
- cattr_accessor :acts_as_authentic_config
219
- self.acts_as_authentic_config = options
220
- acts_as_authentic_without_config(options)
221
- end
222
-
223
- def first_column_to_exist(*columns_to_check) # :nodoc:
224
- columns_to_check.each { |column_name| return column_name.to_sym if column_names.include?(column_name.to_s) }
225
- columns_to_check.first ? columns_to_check.first.to_sym : nil
226
- end
227
- end
228
- end
229
- end
230
- end
231
- end
232
-
233
- ActiveRecord::Base.class_eval do
234
- class << self
235
- include Authlogic::ORMAdapters::ActiveRecordAdapter::ActsAsAuthentic::Config
236
- alias_method_chain :acts_as_authentic, :config
237
- end
238
- end
@@ -1,155 +0,0 @@
1
- module Authlogic
2
- module ORMAdapters
3
- module ActiveRecordAdapter
4
- module ActsAsAuthentic
5
- # = Credentials
6
- #
7
- # Handles any credential specific code, such as validating the login, encrpyting the password, etc.
8
- #
9
- # === Class Methods
10
- #
11
- # * <tt>friendly_unique_token</tt> - returns a random string of 20 alphanumeric characters. Used when resetting the password. This is a more user friendly token then a long Sha512 hash.
12
- #
13
- # === Instance Methods
14
- #
15
- # * <tt>{options[:password_field]}=(value)</tt> - encrypts a raw password and sets it to your crypted_password_field. Also sets the password_salt to a random token.
16
- # * <tt>valid_{options[:password_field]}?(password_to_check)</tt> - checks is the password is valid. The password passed must be the raw password, not encrypted.
17
- # * <tt>reset_{options[:password_field]}</tt> - resets the password using the friendly_unique_token class method
18
- # * <tt>reset_{options[:password_field]}!</tt> - calls reset_password and then saves the record
19
- module Credentials
20
- def acts_as_authentic_with_credentials(options = {})
21
- acts_as_authentic_without_credentials(options)
22
-
23
- if options[:validate_fields]
24
- email_name_regex = '[\w\.%\+\-]+'
25
- domain_head_regex = '(?:[A-Z0-9\-]+\.)+'
26
- domain_tld_regex = '(?:[A-Z]{2}|aero|ag|asia|at|be|biz|ca|cc|cn|com|de|edu|eu|fm|gov|gs|jobs|jp|in|info|me|mil|mobi|museum|ms|name|net|nu|nz|org|tc|tw|tv|uk|us|vg|ws)'
27
- email_field_regex ||= /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
28
-
29
- if options[:validate_login_field]
30
- case options[:login_field_type]
31
- when :email
32
- validates_length_of options[:login_field], sanitize_validation_length_options({:within => 6..100}, options[:login_field_validates_length_of_options])
33
- validates_format_of options[:login_field], {:with => email_field_regex, :message => I18n.t('error_messages.email_invalid', :default => "should look like an email address.")}.merge(options[:login_field_validates_format_of_options])
34
- else
35
- validates_length_of options[:login_field], sanitize_validation_length_options({:within => 2..100}, options[:login_field_validates_length_of_options])
36
- validates_format_of options[:login_field], {:with => /\A\w[\w\.\-_@ ]+\z/, :message => I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.")}.merge(options[:login_field_validates_format_of_options])
37
- end
38
-
39
- validates_uniqueness_of options[:login_field], {:allow_blank => true}.merge(options[:login_field_validates_uniqueness_of_options].merge(:if => "#{options[:login_field]}_changed?".to_sym))
40
- end
41
-
42
- if options[:validate_password_field]
43
- validates_length_of options[:password_field], sanitize_validation_length_options({:minimum => 4}, options[:password_field_validates_length_of_options].merge(:if => "validate_#{options[:password_field]}?".to_sym))
44
- validates_confirmation_of options[:password_field], options[:password_field_validates_confirmation_of_options].merge(:if => "#{options[:password_salt_field]}_changed?".to_sym)
45
- validates_presence_of "#{options[:password_field]}_confirmation", options[:password_confirmation_field_validates_presence_of_options].merge(:if => "#{options[:password_salt_field]}_changed?".to_sym)
46
- end
47
-
48
- if options[:validate_email_field] && options[:email_field]
49
- validates_length_of options[:email_field], sanitize_validation_length_options({:within => 6..100}, options[:email_field_validates_length_of_options])
50
- validates_format_of options[:email_field], {:with => email_field_regex, :message => I18n.t('error_messages.email_invalid', :default => "should look like an email address.")}.merge(options[:email_field_validates_format_of_options])
51
- validates_uniqueness_of options[:email_field], options[:email_field_validates_uniqueness_of_options].merge(:if => "#{options[:email_field]}_changed?".to_sym)
52
- end
53
- end
54
-
55
- attr_accessor "validate_#{options[:password_field]}".to_sym
56
- attr_reader options[:password_field]
57
-
58
- class_eval <<-"end_eval", __FILE__, __LINE__
59
- def self.friendly_unique_token
60
- chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
61
- newpass = ""
62
- 1.upto(20) { |i| newpass << chars[rand(chars.size-1)] }
63
- newpass
64
- end
65
-
66
- def #{options[:password_field]}=(pass)
67
- return if pass.blank?
68
- @#{options[:password_field]} = pass
69
- self.#{options[:password_salt_field]} = self.class.unique_token
70
- self.#{options[:crypted_password_field]} = #{options[:crypto_provider]}.encrypt(*encrypt_arguments(@#{options[:password_field]}, #{options[:act_like_restful_authentication].inspect} ? :restful_authentication : nil))
71
- end
72
-
73
- def valid_#{options[:password_field]}?(attempted_password)
74
- return false if attempted_password.blank? || #{options[:crypted_password_field]}.blank? || #{options[:password_salt_field]}.blank?
75
-
76
- ([#{options[:crypto_provider]}] + #{options[:transition_from_crypto_provider].inspect}).each_with_index do |encryptor, index|
77
- # The arguments_type of for the transitioning from restful_authentication
78
- arguments_type = (#{options[:act_like_restful_authentication].inspect} && index == 0) ||
79
- (#{options[:transition_from_restful_authentication].inspect} && index > 0 && encryptor == Authlogic::CryptoProviders::Sha1) ?
80
- :restful_authentication : nil
81
-
82
- if encryptor.matches?(#{options[:crypted_password_field]}, *encrypt_arguments(attempted_password, arguments_type))
83
- # If we are transitioning from an older encryption algorithm and the password is still using the old algorithm
84
- # then let's reset the password using the new algorithm. If the algorithm has a cost (BCrypt) and the cost has changed, update the password with
85
- # the new cost.
86
- if index > 0 || (encryptor.respond_to?(:cost_matches?) && !encryptor.cost_matches?(#{options[:crypted_password_field]}))
87
- self.password = attempted_password
88
- save(false)
89
- end
90
-
91
- return true
92
- end
93
- end
94
-
95
- false
96
- end
97
-
98
- def reset_#{options[:password_field]}
99
- friendly_token = self.class.friendly_unique_token
100
- self.#{options[:password_field]} = friendly_token
101
- self.#{options[:password_field]}_confirmation = friendly_token
102
- end
103
- alias_method :randomize_#{options[:password_field]}, :reset_#{options[:password_field]}
104
-
105
- def confirm_#{options[:password_field]}
106
- raise "confirm_#{options[:password_field]} has been removed, please use #{options[:password_field]}_confirmation. " +
107
- "As this is the field that ActiveRecord automatically creates with validates_confirmation_of."
108
- end
109
-
110
- def reset_#{options[:password_field]}!
111
- reset_#{options[:password_field]}
112
- save_without_session_maintenance(false)
113
- end
114
- alias_method :randomize_#{options[:password_field]}!, :reset_#{options[:password_field]}!
115
-
116
- def validate_#{options[:password_field]}?
117
- case #{options[:password_field_validates_length_of_options][:if].inspect}
118
- when String
119
- return false if !eval('#{options[:password_field_validates_length_of_options][:if]}')
120
- when Symbol
121
- return false if !send(#{options[:password_field_validates_length_of_options][:if].inspect})
122
- end
123
-
124
- new_record? || #{options[:password_salt_field]}_changed? || #{options[:crypted_password_field]}.blank? || ["true", "1", "yes"].include?(validate_#{options[:password_field]}.to_s)
125
- end
126
-
127
- private
128
- def encrypt_arguments(raw_password, arguments_type = nil)
129
- case arguments_type
130
- when :restful_authentication
131
- [REST_AUTH_SITE_KEY, #{options[:password_salt_field]}, raw_password, REST_AUTH_SITE_KEY]
132
- else
133
- [raw_password, #{options[:password_salt_field]}]
134
- end
135
- end
136
- end_eval
137
- end
138
-
139
- def sanitize_validation_length_options(defaults, options)
140
- length_keys = [:minimum, :maximum, :in, :within, :is]
141
- length_keys.each { |key| defaults.delete(key) } if options.keys.find { |key| length_keys.include?(key.to_sym) }
142
- defaults.merge(options)
143
- end
144
- end
145
- end
146
- end
147
- end
148
- end
149
-
150
- ActiveRecord::Base.class_eval do
151
- class << self
152
- include Authlogic::ORMAdapters::ActiveRecordAdapter::ActsAsAuthentic::Credentials
153
- alias_method_chain :acts_as_authentic, :credentials
154
- end
155
- end