sorcery 0.8.6 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.travis.yml +75 -14
  4. data/CHANGELOG.md +32 -1
  5. data/Gemfile +1 -0
  6. data/README.md +138 -86
  7. data/gemfiles/active_record-rails40.gemfile +7 -0
  8. data/gemfiles/active_record-rails41.gemfile +3 -2
  9. data/gemfiles/mongo_mapper-rails40.gemfile +9 -0
  10. data/gemfiles/mongo_mapper-rails41.gemfile +2 -1
  11. data/gemfiles/mongoid-rails40.gemfile +9 -0
  12. data/gemfiles/mongoid-rails41.gemfile +3 -5
  13. data/gemfiles/mongoid3-rails32.gemfile +9 -0
  14. data/lib/generators/sorcery/USAGE +1 -1
  15. data/lib/generators/sorcery/install_generator.rb +19 -5
  16. data/lib/generators/sorcery/templates/initializer.rb +36 -10
  17. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +3 -1
  18. data/lib/generators/sorcery/templates/migration/core.rb +2 -2
  19. data/lib/generators/sorcery/templates/migration/external.rb +3 -1
  20. data/lib/sorcery/adapters/active_record_adapter.rb +120 -0
  21. data/lib/sorcery/adapters/base_adapter.rb +30 -0
  22. data/lib/sorcery/adapters/data_mapper_adapter.rb +176 -0
  23. data/lib/sorcery/adapters/mongo_mapper_adapter.rb +110 -0
  24. data/lib/sorcery/adapters/mongoid_adapter.rb +97 -0
  25. data/lib/sorcery/controller/config.rb +65 -0
  26. data/lib/sorcery/controller/submodules/activity_logging.rb +16 -21
  27. data/lib/sorcery/controller/submodules/brute_force_protection.rb +6 -6
  28. data/lib/sorcery/controller/submodules/external.rb +9 -29
  29. data/lib/sorcery/controller/submodules/remember_me.rb +4 -4
  30. data/lib/sorcery/controller/submodules/session_timeout.rb +10 -6
  31. data/lib/sorcery/controller.rb +5 -64
  32. data/lib/sorcery/model/config.rb +96 -0
  33. data/lib/sorcery/model/submodules/activity_logging.rb +29 -36
  34. data/lib/sorcery/model/submodules/brute_force_protection.rb +21 -37
  35. data/lib/sorcery/model/submodules/external.rb +53 -9
  36. data/lib/sorcery/model/submodules/remember_me.rb +12 -31
  37. data/lib/sorcery/model/submodules/reset_password.rb +21 -39
  38. data/lib/sorcery/model/submodules/user_activation.rb +21 -63
  39. data/lib/sorcery/model/temporary_token.rb +4 -4
  40. data/lib/sorcery/model.rb +47 -175
  41. data/lib/sorcery/providers/base.rb +11 -0
  42. data/lib/sorcery/providers/facebook.rb +16 -5
  43. data/lib/sorcery/providers/github.rb +11 -2
  44. data/lib/sorcery/providers/google.rb +1 -1
  45. data/lib/sorcery/providers/heroku.rb +57 -0
  46. data/lib/sorcery/providers/jira.rb +77 -0
  47. data/lib/sorcery/providers/linkedin.rb +1 -1
  48. data/lib/sorcery/providers/liveid.rb +1 -1
  49. data/lib/sorcery/providers/salesforce.rb +50 -0
  50. data/lib/sorcery/providers/twitter.rb +1 -1
  51. data/lib/sorcery/providers/vk.rb +6 -4
  52. data/lib/sorcery/providers/xing.rb +2 -2
  53. data/lib/sorcery/test_helpers/internal.rb +7 -3
  54. data/lib/sorcery/test_helpers/rails/controller.rb +5 -1
  55. data/lib/sorcery/version.rb +3 -0
  56. data/lib/sorcery.rb +75 -43
  57. data/sorcery.gemspec +6 -2
  58. data/spec/active_record/user_activity_logging_spec.rb +9 -0
  59. data/spec/controllers/controller_activity_logging_spec.rb +124 -0
  60. data/spec/controllers/controller_brute_force_protection_spec.rb +43 -0
  61. data/spec/{active_record → controllers}/controller_http_basic_auth_spec.rb +14 -11
  62. data/spec/{active_record → controllers}/controller_oauth2_spec.rb +151 -64
  63. data/spec/{active_record → controllers}/controller_oauth_spec.rb +94 -70
  64. data/spec/{active_record → controllers}/controller_remember_me_spec.rb +32 -12
  65. data/spec/{active_record → controllers}/controller_session_timeout_spec.rb +15 -5
  66. data/spec/{shared_examples/controller_shared_examples.rb → controllers/controller_spec.rb} +34 -19
  67. data/spec/{datamapper → data_mapper}/user_activation_spec.rb +1 -1
  68. data/spec/data_mapper/user_activity_logging_spec.rb +14 -0
  69. data/spec/{datamapper → data_mapper}/user_brute_force_protection_spec.rb +1 -1
  70. data/spec/{datamapper → data_mapper}/user_oauth_spec.rb +1 -1
  71. data/spec/{datamapper → data_mapper}/user_remember_me_spec.rb +1 -1
  72. data/spec/{datamapper → data_mapper}/user_reset_password_spec.rb +1 -1
  73. data/spec/{datamapper → data_mapper}/user_spec.rb +1 -1
  74. data/spec/mongoid/user_spec.rb +13 -0
  75. data/spec/orm/active_record.rb +12 -0
  76. data/spec/orm/{datamapper.rb → data_mapper.rb} +16 -2
  77. data/spec/orm/mongo_mapper.rb +0 -1
  78. data/spec/orm/mongoid.rb +4 -0
  79. data/spec/rails_app/app/controllers/sorcery_controller.rb +62 -1
  80. data/spec/rails_app/app/mongo_mapper/user.rb +2 -0
  81. data/spec/rails_app/config/routes.rb +9 -0
  82. data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +2 -2
  83. data/spec/shared_examples/user_activation_shared_examples.rb +7 -7
  84. data/spec/shared_examples/user_activity_logging_shared_examples.rb +73 -5
  85. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +127 -9
  86. data/spec/shared_examples/user_oauth_shared_examples.rb +3 -6
  87. data/spec/shared_examples/user_remember_me_shared_examples.rb +6 -3
  88. data/spec/shared_examples/user_reset_password_shared_examples.rb +10 -10
  89. data/spec/shared_examples/user_shared_examples.rb +146 -46
  90. data/spec/spec_helper.rb +7 -22
  91. metadata +36 -57
  92. data/Gemfile.rails4 +0 -22
  93. data/VERSION +0 -1
  94. data/lib/sorcery/model/adapters/active_record.rb +0 -54
  95. data/lib/sorcery/model/adapters/datamapper.rb +0 -123
  96. data/lib/sorcery/model/adapters/mongo_mapper.rb +0 -60
  97. data/lib/sorcery/model/adapters/mongoid.rb +0 -88
  98. data/lib/sorcery/test_helpers/rails.rb +0 -7
  99. data/spec/active_record/controller_activity_logging_spec.rb +0 -29
  100. data/spec/active_record/controller_brute_force_protection_spec.rb +0 -158
  101. data/spec/active_record/controller_spec.rb +0 -8
  102. data/spec/active_record/integration_spec.rb +0 -23
  103. data/spec/datamapper/controller_activity_logging_spec.rb +0 -17
  104. data/spec/datamapper/controller_spec.rb +0 -8
  105. data/spec/datamapper/user_activity_logging_spec.rb +0 -9
  106. data/spec/mongo_mapper/controller_spec.rb +0 -8
  107. data/spec/mongoid/controller_activity_logging_spec.rb +0 -16
  108. data/spec/mongoid/controller_spec.rb +0 -8
  109. data/spec/rails_app/public/404.html +0 -26
  110. data/spec/rails_app/public/422.html +0 -26
  111. data/spec/rails_app/public/500.html +0 -26
  112. data/spec/rails_app/public/favicon.ico +0 -0
  113. data/spec/rails_app/public/images/rails.png +0 -0
  114. data/spec/rails_app/public/javascripts/application.js +0 -2
  115. data/spec/rails_app/public/javascripts/controls.js +0 -965
  116. data/spec/rails_app/public/javascripts/dragdrop.js +0 -974
  117. data/spec/rails_app/public/javascripts/effects.js +0 -1123
  118. data/spec/rails_app/public/javascripts/prototype.js +0 -6001
  119. data/spec/rails_app/public/javascripts/rails.js +0 -175
  120. data/spec/rails_app/public/robots.txt +0 -5
  121. data/spec/rails_app/public/stylesheets/.gitkeep +0 -0
  122. data/spec/shared_examples/controller_activity_logging_shared_examples.rb +0 -125
  123. data/spec/shared_examples/controller_oauth2_shared_examples.rb +0 -52
  124. data/spec/shared_examples/controller_oauth_shared_examples.rb +0 -62
  125. /data/spec/rails_app/app/{datamapper → data_mapper}/authentication.rb +0 -0
  126. /data/spec/rails_app/app/{datamapper → data_mapper}/user.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73519a45c58c078688dd72b3ef7dc52b2b05ba92
