simple_auth 1.5.0 → 2.0.0

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -1
  3. data/.travis.yml +11 -0
  4. data/CHANGELOG.md +5 -0
  5. data/Gemfile +0 -2
  6. data/Gemfile.lock +102 -79
  7. data/README.md +243 -0
  8. data/Rakefile +15 -0
  9. data/gemfiles/rails_3_1.gemfile +5 -0
  10. data/gemfiles/rails_3_1.gemfile.lock +151 -0
  11. data/gemfiles/rails_3_2.gemfile +5 -0
  12. data/gemfiles/rails_3_2.gemfile.lock +149 -0
  13. data/gemfiles/rails_4_0.gemfile +4 -0
  14. data/gemfiles/rails_4_0.gemfile.lock +140 -0
  15. data/gemfiles/rails_4_1.gemfile +4 -0
  16. data/gemfiles/rails_4_1.gemfile.lock +146 -0
  17. data/lib/simple_auth.rb +1 -6
  18. data/lib/simple_auth/action_controller.rb +14 -10
  19. data/lib/simple_auth/active_record.rb +86 -0
  20. data/lib/simple_auth/compat.rb +2 -0
  21. data/lib/simple_auth/compat/active_record.rb +31 -0
  22. data/lib/simple_auth/compat/config.rb +17 -0
  23. data/lib/simple_auth/config.rb +0 -20
  24. data/lib/simple_auth/exceptions.rb +0 -1
  25. data/lib/simple_auth/railtie.rb +1 -1
  26. data/lib/simple_auth/rspec.rb +2 -2
  27. data/lib/simple_auth/session.rb +1 -1
  28. data/lib/simple_auth/version.rb +2 -2
  29. data/simple_auth.gemspec +4 -4
  30. data/spec/controllers/redirect_logged_user_spec.rb +16 -16
  31. data/spec/controllers/require_logged_user_spec.rb +34 -34
  32. data/spec/schema.rb +5 -1
  33. data/spec/simple_auth/active_record_spec.rb +104 -2
  34. data/spec/simple_auth/compat_spec.rb +31 -0
  35. data/spec/simple_auth/config_spec.rb +8 -27
  36. data/spec/simple_auth/helper_spec.rb +7 -7
  37. data/spec/simple_auth/session_spec.rb +76 -76
  38. data/spec/spec_helper.rb +2 -168
  39. data/spec/support/app/models/customer.rb +3 -0
  40. data/templates/initializer.rb +0 -8
  41. metadata +62 -33
  42. data/README.markdown +0 -202
  43. data/lib/simple_auth/orm/active_record.rb +0 -80
  44. data/lib/simple_auth/orm/base.rb +0 -89
  45. data/lib/simple_auth/orm/mongo_mapper.rb +0 -62
  46. data/spec/simple_auth/mongo_mapper_spec.rb +0 -10
  47. data/spec/support/app/models/account.rb +0 -6
@@ -0,0 +1,3 @@
1
+ class Customer < ActiveRecord::Base
2
+ authentication
3
+ end
@@ -1,13 +1,5 @@
1
1
  # Use this file to setup SimpleAuth.
2
2
  SimpleAuth.setup do |config|
3
- # Generate the password hash. The specified block should expected
4
- # the plain password and the password hash as block parameters.
5
- # config.crypter = proc {|password, salt| Digest::SHA256.hexdigest("#{password}--#{salt}") }
6
-
7
- # Generate the password salt. The specified block should expect
8
- # the ActiveRecord instance as block parameter.
9
- # config.salt = proc {|r| Digest::SHA256.hexdigest("#{Time.now.to_s}--#{r.email}")}
10
-
11
3
  # Set which attributes will be used for authentication.
12
4
  config.credentials = [:email, :login]
13
5
 
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-04 00:00:00.000000000 Z
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
20
- type: :development
19
+ version: 3.1.0
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.0
26
+ version: 3.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sqlite3-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 3.0.0.beta2
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 3.0.0.beta2
55
55
  - !ruby/object:Gem::Dependency
56
- name: mongo_mapper
56
+ name: bcrypt
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 3.1.7
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 3.1.7
69
69
  - !ruby/object:Gem::Dependency
70
- name: bson_ext
70
+ name: pry-meta
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: A simple authentication system for Rails apps
@@ -87,21 +87,32 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .rspec
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CHANGELOG.md
92
94
  - Gemfile
93
95
  - Gemfile.lock
94
- - README.markdown
96
+ - README.md
95
97
  - Rakefile
