Sha256: 546e044d5f88aef9ac5aa0bb66244482538634701221a3058d57bb269e536624

Contents?: true

Size: 1.09 KB

Versions: 8

Compression:

Stored size: 1.09 KB

Contents

require_dependency "push_type/admin_controller"

module PushType
  class ProfilesController < AdminController

    before_action :load_user

    def edit
    end

    def update
      if update_user profile_params
        flash[:notice] = 'Profile successfully updated.'
        bypass_sign_in @user
        redirect_to push_type.edit_profile_path
      else
        render 'edit'
      end
    end

    private

    def initial_breadcrumb
      breadcrumbs.add 'Profile', push_type.edit_profile_path
    end

    def load_user
      @user = current_user
    end

    def update_user(user_params)
      if password_required?
        @user.update_with_password user_params
      else
        user_params.delete :current_password
        @user.update_without_password user_params
      end
    end

    def password_required?
      profile_params[:password].present? || profile_params[:password_confirmation].present?
    end

    def profile_params
      fields = [:name, :email, :current_password, :password, :password_confirmation] + @user.fields.keys
      params.fetch(:user, {}).permit(*fields)
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
push_type_auth-0.9.5 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.9.3 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.9.2 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.9.1 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.9.0 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.9.0.beta.4 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.9.0.beta.3 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.9.0.beta.2 app/controllers/push_type/profiles_controller.rb