refinerycms-authentication 2.0.2 → 2.0.3

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.
@@ -15,7 +15,7 @@ module Refinery
15
15
  end
16
16
 
17
17
  def create
18
- @user = Refinery::User.new(params[:user])
18
+ @user = Refinery::User.new(params[:user].except(:roles))
19
19
  @selected_plugin_names = params[:user][:plugins] || []
20
20
  @selected_role_names = params[:user][:roles] || []
21
21
 
@@ -1,5 +1,6 @@
1
1
  module Refinery
2
2
  class PasswordsController < Devise::PasswordsController
3
+ helper Refinery::Core::Engine.helpers
3
4
  layout 'refinery/layouts/login'
4
5
 
5
6
  before_filter :store_password_reset_return_to, :only => [:update]
@@ -1,5 +1,6 @@
1
1
  module Refinery
2
2
  class SessionsController < Devise::SessionsController
3
+ helper Refinery::Core::Engine.helpers
3
4
  layout 'refinery/layouts/login'
4
5
 
5
6
  before_filter :clear_unauthenticated_flash, :only => [:new]
@@ -4,6 +4,7 @@ module Refinery
4
4
  # Protect these actions behind an admin login
5
5
  before_filter :redirect?, :only => [:new, :create]
6
6
 
7
+ helper Refinery::Core::Engine.helpers
7
8
  layout 'refinery/layouts/login'
8
9
 
9
10
  def new
@@ -0,0 +1,6 @@
1
+ module Refinery
2
+ module Admin
3
+ module UsersHelper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module Refinery
2
+ module PasswordsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Refinery
2
+ module UserMailerHelper
3
+ end
4
+ end
@@ -1,4 +1,5 @@
1
1
  require 'devise'
2
+ require 'friendly_id'
2
3
 
3
4
  module Refinery
4
5
  class User < Refinery::Core::BaseModel
@@ -43,7 +44,7 @@ module Refinery
43
44
  end
44
45
 
45
46
  def authorized_plugins
46
- plugins.collect { |p| p.name } | ::Refinery::Plugins.always_allowed.names
47
+ plugins.collect(&:name) | ::Refinery::Plugins.always_allowed.names
47
48
  end
48
49
 
49
50
  def can_delete?(user_to_delete = self)
@@ -1,5 +1,12 @@
1
+ Refinery::Core::Engine.routes.append do
2
+ namespace :admin, :path => 'refinery' do
3
+ resources :users, :except => :show
4
+ end
5
+ end
6
+
1
7
  Refinery::Core::Engine.routes.draw do
2
8
  begin
9
+ require 'devise'
3
10
  devise_for :refinery_user,
4
11
  :class_name => 'Refinery::User',
5
12
  :path => 'refinery/users',
@@ -29,9 +36,3 @@ Refinery::Core::Engine.routes.draw do
29
36
  end
30
37
  end
31
38
  end
32
-
33
- Refinery::Core::Engine.routes.append do
34
- namespace :admin, :path => 'refinery' do
35
- resources :users, :except => :show
36
- end
37
- end
@@ -33,8 +33,10 @@ module Refinery
33
33
  protected :store_location, :redirect_back_or_default, :refinery_user?
34
34
 
35
35
  def self.included(base)
36
- base.send :helper_method, :current_refinery_user, :current_user_session,
37
- :refinery_user_signed_in?, :refinery_user? if base.respond_to? :helper_method
36
+ if base.respond_to? :helper_method
37
+ base.send :helper_method, :current_refinery_user, :current_user_session,
38
+ :refinery_user_signed_in?, :refinery_user?
39
+ end
38
40
  end
39
41
  end
40
42
  end
