Method: UsersController#update

Defined in:
app/controllers/users_controller.rb

#updateObject



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'app/controllers/users_controller.rb', line 164

def update
  is_updating_password = params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
  if is_updating_password
    @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
  end
  @user.safe_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.pref.safe_attributes = params[:pref]

  if @user.save
    @user.pref.save

    Mailer.deliver_password_updated(@user, User.current) if is_updating_password
    if was_activated
      Mailer.(@user)
    elsif @user.active? && params[:send_information] && @user != User.current
      Mailer.(@user, @user.password)
    end

    respond_to do |format|
      format.html do
        flash[:notice] = l(:notice_successful_update)
        redirect_to_referer_or edit_user_path(@user)
      end
      format.api  {render_api_ok}
    end
  else
    @auth_sources = AuthSource.all
    @membership ||= Member.new
    # Clear password input
    @user.password = @user.password_confirmation = nil

    respond_to do |format|
      format.html {render :action => :edit}
      format.api  {render_validation_errors(@user)}
    end
  end
end