<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/views/user_mailer/reset_password.rhtml</filename>
    </added>
    <added>
      <filename>lib/password_generator.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -2,6 +2,14 @@ class Admin::UsersController &lt; ApplicationController
   require_role :admin
   layout 'admin'
   
+  def reset_password
+    @user = User.find(params[:id])
+    @user.reset_password!
+    
+    flash[:notice] = &quot;A new password has been sent to the user by email.&quot;
+    redirect_to admin_user_path(@user)
+  end
+  
   def pending
     @users = User.paginate :all, :conditions =&gt; {:state =&gt; 'pending'}, :page =&gt; params[:page]
     render :action =&gt; 'index'</diff>
      <filename>app/controllers/admin/users_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -69,6 +69,16 @@ class User &lt; ActiveRecord::Base
     transitions :from =&gt; :suspended, :to =&gt; :passive
   end
 
+  # Creates a new password for the user, and notifies him with an email
+  def reset_password!
+    password = PasswordGenerator.random_pronouncable_password(3)
+    self.password = password
+    self.password_confirmation = password
+    save
+    
+    UserMailer.deliver_reset_password(self)
+  end
+
   # Authenticates a user by their login name and unencrypted password.  Returns the user or nil.
   def self.authenticate(login, password)
     u = find_in_state :first, :active, :conditions =&gt; {:login =&gt; login} # need to get the salt</diff>
      <filename>app/models/user.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,12 @@ class UserMailer &lt; ActionMailer::Base
     @subject    += 'Please activate your new account'
   
     @body[:url]  = &quot;http://base_app_url/activate/#{user.activation_code}&quot;
+  end
   
+  def reset_password(user)
+    setup_email(user)
+    @subject += &quot;Your password has been reset&quot;
+    @body[:url]  = &quot;http://base_app_url/login&quot;
   end
   
   def activation(user)</diff>
      <filename>app/models/user_mailer.rb</filename>
    </modified>
    <modified>
      <diff>@@ -38,7 +38,7 @@ base_app Account for &lt;em&gt;&lt;%=h @user.login %&gt;&lt;/em&gt;
 	&lt;%= cell_separator %&gt;
 	
 	&lt;%= cell &quot;Email&quot;, h(@user.email) %&gt;
-	&lt;%= cell &quot;Password&quot;, &quot;*&quot; * 8 %&gt;
+	&lt;%= cell &quot;Password&quot;, &quot;#{&quot;*&quot;*8} &lt;small&gt;#{link_to &quot;reset password&quot;, reset_password_admin_user_url(@user), :method =&gt; :put}&lt;/small&gt;&quot; %&gt;
 	
 	&lt;%= cell_separator %&gt;
 	</diff>
      <filename>app/views/admin/users/show.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -19,7 +19,8 @@ ActionController::Routing::Routes.draw do |map|
     admin.resources :users, :member =&gt; { :suspend   =&gt; :put,
                                          :unsuspend =&gt; :put,
                                          :activate  =&gt; :put, 
-                                         :purge     =&gt; :delete },
+                                         :purge     =&gt; :delete,
+                                         :reset_password =&gt; :put },
                             :collection =&gt; { :pending   =&gt; :get,
                                              :active    =&gt; :get, 
                                              :suspended =&gt; :get, </diff>
      <filename>config/routes.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>bc298994b16cf906c1be8d7321205f476be4a89c</id>
    </parent>
  </parents>
  <author>
    <name>Ariejan de Vroom</name>
    <email>ariejan@ariejan.net</email>
  </author>
  <url>http://github.com/ariejan/baseapp/commit/050fa8e7c7a048a01cd55fc41772a1b31ebab939</url>
  <id>050fa8e7c7a048a01cd55fc41772a1b31ebab939</id>
  <committed-date>2008-02-25T07:37:18-08:00</committed-date>
  <authored-date>2008-02-25T07:37:18-08:00</authored-date>
  <message>Added 'reset password' feature for administrators</message>
  <tree>b63a966cf5048f355c5ab07fb352b302c6759cea</tree>
  <committer>
    <name>Ariejan de Vroom</name>
    <email>ariejan@ariejan.net</email>
  </committer>
</commit>
