Sha256: 73f92e91859bb53c3295bed060446a515e00118202ace13490c2ec44c27e2d3d

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

class Admin::SettingsController < Admin::ApplicationController

  before_action :require_user
  skip_before_action :require_admin_user

  before_action do |c|
    if current_user && current_user.has_admin_rights?
      add_breadcrumb "Settings", :admin_settings_path
    end
  end

  def edit
    
  end

  def update
    if check_password && @current_user.update_attributes(user_params)
      if user_params.include?(:password)
          SpudUserSession.create(@current_user)
      end
      flash[:notice] = "User settings saved successfully."
      respond_with @current_user, :location => admin_settings_path
    else
      render 'edit', :status => 401
    end
  end

private

  def user_params
    params.require(:spud_user).permit(:login, :first_name, :last_name, :email, :password, :password_confirmation, :time_zone)
  end

  def check_password
    if params[:spud_user][:password].nil? || params[:spud_user][:password].empty?
      return true
    else
      if !current_user.valid_password?(params[:current_password])
        current_user.errors.add(:current_password, "is not correct. Please enter correct password.")
        return false
      end
      return true
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tb_core-1.3.10 app/controllers/admin/settings_controller.rb
tb_core-1.3.9 app/controllers/admin/settings_controller.rb
tb_core-1.3.7 app/controllers/admin/settings_controller.rb
tb_core-1.3.6 app/controllers/admin/settings_controller.rb