98
+ - gemfiles/rails_3_1.gemfile
99
+ - gemfiles/rails_3_1.gemfile.lock
100
+ - gemfiles/rails_3_2.gemfile
101
+ - gemfiles/rails_3_2.gemfile.lock
102
+ - gemfiles/rails_4_0.gemfile
103
+ - gemfiles/rails_4_0.gemfile.lock
104
+ - gemfiles/rails_4_1.gemfile
105
+ - gemfiles/rails_4_1.gemfile.lock
96
106
  - lib/simple_auth.rb
97
107
  - lib/simple_auth/action_controller.rb
108
+ - lib/simple_auth/active_record.rb
109
+ - lib/simple_auth/compat.rb
110
+ - lib/simple_auth/compat/active_record.rb
111
+ - lib/simple_auth/compat/config.rb
98
112
  - lib/simple_auth/config.rb
99
113
  - lib/simple_auth/exceptions.rb
100
114
  - lib/simple_auth/generator.rb
101
115
  - lib/simple_auth/helper.rb
102
- - lib/simple_auth/orm/active_record.rb
103
- - lib/simple_auth/orm/base.rb
104
- - lib/simple_auth/orm/mongo_mapper.rb
105
116
  - lib/simple_auth/railtie.rb
106
117
  - lib/simple_auth/rspec.rb
107
118
  - lib/simple_auth/session.rb
@@ -113,14 +124,14 @@ files:
113
124
  - spec/controllers/require_logged_user_spec.rb
114
125
  - spec/schema.rb
115
126
  - spec/simple_auth/active_record_spec.rb
127
+ - spec/simple_auth/compat_spec.rb
116
128
  - spec/simple_auth/config_spec.rb
117
129
  - spec/simple_auth/helper_spec.rb
118
130
  - spec/simple_auth/initializer_spec.rb
119
- - spec/simple_auth/mongo_mapper_spec.rb
120
131
  - spec/simple_auth/session_spec.rb
121
132
  - spec/spec_helper.rb
122
133
  - spec/support/app/controllers/application_controller.rb
123
- - spec/support/app/models/account.rb
134
+ - spec/support/app/models/customer.rb
124
135
  - spec/support/app/models/user.rb
125
136
  - spec/support/app/views/dashboard/index.erb
126
137
  - spec/support/app/views/session/new.erb
@@ -137,18 +148,36 @@ require_paths:
137
148
  - lib
138
149
  required_ruby_version: !ruby/object:Gem::Requirement
139
150
  requirements:
140
- - - '>='
151
+ - - ">="
141
152
  - !ruby/object:Gem::Version
142
153
  version: '0'
143
154
  required_rubygems_version: !ruby/object:Gem::Requirement
144
155
  requirements:
145
- - - '>='
156
+ - - ">="
146
157
  - !ruby/object:Gem::Version
147
158
  version: '0'
148
159
  requirements: []
149
160
  rubyforge_project:
150
- rubygems_version: 2.0.3
161
+ rubygems_version: 2.2.2
151
162
  signing_key:
152
163
  specification_version: 4
153
164
  summary: A simple authentication system for Rails apps
