authenticate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +21 -0
  6. data/Gemfile.lock +154 -0
  7. data/LICENSE +20 -0
  8. data/README.md +240 -0
  9. data/Rakefile +6 -0
  10. data/app/assets/config/authenticate_manifest.js +0 -0
  11. data/app/assets/images/authenticate/.keep +0 -0
  12. data/app/assets/javascripts/authenticate/.keep +0 -0
  13. data/app/assets/stylesheets/authenticate/.keep +0 -0
  14. data/app/controllers/.keep +0 -0
  15. data/app/helpers/.keep +0 -0
  16. data/app/mailers/.keep +0 -0
  17. data/app/models/.keep +0 -0
  18. data/app/views/.keep +0 -0
  19. data/authenticate.gemspec +38 -0
  20. data/bin/rails +12 -0
  21. data/config/routes.rb +2 -0
  22. data/lib/authenticate.rb +12 -0
  23. data/lib/authenticate/callbacks/authenticatable.rb +4 -0
  24. data/lib/authenticate/callbacks/brute_force.rb +31 -0
  25. data/lib/authenticate/callbacks/lifetimed.rb +5 -0
  26. data/lib/authenticate/callbacks/timeoutable.rb +15 -0
  27. data/lib/authenticate/callbacks/trackable.rb +8 -0
  28. data/lib/authenticate/configuration.rb +144 -0
  29. data/lib/authenticate/controller.rb +110 -0
  30. data/lib/authenticate/crypto/bcrypt.rb +30 -0
  31. data/lib/authenticate/debug.rb +10 -0
  32. data/lib/authenticate/engine.rb +21 -0
  33. data/lib/authenticate/lifecycle.rb +120 -0
  34. data/lib/authenticate/login_status.rb +27 -0
  35. data/lib/authenticate/model/brute_force.rb +51 -0
  36. data/lib/authenticate/model/db_password.rb +71 -0
  37. data/lib/authenticate/model/email.rb +76 -0
  38. data/lib/authenticate/model/lifetimed.rb +48 -0
  39. data/lib/authenticate/model/timeoutable.rb +47 -0
  40. data/lib/authenticate/model/trackable.rb +43 -0
  41. data/lib/authenticate/model/username.rb +45 -0
  42. data/lib/authenticate/modules.rb +61 -0
  43. data/lib/authenticate/session.rb +123 -0
  44. data/lib/authenticate/token.rb +7 -0
  45. data/lib/authenticate/user.rb +50 -0
  46. data/lib/authenticate/version.rb +3 -0
  47. data/lib/tasks/authenticate_tasks.rake +4 -0
  48. data/spec/configuration_spec.rb +60 -0
  49. data/spec/dummy/README.rdoc +28 -0
  50. data/spec/dummy/Rakefile +6 -0
  51. data/spec/dummy/app/assets/images/.keep +0 -0
  52. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  53. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  54. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  55. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  56. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  57. data/spec/dummy/app/mailers/.keep +0 -0
  58. data/spec/dummy/app/models/.keep +0 -0
  59. data/spec/dummy/app/models/concerns/.keep +0 -0
  60. data/spec/dummy/app/models/user.rb +3 -0
  61. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  62. data/spec/dummy/bin/bundle +3 -0
  63. data/spec/dummy/bin/rails +4 -0
  64. data/spec/dummy/bin/rake +4 -0
  65. data/spec/dummy/bin/setup +29 -0
  66. data/spec/dummy/config.ru +4 -0
  67. data/spec/dummy/config/application.rb +26 -0
  68. data/spec/dummy/config/boot.rb +5 -0
  69. data/spec/dummy/config/database.yml +25 -0
  70. data/spec/dummy/config/environment.rb +5 -0
  71. data/spec/dummy/config/environments/development.rb +41 -0
  72. data/spec/dummy/config/environments/production.rb +79 -0
  73. data/spec/dummy/config/environments/test.rb +42 -0
  74. data/spec/dummy/config/initializers/assets.rb +11 -0
  75. data/spec/dummy/config/initializers/authenticate.rb +7 -0
  76. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  77. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  78. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  79. data/spec/dummy/config/initializers/inflections.rb +16 -0
  80. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  81. data/spec/dummy/config/initializers/session_store.rb +3 -0
  82. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  83. data/spec/dummy/config/locales/en.yml +23 -0
  84. data/spec/dummy/config/routes.rb +56 -0
  85. data/spec/dummy/config/secrets.yml +22 -0
  86. data/spec/dummy/db/development.sqlite3 +0 -0
  87. data/spec/dummy/db/migrate/20160120003910_create_users.rb +18 -0
  88. data/spec/dummy/db/schema.rb +31 -0
  89. data/spec/dummy/db/test.sqlite3 +0 -0
  90. data/spec/dummy/lib/assets/.keep +0 -0
  91. data/spec/dummy/log/.keep +0 -0
  92. data/spec/dummy/public/404.html +67 -0
  93. data/spec/dummy/public/422.html +67 -0
  94. data/spec/dummy/public/500.html +66 -0
  95. data/spec/dummy/public/favicon.ico +0 -0
  96. data/spec/factories/users.rb +23 -0
  97. data/spec/model/session_spec.rb +86 -0
  98. data/spec/model/token_spec.rb +11 -0
  99. data/spec/model/user_spec.rb +12 -0
  100. data/spec/orm/active_record.rb +17 -0
  101. data/spec/spec_helper.rb +148 -0
  102. metadata +255 -0
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Authenticate::Token do
4
+ it 'is a random hex string' do
5
+ token = 'my_token'
6
+ allow(SecureRandom).to receive(:hex).with(20).and_return(token)
7
+
8
+ expect(Authenticate::Token.new).to eq token
9
+ end
10
+
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Authenticate::User do
4
+
5
+ it 'generates a new session token' do
6
+ user = create(:user, :with_session_token)
7
+ old_token = user.session_token
8
+ user.generate_session_token
9
+ expect(user.session_token).to_not eq old_token
10
+ end
11
+
12
+ end
@@ -0,0 +1,17 @@
1
+ require 'authenticate'
2
+
3
+ ActiveRecord::Migration.verbose = false
4
+ # ActiveRecord::Base.logger = Logger.new(nil)
5
+ # ActiveRecord::Base.include_root_in_json = true
6
+
7
+ def setup_orm
8
+ ActiveRecord::Migrator.migrate(migrations_path)
9
+ end
10
+
11
+ def teardown_orm
12
+ ActiveRecord::Migrator.rollback(migrations_path)
13
+ end
14
+
15
+ def migrations_path
16
+ Rails.root.join("db", "migrate", "core")
17
+ end
@@ -0,0 +1,148 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+
5
+ ENV["RAILS_ENV"] ||= 'test'
6
+
7
+ MY_ORM = :active_record
8
+
9
+ # require 'simplecov'
10
+ # SimpleCov.root File.join(File.dirname(__FILE__), '..', 'lib')
11
+ # SimpleCov.start
12
+
13
+
14
+ require 'rails/all'
15
+ # require 'rspec'
16
+ require 'rspec/rails'
17
+ require 'factory_girl_rails'
18
+ # require 'timecop'
19
+
20
+ ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
21
+ Dir[File.join(ENGINE_RAILS_ROOT, "spec/factories/**/*.rb")].each {|f| require f }
22
+
23
+ def setup_orm; end
24
+ def teardown_orm; end
25
+
26
+ require "orm/#{MY_ORM}"
27
+
28
+ # require "rails_app/config/environment"
29
+ require "dummy/config/environment"
30
+
31
+ # class TestMailer < ActionMailer::Base;end
32
+
33
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
34
+
35
+ RSpec.configure do |config|
36
+ config.fixture_path = "#{::Rails.root}/spec/factories"
37
+
38
+ config.include RSpec::Rails::ControllerExampleGroup, :file_path => /controller(.)*_spec.rb$/
39
+ config.mock_with :rspec
40
+ config.include FactoryGirl::Syntax::Methods
41
+
42
+ config.use_transactional_fixtures = true
43
+
44
+ config.before(:suite) { setup_orm }
45
+ config.after(:suite) { teardown_orm }
46
+ config.before(:each) { ActionMailer::Base.deliveries.clear }
47
+ end
48
+
49
+
50
+ def restore_default_configuration
51
+ Authenticate.configuration = nil
52
+ Authenticate.configure {}
53
+ end
54
+
55
+
56
+
57
+ # # This file was generated by the `rails generate rspec:install` command. Conventionally, all
58
+ # # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
59
+ # # The generated `.rspec` file contains `--require spec_helper` which will cause
60
+ # # this file to always be loaded, without a need to explicitly require it in any
61
+ # # files.
62
+ # #
63
+ # # Given that it is always loaded, you are encouraged to keep this file as
64
+ # # light-weight as possible. Requiring heavyweight dependencies from this file
65
+ # # will add to the boot time of your test suite on EVERY test run, even for an
66
+ # # individual file that may not need all of that loaded. Instead, consider making
67
+ # # a separate helper file that requires the additional dependencies and performs
68
+ # # the additional setup, and require it from the spec files that actually need
69
+ # # it.
70
+ # #
71
+ # # The `.rspec` file also contains a few flags that are not defaults but that
72
+ # # users commonly want.
73
+ # #
74
+ # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
75
+ # RSpec.configure do |config|
76
+ # # rspec-expectations config goes here. You can use an alternate
77
+ # # assertion/expectation library such as wrong or the stdlib/minitest
78
+ # # assertions if you prefer.
79
+ # config.expect_with :rspec do |expectations|
80
+ # # This option will default to `true` in RSpec 4. It makes the `description`
81
+ # # and `failure_message` of custom matchers include text for helper methods
82
+ # # defined using `chain`, e.g.:
83
+ # # be_bigger_than(2).and_smaller_than(4).description
84
+ # # # => "be bigger than 2 and smaller than 4"
85
+ # # ...rather than:
86
+ # # # => "be bigger than 2"
87
+ # expectations.include_chain_clauses_in_custom_matcher_descriptions = true
88
+ # end
89
+ #
90
+ # # rspec-mocks config goes here. You can use an alternate test double
91
+ # # library (such as bogus or mocha) by changing the `mock_with` option here.
92
+ # config.mock_with :rspec do |mocks|
93
+ # # Prevents you from mocking or stubbing a method that does not exist on
94
+ # # a real object. This is generally recommended, and will default to
95
+ # # `true` in RSpec 4.
96
+ # mocks.verify_partial_doubles = true
97
+ # end
98
+ #
99
+ # # The settings below are suggested to provide a good initial experience
100
+ # # with RSpec, but feel free to customize to your heart's content.
101
+ # =begin
102
+ # # These two settings work together to allow you to limit a spec run
103
+ # # to individual examples or groups you care about by tagging them with
104
+ # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
105
+ # # get run.
106
+ # config.filter_run :focus
107
+ # config.run_all_when_everything_filtered = true
108
+ #
109
+ # # Allows RSpec to persist some state between runs in order to support
110
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
111
+ # # you configure your source control system to ignore this file.
112
+ # config.example_status_persistence_file_path = "spec/examples.txt"
113
+ #
114
+ # # Limits the available syntax to the non-monkey patched syntax that is
115
+ # # recommended. For more details, see:
116
+ # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
117
+ # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
118
+ # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
119
+ # config.disable_monkey_patching!
120
+ #
121
+ # # Many RSpec users commonly either run the entire suite or an individual
122
+ # # file, and it's useful to allow more verbose output when running an
123
+ # # individual spec file.
124
+ # if config.files_to_run.one?
125
+ # # Use the documentation formatter for detailed output,
126
+ # # unless a formatter has already been configured
127
+ # # (e.g. via a command-line flag).
128
+ # config.default_formatter = 'doc'
129
+ # end
130
+ #
131
+ # # Print the 10 slowest examples and example groups at the
132
+ # # end of the spec run, to help surface which specs are running
133
+ # # particularly slow.
134
+ # config.profile_examples = 10
135
+ #
136
+ # # Run specs in random order to surface order dependencies. If you find an
137
+ # # order dependency and want to debug it, you can fix the order by providing
138
+ # # the seed, which is printed after each run.
139
+ # # --seed 1234
140
+ # config.order = :random
141
+ #
142
+ # # Seed global randomization in this process using the `--seed` CLI option.
143
+ # # Setting this allows you to use `--seed` to deterministically reproduce
144
+ # # test failures related to randomization by passing the same `--seed` value
145
+ # # as the one that triggered the failure.
146
+ # Kernel.srand config.seed
147
+ # =end
148
+ # end
metadata ADDED
@@ -0,0 +1,255 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: authenticate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Tomich
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bcrypt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: email_validator
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '5.1'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '4.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '5.1'
61
+ - !ruby/object:Gem::Dependency
62
+ name: sqlite3
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec-rails
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: factory_girl_rails
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ description: Rails authentication with email & password
118
+ email:
119
+ - justin@tomich.org
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files:
123
+ - LICENSE
124
+ - README.md
125
+ files:
126
+ - ".gitignore"
127
+ - ".rspec"
128
+ - ".ruby-version"
129
+ - Gemfile
130
+ - Gemfile.lock
131
+ - LICENSE
132
+ - README.md
133
+ - Rakefile
134
+ - app/assets/config/authenticate_manifest.js
135
+ - app/assets/images/authenticate/.keep
136
+ - app/assets/javascripts/authenticate/.keep
137
+ - app/assets/stylesheets/authenticate/.keep
138
+ - app/controllers/.keep
139
+ - app/helpers/.keep
140
+ - app/mailers/.keep
141
+ - app/models/.keep
142
+ - app/views/.keep
143
+ - authenticate.gemspec
144
+ - bin/rails
145
+ - config/routes.rb
146
+ - lib/authenticate.rb
147
+ - lib/authenticate/callbacks/authenticatable.rb
148
+ - lib/authenticate/callbacks/brute_force.rb
149
+ - lib/authenticate/callbacks/lifetimed.rb
150
+ - lib/authenticate/callbacks/timeoutable.rb
151
+ - lib/authenticate/callbacks/trackable.rb
152
+ - lib/authenticate/configuration.rb
153
+ - lib/authenticate/controller.rb
154
+ - lib/authenticate/crypto/bcrypt.rb
155
+ - lib/authenticate/debug.rb
156
+ - lib/authenticate/engine.rb
157
+ - lib/authenticate/lifecycle.rb
158
+ - lib/authenticate/login_status.rb
159
+ - lib/authenticate/model/brute_force.rb
160
+ - lib/authenticate/model/db_password.rb
161
+ - lib/authenticate/model/email.rb
162
+ - lib/authenticate/model/lifetimed.rb
163
+ - lib/authenticate/model/timeoutable.rb
164
+ - lib/authenticate/model/trackable.rb
165
+ - lib/authenticate/model/username.rb
166
+ - lib/authenticate/modules.rb
167
+ - lib/authenticate/session.rb
168
+ - lib/authenticate/token.rb
169
+ - lib/authenticate/user.rb
170
+ - lib/authenticate/version.rb
171
+ - lib/tasks/authenticate_tasks.rake
172
+ - spec/configuration_spec.rb
173
+ - spec/dummy/README.rdoc
174
+ - spec/dummy/Rakefile
175
+ - spec/dummy/app/assets/images/.keep
176
+ - spec/dummy/app/assets/javascripts/application.js
177
+ - spec/dummy/app/assets/stylesheets/application.css
178
+ - spec/dummy/app/controllers/application_controller.rb
179
+ - spec/dummy/app/controllers/concerns/.keep
180
+ - spec/dummy/app/helpers/application_helper.rb
181
+ - spec/dummy/app/mailers/.keep
182
+ - spec/dummy/app/models/.keep
183
+ - spec/dummy/app/models/concerns/.keep
184
+ - spec/dummy/app/models/user.rb
185
+ - spec/dummy/app/views/layouts/application.html.erb
186
+ - spec/dummy/bin/bundle
187
+ - spec/dummy/bin/rails
188
+ - spec/dummy/bin/rake
189
+ - spec/dummy/bin/setup
190
+ - spec/dummy/config.ru
191
+ - spec/dummy/config/application.rb
192
+ - spec/dummy/config/boot.rb
193
+ - spec/dummy/config/database.yml
194
+ - spec/dummy/config/environment.rb
195
+ - spec/dummy/config/environments/development.rb
196
+ - spec/dummy/config/environments/production.rb
197
+ - spec/dummy/config/environments/test.rb
198
+ - spec/dummy/config/initializers/assets.rb
199
+ - spec/dummy/config/initializers/authenticate.rb
200
+ - spec/dummy/config/initializers/backtrace_silencers.rb
201
+ - spec/dummy/config/initializers/cookies_serializer.rb
202
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
203
+ - spec/dummy/config/initializers/inflections.rb
204
+ - spec/dummy/config/initializers/mime_types.rb
205
+ - spec/dummy/config/initializers/session_store.rb
206
+ - spec/dummy/config/initializers/wrap_parameters.rb
207
+ - spec/dummy/config/locales/en.yml
208
+ - spec/dummy/config/routes.rb
209
+ - spec/dummy/config/secrets.yml
210
+ - spec/dummy/db/development.sqlite3
211
+ - spec/dummy/db/migrate/20160120003910_create_users.rb
212
+ - spec/dummy/db/schema.rb
213
+ - spec/dummy/db/test.sqlite3
214
+ - spec/dummy/lib/assets/.keep
215
+ - spec/dummy/log/.keep
216
+ - spec/dummy/public/404.html
217
+ - spec/dummy/public/422.html
218
+ - spec/dummy/public/500.html
219
+ - spec/dummy/public/favicon.ico
220
+ - spec/factories/users.rb
221
+ - spec/model/session_spec.rb
222
+ - spec/model/token_spec.rb
223
+ - spec/model/user_spec.rb
224
+ - spec/orm/active_record.rb
225
+ - spec/spec_helper.rb
226
+ homepage: http://github.com/tomichj/authenticate
227
+ licenses:
228
+ - MIT
229
+ metadata: {}
230
+ post_install_message:
231
+ rdoc_options:
232
+ - "--charset=UTF-8"
233
+ require_paths:
234
+ - lib
235
+ required_ruby_version: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - ">="
238
+ - !ruby/object:Gem::Version
239
+ version: '2.0'
240
+ required_rubygems_version: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - ">="
243
+ - !ruby/object:Gem::Version
244
+ version: '0'
245
+ requirements: []
246
+ rubyforge_project:
247
+ rubygems_version: 2.5.1
248
+ signing_key:
249
+ specification_version: 4
250
+ summary: Rails authentication with email & password
251
+ test_files:
252
+ - spec/configuration_spec.rb
253
+ - spec/model/session_spec.rb
254
+ - spec/model/token_spec.rb
255
+ - spec/model/user_spec.rb