From: Tom Hughes Date: Tue, 12 Jun 2007 00:28:53 +0000 (+0000) Subject: Allow users to change their password from the account page, and get rid X-Git-Tag: live~8899 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/2afcb4b222b6a5ef11e537e3fb33e7cc7246b966 Allow users to change their password from the account page, and get rid of the separate edit page that (partially) duplicated the account page. --- diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 83845af42..cc934fc32 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -2,8 +2,8 @@ class UserController < ApplicationController layout 'site' before_filter :authorize, :only => [:preferences, :api_details, :api_gpx_files] - before_filter :authorize_web, :only => [:edit, :account, :go_public, :view, :diary, :make_friend] - before_filter :require_user, :only => [:edit, :set_home, :account, :go_public, :make_friend] + before_filter :authorize_web, :only => [:account, :go_public, :view, :diary, :make_friend] + before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend] def save @user = User.new(params[:user]) @@ -18,18 +18,23 @@ class UserController < ApplicationController end end - def edit + def account if params[:user] and params[:user][:display_name] and params[:user][:description] home_lat = params[:user][:home_lat] home_lon = params[:user][:home_lon] @user.display_name = params[:user][:display_name] + if params[:user][:pass_crypt].length > 0 or params[:user][:pass_crypt_confirmation].length > 0 + @user.pass_crypt = params[:user][:pass_crypt] + @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation] + end @user.description = params[:user][:description] @user.home_lat = home_lat.to_f @user.home_lon = home_lon.to_f if @user.save flash[:notice] = "User information updated successfully." - redirect_to :controller => 'user', :action => 'account' + else + flash.delete(:notice) end end end diff --git a/app/models/user.rb b/app/models/user.rb index d6cff0f25..da4d4c205 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -24,7 +24,7 @@ class User < ActiveRecord::Base end def encrypt_password - self.pass_crypt = Digest::MD5.hexdigest(pass_crypt) if pass_crypt_confirmation + self.pass_crypt = Digest::MD5.hexdigest(pass_crypt) unless pass_crypt_confirmation.nil? end def self.authenticate(email, passwd) diff --git a/app/views/user/account.rhtml b/app/views/user/account.rhtml index eafa2d5f4..ca1fe61bd 100644 --- a/app/views/user/account.rhtml +++ b/app/views/user/account.rhtml @@ -1,10 +1,12 @@

User details

<%= error_messages_for 'user' %> -<% form_tag :controller => 'user', :action => 'edit', :display_name => @user.display_name do %> +<% form_tag :controller => 'user', :action => 'account', :display_name => @user.display_name do %> + + class="nohome" <%end%> >
Name<%= @user.email %>
Mapper since<%= @user.creation_time %> (<%= time_ago_in_words(@user.creation_time) %> ago)
Display Name<%= text_field :user, :display_name, :value => @user.display_name %>
Password<%= password_field('user', 'pass_crypt',{:value => '', :size => 50, :maxlength => 255}) %>
Confirm Password<%= password_field('user', 'pass_crypt_confirmation',{:value => '', :size => 50, :maxlength => 255}) %>
Your homeYou have not entered your home location.Latitude: <%= text_field :user, :home_lat, :value => @user.home_lat, :size => 20, :id => "home_lat" %> Longitude <%= text_field :user, :home_lon, :value => @user.home_lon, :size => 20, :id => "home_lon" %>
diff --git a/app/views/user/edit.rhtml b/app/views/user/edit.rhtml deleted file mode 100644 index 0ca853e0b..000000000 --- a/app/views/user/edit.rhtml +++ /dev/null @@ -1,12 +0,0 @@ -

Edit details:

-<%= error_messages_for 'user' %> -<% form_tag :controller => 'user', :action => 'edit', :display_name => User.find(@user.id).display_name do %> - - - - - - -
display name<%= text_field :user, :display_name, :value => @user.display_name %>
description<%= text_area :user, :description, :value => @user.description %>
home latitude<%= text_field :user, :home_lat, :value => @user.home_lat %>
home longitude<%= text_field :user, :home_lon, :value => @user.home_lon %>
-<%= submit_tag 'Change' %> -<% end %> diff --git a/config/routes.rb b/config/routes.rb index f2ccdad0e..bc7f08b5b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -76,7 +76,6 @@ ActionController::Routing::Routes.draw do |map| map.connect '/user/:display_name/diary', :controller => 'user', :action => 'diary' map.connect '/user/:display_name/diary/rss', :controller => 'user', :action => 'rss' map.connect '/user/:display_name/diary/newpost', :controller => 'diary_entry', :action => 'new' - map.connect '/user/:display_name/edit', :controller => 'user', :action => 'edit' map.connect '/user/:display_name/account', :controller => 'user', :action => 'account' map.connect '/user/:display_name/set_home', :controller => 'user', :action => 'set_home' map.connect '/diary', :controller => 'diary_entry', :action => 'list'