Sign Up
Login
Home
Plugins
Gems
News
Job Board
Edit Change password
Plugin home
Submit new plugin
*
Title
*
Content
When using the Restful Authentication plugin and you would like to allow users to change their password, consider using this code as a base In your users controller [code] # # Change user passowrd def change_password end # # Change user passowrd def change_password_update if User.authenticate(current_user.login, params[:old_password]) if ((params[:password] == params[:password_confirmation]) && !params[:password_confirmation].blank?) current_user.password_confirmation = params[:password_confirmation] current_user.password = params[:password] if current_user.save! flash[:notice] = "Password successfully updated" redirect_to change_password_path else flash[:alert] = "Password not changed" render :action => 'change_password' end else flash[:alert] = "New Password mismatch" render :action => 'change_password' end else flash[:alert] = "Old password incorrect" render :action => 'change_password' end end[/code] Create a view users/change_password.html.erb [code]<% form_tag change_password_update_user_path(current_user), :method => :put do |f| %> <fieldset> <dl> <dt><label for="old_password" class="block">Old Password</label></dt> <dd><%= password_field_tag 'old_password', @old_password, :size => 45, :class => 'text' %></dd> <dt><label for="password" class="block">New Password</label></dt> <dd><%= password_field_tag 'password', {}, :size => 45, :class => 'text' %> <div><small>Between 4 and 40 characters</small></div></dd> <dt><label for="password_confirmation" class="block">Confirm new password</label></dt> <dd class="last"><%= password_field_tag 'password_confirmation', {}, :size => 45, :class => 'text' %></dd> </dl> <%= submit_tag 'Change password' %> </fieldset> <%end%>[/code] Finall add this to your config/routes.rb file [code]map.change_password '/change_password', :controller => 'users', :action => 'change_password'[/code]
How do I format code and text?
To check that you are human, please answer the following question.
*
Five times two is what?
Plugin Links
Restful Authentication home
Change password
Plugin Search
Plugin Tags
ACL
acts
Admin
AJAX
amazon
api
assert
asset
association
attribute
Auth
Authentication
browser
Cache
Calendar
Captcha
column
config
CRUD
CSS
data
Database
Date
default
editor
email
exception
filter
find
fixture
flash
form
format
FormHelper
generator
Geo
Gibberish
Google
graph
HAML
helper
HTML
http
image
Images
input
Javascript
label
list
log
Login
mail
Maps
message
migration
Migrations
model
monitor
mysql
number
Sponsors