4
- data.tar.gz: a715fe10e2de64c09d76ec93e658849dd3b9112b
3
+ metadata.gz: 5c0e37f33ed4fa3e085ccc8e3a6a5526afb632f2
4
+ data.tar.gz: 1b224ad20e8ed01e04a2b7a25153e5949b56fa4f
5
5
  SHA512:
6
- metadata.gz: 08d0df3e5b8970ec81233d6dbb373cdabb4ff0e219dce27c7c790756507a36d683557ca11d19b70ea8e85217646ef20259892b6e0ee55f8d35c7d25cfb8df636
7
- data.tar.gz: 66cb33e9e89b23036e1470bf0b937da42e68828ecdb821bc736b471cf938c23fa9eb53911ac35050704748ebdfd1790caa27af12ee97fdd26b58c7fae4cf30f9
6
+ metadata.gz: 48d1dd07a9ab99ade78c490bfffd27144b3951d5ba1f45bcfc1baede6db4cbe228e8916025bfd69fbc48d3342724b00ac2cfd9ecc41110d1b9fdd9559885091b
7
+ data.tar.gz: 250ceb737b38dab40dd3e16488f3e37aadf2b09fe94c6147ed92a2d42aab2d61d01601b3a2891403f70cc23ef4e675f4fb1ad83072d59ee71d8d6e5fd9d9c20d
data/.gitignore CHANGED
@@ -52,4 +52,5 @@ spec/rails_app/log/*
52
52
  *.sqlite3
53
53
  Gemfile*.lock
54
54
  gemfiles/*.lock
55
- .ruby-version
55
+ .ruby-version
56
+ tags
data/.travis.yml CHANGED
@@ -8,30 +8,19 @@ services: mongodb
8
8
 
9
9
  gemfile:
10
10
  - Gemfile
11
- - Gemfile.rails4
12
11
 
13
12
  env:
14
13
  - "SORCERY_ORM=active_record"
15
14
  - "SORCERY_ORM=mongoid"
16
15
  - "SORCERY_ORM=mongo_mapper"
17
- - "SORCERY_ORM=datamapper"
16
+ - "SORCERY_ORM=data_mapper"
18
17
 
19
18
  before_script:
20
19
  - mysql -e 'create database sorcery_test;'
21
20
 
22
21
  matrix:
23
- exclude:
24
- - rvm: 1.9.3
25
- gemfile: Gemfile.rails4
26
- env: "SORCERY_ORM=datamapper"
27
-
28
- - rvm: 2.0.0
29
- gemfile: Gemfile.rails4
30
- env: "SORCERY_ORM=datamapper"
31
-
32
- - rvm: 2.1
33
- gemfile: Gemfile.rails4
34
- env: "SORCERY_ORM=datamapper"
22
+ allow_failures:
23
+ - rvm: :jruby
35
24
 
36
25
  include:
37
26
  - rvm: 1.9.3
@@ -46,6 +35,10 @@ matrix:
46
35
  gemfile: gemfiles/mongoid-rails41.gemfile
47
36
  env: "SORCERY_ORM=mongoid"
48
37
 
38
+ - rvm: jruby
39
+ gemfile: gemfiles/mongoid-rails41.gemfile
40
+ env: "SORCERY_ORM=mongoid"
41
+
49
42
  - rvm: 1.9.3
50
43
  gemfile: gemfiles/mongo_mapper-rails41.gemfile
51
44
  env: "SORCERY_ORM=mongo_mapper"
@@ -58,6 +51,10 @@ matrix:
58
51
  gemfile: gemfiles/mongo_mapper-rails41.gemfile
59
52
  env: "SORCERY_ORM=mongo_mapper"
60
53
 
54
+ - rvm: jruby
55
+ gemfile: gemfiles/mongo_mapper-rails41.gemfile
56
+ env: "SORCERY_ORM=mongo_mapper"
57
+
61
58
  - rvm: 1.9.3
62
59
  gemfile: gemfiles/active_record-rails41.gemfile
63
60
  env: "SORCERY_ORM=active_record"
@@ -69,3 +66,67 @@ matrix:
69
66
  - rvm: 2.1
70
67
  gemfile: gemfiles/active_record-rails41.gemfile
71
68
  env: "SORCERY_ORM=active_record"
69
+
70
+ - rvm: jruby
71
+ gemfile: gemfiles/active_record-rails41.gemfile
72
+ env: "SORCERY_ORM=active_record"
73
+
74
+ - rvm: 1.9.3
75
+ gemfile: gemfiles/mongoid-rails40.gemfile
76
+ env: "SORCERY_ORM=mongoid"
77
+
78
+ - rvm: 2.0.0
79
+ gemfile: gemfiles/mongoid-rails40.gemfile
80
+ env: "SORCERY_ORM=mongoid"
81
+
82
+ - rvm: 2.1
83
+ gemfile: gemfiles/mongoid-rails40.gemfile
84
+ env: "SORCERY_ORM=mongoid"
85
+
86
+ - rvm: jruby
87
+ gemfile: gemfiles/mongoid-rails40.gemfile
88
+ env: "SORCERY_ORM=mongoid"
89
+
90
+ - rvm: 1.9.3
91
+ gemfile: gemfiles/mongo_mapper-rails40.gemfile
92
+ env: "SORCERY_ORM=mongo_mapper"
93
+
94
+ - rvm: 2.0.0
95
+ gemfile: gemfiles/mongo_mapper-rails40.gemfile
96
+ env: "SORCERY_ORM=mongo_mapper"
97
+
98
+ - rvm: 2.1
99
+ gemfile: gemfiles/mongo_mapper-rails40.gemfile
100
+ env: "SORCERY_ORM=mongo_mapper"
101
+
102
+ - rvm: jruby
103
+ gemfile: gemfiles/mongo_mapper-rails40.gemfile
104
+ env: "SORCERY_ORM=mongo_mapper"
105
+
106
+ - rvm: 1.9.3
107
+ gemfile: gemfiles/active_record-rails40.gemfile
108
+ env: "SORCERY_ORM=active_record"
109
+
110
+ - rvm: 2.0.0
111
+ gemfile: gemfiles/active_record-rails40.gemfile
112
+ env: "SORCERY_ORM=active_record"
113
+
114
+ - rvm: 2.1
115
+ gemfile: gemfiles/active_record-rails40.gemfile
116
+ env: "SORCERY_ORM=active_record"
117
+
118
+ - rvm: jruby
119
+ gemfile: gemfiles/active_record-rails40.gemfile
120
+ env: "SORCERY_ORM=active_record"
121
+
122
+ - rvm: 1.9.3
123
+ gemfile: gemfiles/mongoid3-rails32.gemfile
124
+ env: "SORCERY_ORM=mongoid"
125
+
126
+ - rvm: 2.0.0
127
+ gemfile: gemfiles/mongoid3-rails32.gemfile
128
+ env: "SORCERY_ORM=mongoid"
129
+
130
+ - rvm: 2.1
131
+ gemfile: gemfiles/mongoid3-rails32.gemfile
132
+ env: "SORCERY_ORM=mongoid"
data/CHANGELOG.md CHANGED
@@ -1,6 +1,37 @@
1
1
  # Changelog
2
2
 
3
- ## 0.8.6 (not released)
3
+ ## 1.0 (not released yet)
4
+
5
+ * Adapters (Mongoid, MongoMapper, DataMapper) are now separated from the core Sorcery repo and moved under `sorcery-rails` organization. Special thanks to @juike!
6
+
7
+ ## 0.9.1
8
+
9
+ * Fixed fetching private emails from github (thanks to @saratovsource)
10
+ * Added support for `active_for_authentication?` method (thanks to @gchaincl)
11
+ * Fixed migration bug for `external` submodule (thanks to @skv-headless)
12
+ * Added support for new Facebook Graph API (thanks to @mchaisse)
13
+ * Fixed issue with Xing submodule (thanks to @yoyostile)
14
+ * Fixed security bug with using `state` field in oAuth requests
15
+
16
+ ## 0.9.0
17
+
18
+ * Sending emails works with Rails 4.2 (thanks to @wooly)
19
+ * Added `valid_password?` method
20
+ * Added support for JIRA OAuth (thanks to @camilasan)
21
+ * Added support for Heroku OAuth (thanks to @tyrauber)
22
+ * Added support for Salesforce OAuth (thanks to @supremebeing7)
23
+ * Added support for Mongoid 4
24
+ * Fixed issues with empty passwords (thanks to @Borzik)
25
+ * `find_by_provider_and_uid` method was replaced with `find_by_oauth_credentials`
26
+ * Sorcery::VERSION constant was added to allow easy version check
27
+ * `@user.setup_activation` method was made to be public (thanks @iTakeshi)
28
+ * `current_users` method is deprecated
29
+ * Fetching email from VK auth, thanks to @makaroni4
30
+ * Add logged_in? method to test_helpers (thanks to @oriolbcn)
31
+ * #locked? method is now public API (thanks @rogercampos)
32
+ * Introduces a new User instance method `generate_reset_password_token` to generate a new reset password token without sending an email (thanks to @tbuehl)
33
+
34
+ ## 0.8.6
4
35
 
5
36
  * `current_user` returns `nil` instead of `false` if there's no user loggd in (#493)
6
37
  * MongoMapper adapter does not override `save!` method anymore. However due to ORM's lack of support for `validate: false` in `save!`, the combination of `validate: false` and `raise_on_failure: true` is not possible in MongoMapper. The errors will not be raised in this situation. (#151)
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 3.2'
4
4
  gem 'sqlite3'
5
+ gem 'pry'
5
6
 
6
7
  group :mongomapper do
7
8
  gem 'mongo_mapper'
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  [![Build Status](https://travis-ci.org/NoamB/sorcery.svg?branch=master)](https://travis-ci.org/NoamB/sorcery)
2
2
  [![Code Climate](https://codeclimate.com/github/NoamB/sorcery.png)](https://codeclimate.com/github/NoamB/sorcery)
3
+ [![Inline docs](http://inch-ci.org/github/NoamB/sorcery.png?branch=master)](http://inch-ci.org/github/NoamB/sorcery)
3
4
 
4
5
  # sorcery
5
6
  Magical Authentication for Rails 3 and 4. Supports ActiveRecord,
@@ -9,9 +10,11 @@ Inspired by restful_authentication, Authlogic and Devise. Crypto code taken
9
10
  almost unchanged from Authlogic. OAuth code inspired by OmniAuth and Ryan
10
11
  Bates's railscasts about it.
11
12
 
12
- **Rails 4 status:** [Sorcery 0.8.5](http://rubygems.org/gems/sorcery/versions/0.8.5) is fully tested and ready for Rails 4.0.
13
+ **What's happening now?** We are working on 1.0 version, which will include some API-breaking changes. It should be released about April 2015.
14
+ Until then we'll continue releasing `0.9.x` version with bug fixed.
13
15
 
14
- **Rails 4.1 status:** Sorcery 0.8.6 (to be released, currently in master branch) works with Rails 4.1
16
+ **Rails 4 status:** [Sorcery 0.9.0](http://rubygems.org/gems/sorcery/versions/0.9.0) is fully tested and ready for Rails 4.0, 4.1 and 4.2.
17
+ **Mongoid status:** Version 0.9.0 works with Mongoid 4.
15
18
 
16
19
  https://github.com/NoamB/sorcery/wiki/Simple-Password-Authentication
17
20
 
@@ -33,94 +36,117 @@ can write your own authentication flow. It was built with a few goals in mind:
33
36
 
34
37
  Hopefully, I've achieved this. If not, let me know.
35
38
 
36
- ## Useful Links:
39
+ ## Useful Links
37
40
 
38
- Railscast: http://railscasts.com/episodes/283-authentication-with-sorcery
41
+ [Documentation](http://rubydoc.info/gems/sorcery) |
42
+ [Railscast](http://railscasts.com/episodes/283-authentication-with-sorcery) | [Simple tutorial](https://github.com/NoamB/sorcery/wiki/Simple-Password-Authentication) | [Example Rails 3 app](https://github.com/NoamB/sorcery-example-app)
39
43
 
40
- Example Rails 3 app using sorcery:
41
- https://github.com/NoamB/sorcery-example-app
42
-
43
- Documentation: http://rubydoc.info/gems/sorcery
44
-
45
- Check out the tutorials in the github wiki!
44
+ Check out the tutorials in the [Wiki](https://github.com/NoamB/sorcery/wiki) for more!
46
45
 
47
46
  ## API Summary
48
47
 
49
48
  Below is a summary of the library methods. Most method names are self
50
49
  explaining and the rest are commented:
51
50
 
52
- # core
53
- require_login # this is a before filter
54
- login(email, password, remember_me = false)
55
- auto_login(user)# login without credentials
56
- logout
57
- logged_in? # available to view
58
- current_user # available to view
59
- redirect_back_or_to # used when a user tries to access a page while logged out, is asked to login, and we want to return him back to the page he originally wanted.
60
- @user.external? # external users, such as facebook/twitter etc.
61
- User.authenticates_with_sorcery!
62
-
63
- # activity logging
64
- current_users
65
-
66
- # http basic auth
67
- require_login_from_http_basic # this is a before filter
68
-
69
- # external
70
- login_at(provider) # sends the user to an external service (twitter etc.) to authenticate.
71
- login_from(provider) # tries to login from the external provider's callback.
72
- create_from(provider) # create the user in the local app db.
73
-
74
- # remember me
75
- auto_login(user, should_remember=false) # login without credentials, optional remember_me
76
- remember_me!
77
- forget_me!
78
-
79
- # reset password
80
- User.load_from_reset_password_token(token)
81
- @user.deliver_reset_password_instructions!
82
- @user.change_password!(new_password)
83
-
84
- # user activation
85
- User.load_from_activation_token(token)
86
- @user.activate!
51
+
52
+ ### core
53
+ ```ruby
54
+ require_login # this is a before filter
55
+ login(email, password, remember_me = false)
56
+ auto_login(user)# login without credentials
57
+ logout
58
+ logged_in? # available to view
59
+ current_user # available to view
60
+ redirect_back_or_to # used when a user tries to access a page while logged out, is asked to login, and we want to return him back to the page he originally wanted.
61
+ @user.external? # external users, such as facebook/twitter etc.
62
+ @user.active_for_authentication? # add this method to define behaviour that will prevent selected users from signing in
63
+ User.authenticates_with_sorcery!
64
+ ```
65
+
66
+ ### http basic auth
67
+ ```ruby
68
+ require_login_from_http_basic # this is a before filter
69
+ ```
70
+
71
+ ### external
72
+ ```ruby
73
+ login_at(provider) # sends the user to an external service (twitter etc.) to authenticate.
74
+ login_from(provider) # tries to login from the external provider's callback.
75
+ create_from(provider) # create the user in the local app db.
76
+ ```
77
+
78
+ ### remember me
79
+ ```ruby
80
+ auto_login(user, should_remember=false) # login without credentials, optional remember_me
81
+ remember_me!
82
+ forget_me!
83
+ ```
84
+
85
+ ### reset password
86
+ ```ruby
87
+ User.load_from_reset_password_token(token)
88
+ @user.generate_reset_password_token! # if you want to send the email by youself
89
+ @user.deliver_reset_password_instructions! # generates the token and sends the email
90
+ @user.change_password!(new_password)
91
+ ```
92
+
93
+ ### user activation
94
+ ```ruby
95
+ User.load_from_activation_token(token)
96
+ @user.setup_activation
97
+ @user.activate!
98
+ ```
87
99
 
88
100
  Please see the tutorials in the github wiki for detailed usage information.
89
101
 
90
- ## Installation:
102
+ ## Installation
91
103
 
92
104
  If using bundler, first add 'sorcery' to your Gemfile:
93
105
 
94
- gem "sorcery"
106
+ ```ruby
107
+ gem "sorcery"
108
+ ```
95
109
 
96
110
  And run
97
111
 
98
- bundle install
112
+ ```ruby
113
+ bundle install
114
+ ```
99
115
 
100
116
  Otherwise simply
101
117
 
102
- gem install sorcery
118
+ ```ruby
119
+ gem install sorcery
120
+ ```
103
121
 
104
- ## Rails configuration:
122
+ ## Rails configuration
105
123
 
106
- rails generate sorcery:install
124
+ ```bash
125
+ rails generate sorcery:install
126
+ ```
107
127
 
108
128
  This will generate the core migration file, the initializer file and the
109
129
  'User' model class.
110
130
 
111
- rails generate sorcery:install remember_me reset_password
131
+ ```bash
132
+ rails generate sorcery:install remember_me reset_password
133
+ ```
112
134
 
113
135
  This will generate the migrations files for remember_me and reset_password
114
136
  submodules and will create the initializer file (and add submodules to it),
115
137
  and create the 'User' model class.
116
138
 
117
- rails generate sorcery:install --model Person
139
+ ```bash
140
+ rails generate sorcery:install --model Person
141
+ ```
118
142
 
119
143
  This will generate the core migration file, the initializer and change the
120
144
  model class (in the initializer and migration files) to the class 'Person'
121
145
  (and its pluralized version, 'people')
122
146
 
123
- rails generate sorcery:install http_basic_auth external remember_me --migrations
147
+ ```bash
148
+ rails generate sorcery:install http_basic_auth external remember_me --only-submodules
149
+ ```
124
150
 
125
151
  This will generate only the migration files for the specified submodules and
126
152
  will add them to the initializer file.
@@ -136,25 +162,29 @@ After implementing the `delayed_job` into your project add the code below at
136
162
  the end of the `config/initializers/sorcery.rb` file. After that all emails
137
163
  will be sent asynchronously.
138
164
 
139
- module Sorcery
140
- module Model
141
- module InstanceMethods
142
- def generic_send_email(method, mailer)
143
- config = sorcery_config
144
- mail = config.send(mailer).delay.send(config.send(method), self)
145
- end
146
- end
165
+ ```ruby
166
+ module Sorcery
167
+ module Model
168
+ module InstanceMethods
169
+ def generic_send_email(method, mailer)
170
+ config = sorcery_config
171
+ mail = config.send(mailer).delay.send(config.send(method), self)
147
172
  end
148
173
  end
174
+ end
175
+ end
176
+ ```
149
177
 
150
178
  Sidekiq and Resque integrations are coming soon.
151
179
 
152
180
  ## Single Table Inheritance (STI) Support
153
181
  STI is supported via a single setting in config/initializers/sorcery.rb.
154
182
 
155
- ## Full Features List by module:
183
+ ## Full Features List by module
184
+
185
+ **Core** (see [lib/sorcery/model.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model.rb) and
186
+ [lib/sorcery/controller.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller.rb)):
156
187
 
157
- Core (see lib/sorcery/model.rb and lib/sorcery/controller.rb):
158
188
  * login/logout, optional return user to requested url on login, configurable
159
189
  redirect for non-logged-in users.
160
190
  * password encryption, algorithms: bcrypt(default), md5, sha1, sha256,
@@ -163,7 +193,8 @@ Core (see lib/sorcery/model.rb and lib/sorcery/controller.rb):
163
193
  * allow multiple fields to serve as username.
164
194
 
165
195
 
166
- User Activation (see lib/sorcery/model/submodules/user_activation.rb):
196
+ **User Activation** (see [lib/sorcery/model/submodules/user_activation.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/user_activation.rb)):
197
+
167
198
  * User activation by email with optional success email.
168
199
  * configurable attribute names.
169
200
  * configurable mailer, method name, and attribute name.
@@ -171,37 +202,41 @@ User Activation (see lib/sorcery/model/submodules/user_activation.rb):
171
202
  * Optionally prevent non-active users to login.
172
203
 
173
204
 
174
- Reset Password (see lib/sorcery/model/submodules/reset_password.rb):
205
+ **Reset Password** (see [lib/sorcery/model/submodules/reset_password.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/reset_password.rb)):
206
+
175
207
  * Reset password with email verification.
176
208
  * configurable mailer, method name, and attribute name.
177
209
  * configurable temporary token expiration.
178
210
  * configurable time between emails (hammering protection).
179
211
 
180
212
 
181
- Remember Me (see lib/sorcery/model/submodules/remember_me.rb):
213
+ **Remember Me** (see [lib/sorcery/model/submodules/remember_me.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/remember_me.rb)):
214
+
182
215
  * Remember me with configurable expiration.
183
216
  * configurable attribute names.
184
217
 
185
218
 
186
- Session Timeout (see lib/sorcery/controller/submodules/session_timeout.rb):
219
+ **Session Timeout** (see [lib/sorcery/controller/submodules/session_timeout.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller/submodules/session_timeout.rb)):
220
+
187
221
  * Configurable session timeout.
188
222
  * Optionally session timeout will be calculated from last user action.
189
223
 
190
224
 
191
- Brute Force Protection (see
192
- lib/sorcery/model/submodules/brute_force_protection.rb):
225
+ **Brute Force Protection** (see [lib/sorcery/model/submodules/brute_force_protection.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/brute_force_protection.rb)):
226
+
193
227
  * Brute force login hammering protection.
194
228
  * configurable logins before lock and lock duration.
195
229
 
196
230
 
197
- Basic HTTP Authentication (see
198
- lib/sorcery/controller/submodules/http_basic_auth.rb):
231
+ **Basic HTTP Authentication** (see [lib/sorcery/controller/submodules/http_basic_auth.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller/submodules/http_basic_auth.rb)):
232
+
199
233
  * A before filter for requesting authentication with HTTP Basic.
200
234
  * automatic login from HTTP Basic.
201
235
  * automatic login is disabled if session key changed.
202
236
 
203
237
 
204
- Activity Logging (see lib/sorcery/model/submodules/activity_logging.rb):
238
+ **Activity Logging** (see [lib/sorcery/model/submodules/activity_logging.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/activity_logging.rb)):
239
+
205
240
  * automatic logging of last login, last logout, last activity time and IP
206
241
  address for last login.
207
242
  * an easy method of collecting the list of currently logged in users.
@@ -209,15 +244,17 @@ Activity Logging (see lib/sorcery/model/submodules/activity_logging.rb):
209
244
  list of logged in users.
210
245
 
211
246
 
212
- External (see lib/sorcery/controller/submodules/external.rb):
213
- * OAuth1 and OAuth2 support (currently: Twitter, Facebook, Github, Google,
214
- LinkedIn, VK, LiveID and Xing)
247
+ **External** (see [lib/sorcery/controller/submodules/external.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller/submodules/external.rb)):
248
+
249
+ * OAuth1 and OAuth2 support (currently: Twitter, Facebook, Github, Google, Heroku,
250
+ LinkedIn, VK, LiveID, Xing, and Salesforce)
215
251
  * configurable db field names and authentications table.
216
252
 
217
253
 
218
- ## Next Planned Features:
254
+ ## Next Planned Features
219
255
 
220
256
  I've got some thoughts which include (unordered):
257
+
221
258
  * Passing a block to encrypt, allowing the developer to define his own mix
222
259
  of salting and encrypting
223
260
  * Forgot username, maybe as part of the reset_password module
@@ -252,20 +289,26 @@ Important notes:
252
289
  * Usage: include DataMapper::Resource in user model, follow sorcery
253
290
  instructions (remember to add property id, validators and accessor
254
291
  attributes such as password and password_confirmation)
255
- * Option downcase__username_before_authenticating and dm-mysql,
292
+ * Option downcase__username_before_authenticating and dm-mysql,
256
293
  http://datamapper.lighthouseapp.com/projects/20609/tickets/1105-add-support-for-definingchanging-default-collation
257
294
 
258
295
  ## Upgrading
259
296
 
260
297
  Important notes while upgrading:
261
298
 
299
+ * If you are upgrading from <= **0.8.6** and you use Sorcery model methods in your app,
300
+ you might need to change them from `user.method` to `user.sorcery_adapter.method` and from
301
+ `User.method` to `User.sorcery_adapter_method`
302
+
262
303
  * If you are upgrading from <= **0.8.5** and you're using Sorcery test helpers,
263
304
  you need to change the way you include them to following code:
264
305
 
265
- RSpec.configure do |config|
266
- config.include Sorcery::TestHelpers::Rails::Controler, type: [:controller]
267
- config.include Sorcery::TestHelpers::Rails::Integration, type: [:feature]
268
- end
306
+ ```ruby
307
+ RSpec.configure do |config|
308
+ config.include Sorcery::TestHelpers::Rails::Controller, type: :controller
309
+ config.include Sorcery::TestHelpers::Rails::Integration, type: :feature
310
+ end
311
+ ```
269
312
 
270
313
  * If are upgrading to **0.8.2** and use activity_logging feature with
271
314
  ActiveRecord, you will have to add a new column
@@ -274,12 +317,15 @@ Important notes while upgrading:
274
317
  * Sinatra support existed until **v0.7.0** (including), but was dropped
275
318
  later due to being a maintenance nightmare.
276
319
  * If upgrading from <= **0.6.1 to >= **0.7.0** you need to change
277
- 'username_attribute_name' to 'username_attribute_names' in initializer.
320
+ 'username
321
+ _attribute_name' to 'username_attribute_names' in initializer.
278
322
  * If upgrading from <= **v0.5.1** to >= **v0.5.2** you need to explicitly
279
323
  set your user_class model in the initializer file.
280
324
 
281
- # This line must come after the 'user config' block.
282
- config.user_class = User
325
+ ```ruby
326
+ # This line must come after the 'user config' block.
327
+ config.user_class = User
328
+ ```
283
329
 
284
330
 
285
331
  ## Contributing to sorcery
@@ -314,7 +360,13 @@ email: shatrov@me.com
314
360
 
315
361
  twitter: @Kiiiir
316
362
 
363
+ #### Grzegorz Witek
364
+
365
+ email: arnvald.to@gmail.com
366
+
367
+ twitter: @arnvald
368
+
317
369
  ## Copyright
318
370
 
319
- Copyright (c) 2010 Noam Ben Ari (nbenari@gmail.com). See LICENSE.txt for
371
+ Copyright (c) 2010-2014 Noam Ben Ari (nbenari@gmail.com). See LICENSE.txt for
320
372
  further details.
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sqlite3', platform: :mri
4
+ gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
+ gem 'rails', '~> 4.0.1'
6
+
7
+ gemspec path: '..'
@@ -1,6 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'sqlite3'
4
- gem 'rails', '~> 4.1'
3
+ gem 'sqlite3', platform: :mri
4
+ gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
+ gem 'rails', '~> 4.1.0'
5
6
 
6
7
  gemspec path: '..'
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.0.0'
4
+
5
+ gem 'mongo_mapper', github: 'mongomapper/mongomapper'
6
+ gem 'sqlite3', platform: :mri
7
+ gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
8
+
9
+ gemspec path: '..'
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'rails', '~> 4.1.0'
4
4
 
5
5
  gem 'mongo_mapper', github: 'mongomapper/mongomapper'
6
- gem 'sqlite3'
6
+ gem 'sqlite3', platform: :mri
7
+ gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
7
8
 
8
9
  gemspec path: '..'
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.0.0'
4
+
5
+ gem 'mongoid', '~> 4.0.0'
6
+ gem 'sqlite3', platform: :mri
7
+ gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
8
+
9
+ gemspec path: '..'
@@ -2,10 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 4.1.0'
4
4
 
5
- gem 'pry'
6
-
7
- gem 'mongoid', github: 'mongoid/mongoid'
8
- gem 'bson_ext'
9
- gem 'sqlite3'
5
+ gem 'mongoid', '~> 4.0.0'
6
+ gem 'sqlite3', platform: :mri
7
+ gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
10
8
 
11
9
  gemspec path: '..'
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 3.2.0'
4
+
5
+ gem 'mongoid', '~> 3.0'
6
+ gem 'bson_ext'
7
+ gem 'sqlite3'
8
+
9
+ gemspec path: '..'
@@ -16,7 +16,7 @@ Examples:
16
16
  This will generate the core migration file, the initializer and change the model class
17
17
  (in the initializer and migration files) to the class 'Person' (and it's pluralized version, 'people')
18
18
 
19
- rails generate sorcery:install http_basic_auth external remember_me --migrations
19
+ rails generate sorcery:install http_basic_auth external remember_me --only-submodules
20
20
 
21
21
  This will generate only the migration files for the specified submodules and will
22
22
  add them to the initializer file.