@@ -0,0 +1,233 @@
1
+ require 'devise'
2
+
3
+ # Use this hook to configure devise mailer, warden hooks and so forth.
4
+ # Many of these configuration options can be set straight in your model.
5
+ Devise.setup do |config|
6
+ # ==> Mailer Configuration
7
+ # Configure the e-mail address which will be shown in Devise::Mailer,
8
+ # note that it will be overwritten if you use your own mailer class with default "from" parameter.
9
+ # config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
10
+
11
+ # Configure the class responsible to send e-mails.
12
+ # config.mailer = "Devise::Mailer"
13
+
14
+ # Automatically apply schema changes in tableless databases
15
+ config.apply_schema = false
16
+
17
+ # ==> ORM configuration
18
+ # Load and configure the ORM. Supports :active_record (default) and
19
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
20
+ # available as additional gems.
21
+ ActiveSupport.on_load(:active_record) do
22
+ Devise.setup do
23
+ require 'devise/orm/active_record'
24
+ end
25
+ end
26
+
27
+ # ==> Configuration for any authentication mechanism
28
+ # Configure which keys are used when authenticating a user. The default is
29
+ # just :email. You can configure it to use [:username, :subdomain], so for
30
+ # authenticating a user, both parameters are required. Remember that those
31
+ # parameters are used only when authenticating and not when retrieving from
32
+ # session. If you need permissions, you should implement that in a before filter.
33
+ # You can also supply a hash where the value is a boolean determining whether
34
+ # or not authentication should be aborted when the value is not present.
35
+ config.authentication_keys = [ :login ]
36
+
37
+ # Configure parameters from the request object used for authentication. Each entry
38
+ # given should be a request method and it will automatically be passed to the
39
+ # find_for_authentication method and considered in your model lookup. For instance,
40
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
41
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
42
+ # config.request_keys = []
43
+
44
+ # Configure which authentication keys should be case-insensitive.
45
+ # These keys will be downcased upon creating or modifying a user and when used
46
+ # to authenticate or find a user. Default is :email.
47
+ config.case_insensitive_keys = []
48
+
49
+ # Configure which authentication keys should have whitespace stripped.
50
+ # These keys will have whitespace before and after removed upon creating or
51
+ # modifying a user and when used to authenticate or find a user. Default is :email.
52
+ # config.strip_whitespace_keys = [ :email ]
53
+
54
+ # Tell if authentication through request.params is enabled. True by default.
55
+ # It can be set to an array that will enable params authentication only for the
56
+ # given stratragies, for example, `config.params_authenticatable = [:database]` will
57
+ # enable it only for database (email + password) authentication.
58
+ # config.params_authenticatable = true
59
+
60
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
61
+ # It can be set to an array that will enable http authentication only for the
62
+ # given stratragies, for example, `config.http_authenticatable = [:token]` will
63
+ # enable it only for token authentication.
64
+ # config.http_authenticatable = false
65
+
66
+ # If http headers should be returned for AJAX requests. True by default.
67
+ # config.http_authenticatable_on_xhr = true
68
+
69
+ # The realm used in Http Basic Authentication. "Application" by default.
70
+ # config.http_authentication_realm = "Application"
71
+
72
+ # It will change confirmation, password recovery and other workflows
73
+ # to behave the same regardless if the e-mail provided was right or wrong.
74
+ # Does not affect registerable.
75
+ # config.paranoid = true
76
+
77
+ # By default Devise will store the user in session. You can skip storage for
78
+ # :http_auth and :token_auth by adding those symbols to the array below.
79
+ # Notice that if you are skipping storage for all authentication paths, you
80
+ # may want to disable generating routes to Devise's sessions controller by
81
+ # passing :skip => :sessions to `devise_for` in your config/routes.rb
82
+ config.skip_session_storage = [:http_auth]
83
+
84
+ # ==> Configuration for :database_authenticatable
85
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
86
+ # using other encryptors, it sets how many times you want the password re-encrypted.
87
+ #
88
+ # Limiting the stretches to just one in testing will increase the performance of
89
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
90
+ # a value less than 10 in other environments.
91
+ config.stretches = Rails.env.test? ? 1 : 10
92
+
93
+ # Setup a pepper to generate the encrypted password.
94
+ # config.pepper = <%= SecureRandom.hex(64).inspect %>
95
+
96
+ # ==> Configuration for :confirmable
97
+ # A period that the user is allowed to access the website even without
98
+ # confirming his account. For instance, if set to 2.days, the user will be
99
+ # able to access the website for two days without confirming his account,
100
+ # access will be blocked just in the third day. Default is 0.days, meaning
101
+ # the user cannot access the website without confirming his account.
102
+ # config.allow_unconfirmed_access_for = 2.days
103
+
104
+ # If true, requires any email changes to be confirmed (exctly the same way as
105
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
106
+ # db field (see migrations). Until confirmed new email is stored in
107
+ # unconfirmed email column, and copied to email column on successful confirmation.
108
+ # config.reconfirmable = true
109
+
110
+ # Defines which key will be used when confirming an account
111
+ # config.confirmation_keys = [ :email ]
112
+
113
+ # ==> Configuration for :rememberable
114
+ # The time the user will be remembered without asking for credentials again.
115
+ # config.remember_for = 2.weeks
116
+
117
+ # If true, extends the user's remember period when remembered via cookie.
118
+ # config.extend_remember_period = false
119
+
120
+ # If true, uses the password salt as remember token. This should be turned
121
+ # to false if you are not using database authenticatable.
122
+ config.use_salt_as_remember_token = true
123
+
124
+ # Options to be passed to the created cookie. For instance, you can set
125
+ # :secure => true in order to force SSL only cookies.
126
+ # config.cookie_options = {}
127
+
128
+ # ==> Configuration for :validatable
129
+ # Range for password length. Default is 6..128.
130
+ config.password_length = 4..128
131
+
132
+ # Email regex used to validate email formats. It simply asserts that
133
+ # an one (and only one) @ exists in the given string. This is mainly
134
+ # to give user feedback and not to assert the e-mail validity.
135
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
136
+
137
+ # ==> Configuration for :timeoutable
138
+ # The time you want to timeout the user session without activity. After this
139
+ # time the user will be asked for credentials again. Default is 30 minutes.
140
+ # config.timeout_in = 30.minutes
141
+
142
+ # ==> Configuration for :lockable
143
+ # Defines which strategy will be used to lock an account.
144
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
145
+ # :none = No lock strategy. You should handle locking by yourself.
146
+ # config.lock_strategy = :failed_attempts
147
+
148
+ # Defines which key will be used when locking and unlocking an account
149
+ # config.unlock_keys = [ :email ]
150
+
151
+ # Defines which strategy will be used to unlock an account.
152
+ # :email = Sends an unlock link to the user email
153
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
154
+ # :both = Enables both strategies
155
+ # :none = No unlock strategy. You should handle unlocking by yourself.
156
+ # config.unlock_strategy = :both
157
+
158
+ # Number of authentication tries before locking an account if lock_strategy
159
+ # is failed attempts.
160
+ # config.maximum_attempts = 20
161
+
162
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
163
+ # config.unlock_in = 1.hour
164
+
165
+ # ==> Configuration for :recoverable
166
+ #
167
+ # Defines which key will be used when recovering the password for an account
168
+ # config.reset_password_keys = [ :email ]
169
+
170
+ # Time interval you can reset your password with a reset password key.
171
+ # Don't put a too small interval or your users won't have the time to
172
+ # change their passwords.
173
+ config.reset_password_within = 6.hours
174
+
175
+ # ==> Configuration for :encryptable
176
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
177
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
178
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
179
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
180
+ # REST_AUTH_SITE_KEY to pepper)
181
+ # config.encryptor = :sha512
182
+
183
+ # ==> Configuration for :token_authenticatable
184
+ # Defines name of the authentication token params key
185
+ # config.token_authentication_key = :auth_token
186
+
187
+ # ==> Scopes configuration
188
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
189
+ # "users/sessions/new". It's turned off by default because it's slower if you
190
+ # are using only default views.
191
+ # config.scoped_views = false
192
+
193
+ # Configure the default scope given to Warden. By default it's the first
194
+ # devise role declared in your routes (usually :user).
195
+ # config.default_scope = :user
196
+
197
+ # Configure sign_out behavior.
198
+ # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
199
+ # The default is true, which means any logout action will sign out all active scopes.
200
+ # config.sign_out_all_scopes = true
201
+
202
+ # ==> Navigation configuration
203
+ # Lists the formats that should be treated as navigational. Formats like
204
+ # :html, should redirect to the sign in page when the user does not have
205
+ # access, but formats like :xml or :json, should return 401.
206
+ #
207
+ # If you have any extra navigational formats, like :iphone or :mobile, you
208
+ # should add them to the navigational formats lists.
209
+ #
210
+ # The "*/*" below is required to match Internet Explorer requests.
211
+ # config.navigational_formats = ["*/*", :html]
212
+
213
+ # The default HTTP method used to sign out a resource. Default is :delete.
214
+ config.sign_out_via = :delete
215
+
216
+ # ==> OmniAuth
217
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
218
+ # up on your models and hooks.
219
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
220
+
221
+ # ==> Warden configuration
222
+ # If you want to use other strategies, that are not supported by Devise, or
223
+ # change the failure app, you can configure them inside the config.warden block.
224
+ #
225
+ # config.warden do |manager|
226
+ # manager.intercept_401 = false
227
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
228
+ # end
229
+
230
+ # Please do not change the router_name away from :refinery
231
+ # otherwise Refinery may not function properly. Thanks!
232
+ config.router_name = :refinery
233
+ end
@@ -28,6 +28,10 @@ module Refinery
28
28
  end
