Sha256: 620949184ddd073e1f54b16e63c24f0c80357e7d1c5f78be43f5e67303f93e46

Contents?: true

Size: 1.1 KB

Versions: 31

Compression:

Stored size: 1.1 KB

Contents

require_dependency "push_type/admin_controller"

module PushType
  class ProfilesController < AdminController

    before_filter :load_user

    def edit
    end

    def update
      if update_user profile_params
        flash[:notice] = 'Profile successfully updated.'
        sign_in @user, bypass: true
        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

31 entries across 31 versions & 1 rubygems

Version Path
push_type_auth-0.8.2 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.8.1 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.8.0 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.8.0.beta.3 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.8.0.beta.2 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.8.0.beta.1 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.7.0 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.7.0.beta.1 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.6.0 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.6.0.beta.4 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.6.0.beta.3 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.6.0.beta.2 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.6.0.beta.1 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.5.3 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.5.2 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.5.1 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.5.0 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.5.0.alpha.5 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.5.0.alpha.4 app/controllers/push_type/profiles_controller.rb
push_type_auth-0.5.0.alpha.3 app/controllers/push_type/profiles_controller.rb