154
- test_files: []
165
+ test_files:
166
+ - spec/controllers/redirect_logged_user_spec.rb
167
+ - spec/controllers/require_logged_user_spec.rb
168
+ - spec/schema.rb
169
+ - spec/simple_auth/active_record_spec.rb
170
+ - spec/simple_auth/compat_spec.rb
171
+ - spec/simple_auth/config_spec.rb
172
+ - spec/simple_auth/helper_spec.rb
173
+ - spec/simple_auth/initializer_spec.rb
174
+ - spec/simple_auth/session_spec.rb
175
+ - spec/spec_helper.rb
176
+ - spec/support/app/controllers/application_controller.rb
177
+ - spec/support/app/models/customer.rb
178
+ - spec/support/app/models/user.rb
179
+ - spec/support/app/views/dashboard/index.erb
180
+ - spec/support/app/views/session/new.erb
181
+ - spec/support/config/boot.rb
182
+ - spec/support/config/database.yml
183
+ - spec/support/config/routes.rb
data/README.markdown DELETED
@@ -1,202 +0,0 @@
1
- Simple Auth
2
- ===========
3
-
4
- SimpleAuth is an authentication library to be used when Authlogic & Devise are just too complicated.
5
-
6
- This library only supports in-site authentication and won't implement OpenID, Facebook Connect and like. Rails 3.0+ required.
7
-
8
- Installation
9
- ------------
10
-
11
- sudo gem install simple_auth
12
-
13
- Then run `rails generate simple_auth:install` to copy the initializer file.
14
-
15
- Usage
16
- -----
17
-
18
- Your user model should have the attributes `password_hash` and `password_salt`. The credential field can be anything you want, but SimpleAuth uses `[:email, :login]` by default.
19
-
20
- class CreateUsers < ActiveRecord::Migration
21
- def self.up
22
- create_table :users do |t|
23
- t.string :email
24
- t.string :login
25
- t.string :password_hash
26
- t.string :password_salt
27
-
28
- t.timestamps
29
- end
30
-
31
- add_index :users, :email
32
- add_index :users, :login
33
- add_index :users, [:email, :login]
34
- end
35
-
36
- def self.down
37
- drop_table :users
38
- end
39
- end
40
-
41
- In your model, use the `authentication` macro.
42
-
43
- class User < ActiveRecord::Base
44
- authentication
45
- end
46
-
47
- This will add some callbacks and password validations. It will also inject helper methods like `Model.authenticate`.
48
-
49
- Session is valid only when both `Model#authorized?` and `Controller#authorized?` methods return `true`, which is the default behavior. You can override these methods with your own rules:
50
-
51
- class User < ActiveRecord::Base
52
- authentication
53
-
54
- def authorized?
55
- deleted_at.nil?
56
- end
57
- end
58
-
59
- class Admin::DashboardController < ApplicationController
60
- private
61
- def authorized?
62
- current_user.admin?
63
- end
64
- end
65
-
66
- After you set up the model, you can go to the controller.
67
-
68
- class SessionsController < ApplicationController
69
- def new
70
- @user_session = SimpleAuth::Session.new
71
- end
72
-
73
- def create
74
- @user_session = SimpleAuth::Session.new(params[:session])
75
-
76
- if @user_session.save
77
- redirect_to return_to(dashboard_path)
78
- else
79
- flash[:alert] = "Invalid username or password"
80
- render :new
81
- end
82
- end
83
-
84
- def destroy
85
- current_session.destroy if logged_in?
86
- redirect_to root_path
87
- end
88
- end
89
-
90
- The `return_to` helper will give you the requested url (before the user logged in) or the default url.
91
-
92
- You can restrict access by using 2 macros:
93
-
94
- class SignupController < ApplicationController
95
- redirect_logged_user :to => "/"
96
- end
97
-
98
- Here's some usage examples:
99
-
100
- redirect_logged_user :to => proc { login_path }
101
- redirect_logged_user :to => {:controller => "dashboard"}
102
- redirect_logged_user :only => [:index], :to => login_path
103
- redirect_logged_user :except => [:public], :to => login_path
104
-
105
- You can skip the `:to` option if you set it globally on your initializer:
106
-
107
- SimpleAuth::Config.logged_url = {:controller => "session", :action => "new"}
108
- SimpleAuth::Config.logged_url = proc { login_path }
109
-
110
- To require a logged user, use the `require_logged_user` macro:
111
-
112
- class DashboardController < ApplicationController
113
- require_logged_user :to => proc { login_path }
114
- end
115
-
116
- Here's some usage examples:
117
-
118
- require_logged_user :to => proc { login_path }
119
- require_logged_user :to => {:controller => "session", :action => "new"}
120
- require_logged_user :only => [:index], :to => login_path
121
- require_logged_user :except => [:public], :to => login_path
122
-
123
- You can skip the `:to` option if you set it globally on your initializer:
124
-
125
- SimpleAuth::Config.login_url = {:controller => "session", :action => "new"}
126
- SimpleAuth::Config.login_url = proc { login_path }
127
-
128
- There are some helpers:
129
-
130
- logged_in? # controller & views
131
- current_user # controller & views
132
- current_session # controller & views
133
- when_logged(&block) # views
134
- find_by_credential # model
135
- find_by_credential! # model
136
-
137
- If you're having problems to use any helper, include the module `SimpleAuth::Helper` on your `ApplicationHelper`.
138
-
139
- module ApplicationHelper
140
- include SimpleAuth::Helper
141
- end
142
-
143
- ### MongoMapper support
144
-
145
- You can use SimpleAuth with MongoMapper. Just include the module `SimpleAuth::Orm::MongoMapper` and
146
- set up your model with the `authentication` macro.
147
-
148
- class User
149
- include MongoMapper::Document
150
- include SimpleAuth::Orm::MongoMapper
151
-
152
- authentication
153
- end
154
-
155
- ### Translations
156
-
157
- These are the translations you'll need:
158
-
159
- en:
160
- simple_auth:
161
- sessions:
162
- need_to_be_logged: "You need to be logged"
163
- invalid_credentials: "Invalid username or password"
164
-
165
- Troubleshooting
166
- ---------------
167
-
168
- You may receive strange errors related to `can't dup NilClass` or `You have a nil object when you didn't expect it!`. This will occur only on development mode and is an ActiveRecord bug that hasn't been fixed. Open the ActiveRecord file `activerecord-2.3.5/lib/active_record/base.rb` and comment the lines 411-412:
169
-
170
- klass.instance_variables.each { |var| klass.send(:remove_instance_variable, var) }
171
- klass.instance_methods(false).each { |m| klass.send :undef_method, m }
172
-
173
- Dirty, but it works. Here's the ticket for this issue: [Issue #1290](https://rails.lighthouseapp.com/projects/8994/tickets/1290-activerecord-raises-randomly-apparently-a-timezone-issue#ticket-1290-30)
174
-
175
- Maintainer
176
- ----------
177
-
178
- * Nando Vieira (<http://simplesideias.com.br>)
179
-
180
- License:
181
- --------
182
-
183
- (The MIT License)
184
-
185
- Permission is hereby granted, free of charge, to any person obtaining
186
- a copy of this software and associated documentation files (the
187
- 'Software'), to deal in the Software without restriction, including
188
- without limitation the rights to use, copy, modify, merge, publish,
189
- distribute, sublicense, and/or sell copies of the Software, and to
190
- permit persons to whom the Software is furnished to do so, subject to
191
- the following conditions:
192
-
193
- The above copyright notice and this permission notice shall be
194
- included in all copies or substantial portions of the Software.
195
-
196
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
197
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
198
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
199
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
200
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
201
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
202
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,80 +0,0 @@
1
- module SimpleAuth
2
- module Orm
3
- module ActiveRecord
4
- def self.included(base)
5
- base.class_eval { extend Macro }
6
- end
7
-
8
- module Macro
9
- # Set virtual attributes, callbacks and validations.
10
- # Is called automatically after setting up configuration with
11
- # `SimpleAuth.setup {|config| config.model = :user}`.
12
- #
13
- # class User < ActiveRecord::Base
14
- # authentication
15
- # end
16
- #
17
- # Can set configuration when a block is provided.
18
- #
19
- # class User < ActiveRecord::Base
20
- # authentication do |config|
21
- # config.credentials = ["email"]
22
- # end
23
- # end
24
- #
25
- def authentication(&block)
26
- SimpleAuth.setup(&block) if block_given?
27
- SimpleAuth::Config.model ||= name.underscore.to_sym
28
-
29
- return if respond_to?(:authenticate)
30
-
31
- attr_reader :password
32
- attr_accessor :password_confirmation
33
-
34
- include SimpleAuth::Orm::Base::InstanceMethods
35
- extend SimpleAuth::Orm::Base::ClassMethods
36
- extend SimpleAuth::Orm::ActiveRecord::ClassMethods
37
-
38
- before_save :encrypt_password, :if => :validate_password?
39
- after_save :erase_password
40
-
41
- validates_presence_of :password, :if => :validate_password?
42
- validates_length_of :password, :if => :validate_password?, :minimum => 4, :allow_blank => true
43
- validates_presence_of :password_confirmation, :if => :validate_password?
44
- validates_confirmation_of :password, :if => :validate_password?
45
- end
46
- end
47
-
48
- module ClassMethods
49
- # Find user by its credential.
50
- #
51
- # User.find_by_credential "john@doe.com" # using e-mail
52
- # User.find_by_credential "john" # using username
53
- #
54
- def find_by_credential(credential)
55
- # Collect each attribute that should be used as credential.
56
- query = SimpleAuth::Config.credentials.each_with_object([]) do |attr_name, buffer|
57
- buffer << "#{attr_name} = :credential"
58
- end.join(" or ")
59
-
60
- # Set the scope.
61
- scope = SimpleAuth::Config.model_class.where(query, credential: credential.to_s)
62
-
63
- # Find the record using the conditions we built
64
- scope.first
65
- end
66
-
67
- # Find user by its credential. If no user is found, raise
68
- # SimpleAuth::RecordNotFound exception.
69
- #
70
- # User.find_by_credential! "john@doe.com"
71
- #
72
- def find_by_credential!(credential)
73
- record = find_by_credential(credential)
74
- raise SimpleAuth::RecordNotFound, "couldn't find #{SimpleAuth::Config.model} using #{credential.inspect} as credential" unless record
75
- record
76
- end
77
- end
78
- end
79
- end
80
- end