29
29
  end
30
30
 
31
+ config.before_configuration do
32
+ require 'refinery/authentication/devise'
33
+ end
34
+
31
35
  config.after_initialize do
32
36
  Refinery.register_extension(Refinery::Authentication)
33
37
  end
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_dependency 'refinerycms-core', version
24
24
  s.add_dependency 'devise', '~> 2.0.0'
25
+ s.add_dependency 'orm_adapter', '~> 0.0.7'
25
26
  end
@@ -4,7 +4,7 @@ describe "manage users" do
4
4
  login_refinery_superuser
5
5
 
6
6
  describe "new/create" do
7
- it "allows to create user" do
7
+ def visit_and_fill_form
8
8
  visit refinery.admin_users_path
9
9
  click_link "Add new user"
10
10
 
@@ -12,11 +12,34 @@ describe "manage users" do
12
12
  fill_in "Email", :with => "test@refinerycms.com"
13
13
  fill_in "Password", :with => "123456"
14
14
  fill_in "Password confirmation", :with => "123456"
15
+ end
16
+
17
+ it "can create a user" do
18
+ visit_and_fill_form
19
+
15
20
  click_button "Save"
16
21
 
17
22
  page.should have_content("test was successfully added.")
18
23
  page.should have_content("test (test@refinerycms.com)")
