diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1fd8347b..66979d5e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -116,40 +116,51 @@ class UsersController < ApplicationController @notification_options = @user.valid_notification_options @notification_option = @user.mail_notification - if request.post? - @user.admin = params[:user][:admin] if params[:user][:admin] - @user.login = params[:user][:login] if params[:user][:login] - if params[:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?) - @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] - end - @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids] - @user.attributes = params[:user] - # Was the account actived ? (do it before User#save clears the change) - was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) - # TODO: Similar to My#account - @user.mail_notification = params[:notification_option] || 'only_my_events' - @user.pref.attributes = params[:pref] - @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') - - if @user.save - @user.pref.save - @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) - - if was_activated - Mailer.deliver_account_activated(@user) - elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? - Mailer.deliver_account_information(@user, params[:password]) - end - flash[:notice] = l(:notice_successful_update) - redirect_to :back - end - end @auth_sources = AuthSource.find(:all) @membership ||= Member.new + end + + verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } + def update + @user = User.find(params[:id]) + @notification_options = @user.valid_notification_options + @notification_option = @user.mail_notification + + @user.admin = params[:user][:admin] if params[:user][:admin] + @user.login = params[:user][:login] if params[:user][:login] + if params[:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?) + @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] + end + @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids] + @user.attributes = params[:user] + # Was the account actived ? (do it before User#save clears the change) + was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) + # TODO: Similar to My#account + @user.mail_notification = params[:notification_option] || 'only_my_events' + @user.pref.attributes = params[:pref] + @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') + + if @user.save + @user.pref.save + @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) + + if was_activated + Mailer.deliver_account_activated(@user) + elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? + Mailer.deliver_account_information(@user, params[:password]) + end + flash[:notice] = l(:notice_successful_update) + redirect_to :back + else + @auth_sources = AuthSource.find(:all) + @membership ||= Member.new + + render :action => :edit + end rescue ::ActionController::RedirectBackError redirect_to :controller => 'users', :action => 'edit', :id => @user end - + def edit_membership @user = User.find(params[:id]) @membership = Member.edit_membership(params[:membership_id], params[:membership], @user) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 757a91a9..37cecc05 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -34,14 +34,14 @@ module UsersHelper end def change_status_link(user) - url = {:controller => 'users', :action => 'edit', :id => user, :page => params[:page], :status => params[:status], :tab => nil} + url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil} if user.locked? - link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock' + link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock' elsif user.registered? - link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock' + link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock' elsif user != User.current - link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :post, :class => 'icon icon-lock' + link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'icon icon-lock' end end diff --git a/app/views/users/_general.rhtml b/app/views/users/_general.rhtml index e962056a..a08b3cee 100644 --- a/app/views/users/_general.rhtml +++ b/app/views/users/_general.rhtml @@ -1,4 +1,4 @@ -<% labelled_tabular_form_for :user, @user, :url => { :controller => 'users', :action => "edit", :tab => nil }, :html => { :class => nil } do |f| %> +<% labelled_tabular_form_for :user, @user, :url => { :controller => 'users', :action => "update", :tab => nil }, :html => { :method => :put, :class => nil } do |f| %> <%= render :partial => 'form', :locals => { :f => f } %> <% if @user.active? -%>
diff --git a/app/views/users/_groups.rhtml b/app/views/users/_groups.rhtml index 4bca77c0..0ab2f11e 100644 --- a/app/views/users/_groups.rhtml +++ b/app/views/users/_groups.rhtml @@ -1,4 +1,4 @@ -<% form_for(:user, :url => { :action => 'edit' }) do %> +<% form_for(:user, :url => { :action => 'update' }, :html => {:method => :put}) do %>