Edward's reason for the monkey patch and comment about an anonymous
user setting anyone's password is a non-issue. Devise is really quite
sophisticated. Password resets require a token that expires after a
configurable amount of time (I think the default is something like 2
hours), so it's really nothing to worry about.
It's hard to say what's wrong without full access to your codebase.
I'm posting the relevant bits from a number of key files. You won't be
able to copy and paste, but it might help you verify that you have all
the bases covered. One quick note, in application_controller, I
include the line,
"filter_access_to :index, :new, :create, :show, :update, :destroy",
this is simply an easy way to specify authorization in one single
place for all of my controllers. There is also a line that I have
commented out, "check_authorization :unless => :devise_controller?",
which might be something you want to play around with.
One final bit of advice... won't pertain to logging in, but If you are
doing attribute on your models, remember to include :attribute_check
=> true when calling filter_access_to, such as in the following line:
filter_access_to :create, :update, :destroy, :attribute_check => true
This is easily overlooked and trips up many people who are new to
devise. Google "declaritive_authorization attribute_check" for more
information.
Here are the relevant code snippets that I mentioned above:
[routes.rb]
Myapp::Application.routes.draw do
devise_for :users, :controllers => { :invitations => 'devise/
invitations', :password_expired => 'devise/password_expired' }
end
[authorization_rules.rb]
authorization do
role :guest do
has_permission_on :devise_sessions, :to =>
[:new, :create, :delete]
has_permission_on :devise_passwords, :to =>
[:new, :create, :edit, :update]
has_permission_on :devise_unlocks, :to => [:show, :new, :create]
has_permission_on :devise_invitations, :to => [:edit, :update]
end
end
[application_controller.rb]
class ApplicationController < ActionController::Base
protect_from_forgery
# check_authorization :unless => :devise_controller?
# filter_resource_access
filter_access_to :index, :new, :create, :show, :update, :destroy
layout :layout_by_resource
before_filter :set_current_user
protected
def set_current_user
Authorization.current_user = current_user
end
def layout_by_resource
if devise_controller?
"login"
else
"application"
end
end
end
[user.rb]
class User < ActiveRecord::Base
attr_accessible :client_id, :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :address, :city, :state, :country, :zip, :url, :business_phone, :mobile_phone, :fax
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :lockable, :timeoutable, :password_expirable, :password_archivable, :secure_validatable, :invitable, :invite_for
=> 2.weeks
has_and_belongs_to_many :roles
validates :email, :first_name, :last_name, :client_id, :presence =>
true
validates :password, :length => { :in => password_length, :too_short
=> :password_too_short, :too_long => :password_too_long }, :format =>
{ :with => password_regex, :message
=> :invalid_password_format }, :confirmation => { :message =>
"Confirmation does not match password." }, :if => :password_required?
#:passwords_dont_match }
def role_symbols
(roles || []).map {|r| r.name.to_sym}
end
end
Hope that helps... good luck!
On May 9, 2:33 am, Peter Hamilton <
peterghamil...@gmail.com> wrote:
> I'm still lost here. Here's the trace leading up to the
> Authorization::NotAuthorized
>
> declarative_authorization (0.5.5)
> lib/declarative_authorization/authorization.rb:192:in `permit!'
>
> declarative_authorization (0.5.5)
> lib/declarative_authorization/in_model.rb:159:in `block (3 levels) in
> using_access_control'
>
> activesupport (3.2.2) lib/active_support/callbacks.rb:407:in
> `_run__4541110893238119253__update__4112429618023661094__callbacks'
>
> activesupport (3.2.2) lib/active_support/callbacks.rb:405:in
> `__run_callback'
>
> activesupport (3.2.2) lib/active_support/callbacks.rb:385:in
> `_run_update_callbacks'
>
> activesupport (3.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
>
> activerecord (3.2.2) lib/active_record/callbacks.rb:272:in `update'
> .....
>
> It fails right after calling update on the model. So it's definitely the
> model.
>
> Eduard is right on. Here's the message where he has his patch to devise:
http://groups.google.com/group/declarative_authorization/browse_threa...
>
> Sorry for the multiple replies and thanks for the help.
>
> ...
>
> read more »