19
24
  end
25
+
26
+ context "when assigning roles config is enabled" do
27
+ before do
28
+ Refinery::Authentication.stub(:superuser_can_assign_roles).and_return(true)
29
+ end
30
+
31
+ it "allows superuser to assign roles" do
32
+ visit_and_fill_form
33
+
34
+ within "#roles" do
35
+ check "roles_#{Refinery::Role.first.title.downcase}"
36
+ end
37
+ click_button "Save"
38
+
39
+ page.should have_content("test was successfully added.")
40
+ page.should have_content("test (test@refinerycms.com)")
41
+ end
42
+ end
20
43
  end
21
44
 
22
45
  describe "edit/update" do
metadata CHANGED
@@ -1,71 +1,81 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-authentication
3
- version: !ruby/object:Gem::Version
4
- hash: 11
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.3
5
5
  prerelease:
6
- segments:
7
- - 2
8
- - 0
9
- - 2
10
- version: 2.0.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Philip Arndt
14
- - "U\xC4\xA3is Ozols"
9
+ - Uģis Ozols
15
10
  - David Jones
16
11
  - Steven Heidel
17
12
  autorequire:
18
13
  bindir: bin
19
14
  cert_chain: []
20
-
21
- date: 2012-03-15 00:00:00 Z
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
15
+ date: 2012-04-02 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: refinerycms-core
19
+ requirement: !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - '='
23
+ - !ruby/object:Gem::Version
24
+ version: 2.0.3
25
+ type: :runtime
24
26
  prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
27
+ version_requirements: !ruby/object:Gem::Requirement
26
28
  none: false
