Sha256: f5572c961beed9d413ea1bc58d2bf9ab491669c4ff9c80e364e90bbb7bba6306

Contents?: true

Size: 1.7 KB

Versions: 24

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

# This controller handles updating your own user data.
class Admin::ProfilesController < Admin::BaseController
  before_action :set_user, only: [:index, :update]

  def index; end

  def update
    @user.resource = upload_avatar if params[:user][:filename]

    if @user.update(update_params)
      redirect_to admin_profiles_url, notice: I18n.t("admin.profiles.index.success")
    else
      render :index
    end
  end

  private

  def upload_avatar
    file = params[:user][:filename]

    mime = if file.content_type
             file.content_type.chomp
           else
             "text/plain"
           end

    Resource.create(upload: file, mime: mime, created_at: Time.zone.now)
  end

  # Use callbacks to share common setup or constraints between actions.
  def set_user
    @user = current_user
  end

  # Never trust parameters from the scary internet, only allow the white list through.
  def user_params
    params.require(:user).permit(:login, :password, :password_confirmation,
                                 :email, :firstname, :lastname, :nickname,
                                 :name, :notify_via_email,
                                 :notify_on_new_articles, :notify_on_comments,
                                 :text_filter_id, :state,
                                 :twitter_account, :twitter_oauth_token,
                                 :twitter_oauth_token_secret, :description,
                                 :url, :msn, :yahoo, :jabber, :aim, :twitter)
  end

  def update_params
    if user_params[:password].blank? && user_params[:password_confirmation].blank?
      user_params.except(:password_confirmation, :password)
    else
      user_params
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
publify_core-10.0.2 app/controllers/admin/profiles_controller.rb
HornsAndHooves-publify_core-10.5.0 app/controllers/admin/profiles_controller.rb
HornsAndHooves-publify_core-10.4.0 app/controllers/admin/profiles_controller.rb
HornsAndHooves-publify_core-10.3.0 app/controllers/admin/profiles_controller.rb
HornsAndHooves-publify_core-10.2.0 app/controllers/admin/profiles_controller.rb
publify_core-10.0.1 app/controllers/admin/profiles_controller.rb
publify_core-10.0.0 app/controllers/admin/profiles_controller.rb
publify_core-9.2.10 app/controllers/admin/profiles_controller.rb
HornsAndHooves-publify_core-10.1.1 app/controllers/admin/profiles_controller.rb
HornsAndHooves-publify_core-10.1.0 app/controllers/admin/profiles_controller.rb
HornsAndHooves-publify_core-10.0.3 app/controllers/admin/profiles_controller.rb
HornsAndHooves-publify_core-10.0.2 app/controllers/admin/profiles_controller.rb
HornsAndHooves-publify_core-10.0.1 app/controllers/admin/profiles_controller.rb
HornsAndHooves-publify_core-10.0.0 app/controllers/admin/profiles_controller.rb
publify_core-9.2.9 app/controllers/admin/profiles_controller.rb
publify_core-9.2.8 app/controllers/admin/profiles_controller.rb
publify_core-9.2.7 app/controllers/admin/profiles_controller.rb
publify_core-9.2.6 app/controllers/admin/profiles_controller.rb
publify_core-9.2.5 app/controllers/admin/profiles_controller.rb
publify_core-9.2.4 app/controllers/admin/profiles_controller.rb