Admins on my site want to be able to set user passwords themselves.  I
couldn't find any good way of turning off Hobo's current_password
validation so I did this...

Can anyone suggest a better way of doing this?  And, is this a feature
that belongs in Hobo proper?

    - Scott



Here's my users_controller.rb, showing how to use it:

diff --git a/app/controllers/users_controller.rb
b/app/controllers/users_controller.rb
index df849be..91b4912 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -93,4 +93,12 @@ class UsersController < ApplicationController
         (session[:return_to].nil? || session[:return_to] == '/')
     end
   end
+
+  def update
+    # if we're logged in as an administrator, there's no need to
confirm the existing
+    # password before setting a new one.
+    rec = find_instance
+    rec.current_password_needed = false if current_user.administrator?
+    hobo_update rec
+  end
 end



This is the change I needed to make to Hobo:

diff --git a/vendor/plugins/hobo/hobo/lib/hobo/user.rb
b/vendor/plugins/hobo/hobo/lib/hobo/user.rb
index 51308c5..e7118a7 100644
--- a/vendor/plugins/hobo/hobo/lib/hobo/user.rb
+++ b/vendor/plugins/hobo/hobo/lib/hobo/user.rb
@@ -46,6 +46,11 @@ module Hobo
         attr_protected *AUTHENTICATION_FIELDS


+        # Tells Hobo that there's no need to check whether the
current password is correct.
+        # Do this, for instance, when an administrator is changing
another user's password.
+        # user.current_password_needed = false if current_user.administrator?
+        @current_password_needed = true
+        attr_accessor :current_password_needed
       end
     end

@@ -161,8 +166,9 @@ module Hobo
       lifecycle_changing_password? || changing_password?
     end

-
     def validate_current_password_when_changing_password
+      # If the controller tells us the current password isn't needed,
we won't require one.
+      return unless @current_password_needed
       changing_password? && !authenticated?(current_password) and
errors.add :current_password, "is not correct"
     end



You probably also want to change the edit page's field-list to not
include the password confirmation box when current_user is an
administrator..

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to