27
- requirements:
28
- - - "="
29
- - !ruby/object:Gem::Version
30
- hash: 11
31
- segments:
32
- - 2
33
- - 0
34
- - 2
35
- version: 2.0.2
36
- version_requirements: *id001
37
- name: refinerycms-core
29
+ requirements:
30
+ - - '='
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: devise
35
+ requirement: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
38
41
  type: :runtime
39
- - !ruby/object:Gem::Dependency
40
42
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
43
+ version_requirements: !ruby/object:Gem::Requirement
42
44
  none: false
43
- requirements:
45
+ requirements:
44
46
  - - ~>
45
- - !ruby/object:Gem::Version
46
- hash: 15
47
- segments:
48
- - 2
49
- - 0
50
- - 0
47
+ - !ruby/object:Gem::Version
51
48
  version: 2.0.0
52
- version_requirements: *id002
53
- name: devise
49
+ - !ruby/object:Gem::Dependency
50
+ name: orm_adapter
51
+ requirement: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 0.0.7
54
57
  type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ~>
63
+ - !ruby/object:Gem::Version
64
+ version: 0.0.7
55
65
  description: The default authentication extension for Refinery CMS
56
66
  email: info@refinerycms.com
57
67
  executables: []
58
-
59
68
  extensions: []
60
-
61
69
  extra_rdoc_files: []
62
-
63
- files:
70
+ files:
64
71
  - app/controllers/refinery/admin/users_controller.rb
65
72
  - app/controllers/refinery/passwords_controller.rb
66
73
  - app/controllers/refinery/sessions_controller.rb
67
74
  - app/controllers/refinery/users_controller.rb
75
+ - app/helpers/refinery/admin/users_helper.rb
76
+ - app/helpers/refinery/passwords_helper.rb
68
77
  - app/helpers/refinery/sessions_helper.rb
78
+ - app/helpers/refinery/user_mailer_helper.rb
69
79
  - app/helpers/refinery/users_helper.rb
70
80
  - app/mailers/refinery/user_mailer.rb
71
81
  - app/models/refinery/role.rb
@@ -120,6 +130,7 @@ files:
120
130
  - lib/refinery/authenticated_system.rb
121
131
  - lib/refinery/authentication.rb
122
132
  - lib/refinery/authentication/configuration.rb
133
+ - lib/refinery/authentication/devise.rb
123
134
  - lib/refinery/authentication/engine.rb
124
135
  - lib/refinerycms-authentication.rb
125
136
  - license.md
@@ -131,39 +142,37 @@ files:
131
142
  - spec/requests/refinery/passwords_spec.rb
132
143
  - spec/requests/refinery/sessions_spec.rb
133
144
  homepage: http://refinerycms.com
134
- licenses:
145
+ licenses:
135
146
  - MIT
136
147
  post_install_message:
137
148
  rdoc_options: []
138
-
139
- require_paths:
149
+ require_paths:
140
150
  - lib
141
- required_ruby_version: !ruby/object:Gem::Requirement
151
+ required_ruby_version: !ruby/object:Gem::Requirement
142
152
  none: false
143
- requirements:
144
- - - ">="
145
- - !ruby/object:Gem::Version
146
- hash: 3
147
- segments:
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ segments:
148
158
  - 0
149
- version: "0"
150
- required_rubygems_version: !ruby/object:Gem::Requirement
159
+ hash: -65986755646960009
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
161
  none: false
152
- requirements:
153
- - - ">="
154
- - !ruby/object:Gem::Version
155
- hash: 3
156
- segments:
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ segments:
157
167
  - 0
158
- version: "0"
168
+ hash: -65986755646960009
159
169
  requirements: []
160
-
161
170
  rubyforge_project: refinerycms
162
- rubygems_version: 1.8.17
171
+ rubygems_version: 1.8.19
163
172
  signing_key:
164
173
  specification_version: 3
165
174
  summary: Authentication extension for Refinery CMS
166
- test_files:
175
+ test_files:
167
176
  - spec/controllers/refinery/admin/users_controller_spec.rb
168
177
  - spec/factories/user.rb
169
178
  - spec/models/refinery/user_spec.rb