Sha256: 82e8d04bb23ad8bcf7cb1a97a0620e8c8f834407e374f07d72add7c6a7c21519

Contents?: true

Size: 1.83 KB

Versions: 11

Compression:

Stored size: 1.83 KB

Contents

class UsersController < ApplicationController
  verify :method => :post, :only => [:update],
         :redirect_to => {:action => :index}

  before_filter :login_required

  def index
    @users = find(:all)
  end

  def show
    @user = find(params[:id])
  end

  def edit
    @user = find(params[:id])
  end

  def update
    @user = find(params[:id])
    previous_user_password = @user.user_password
    object_class_error_message = nil
    begin
      @user.replace_class(params["object-classes"])
    rescue ActiveLdap::RequiredObjectClassMissed
      object_class_error_message = $!.message
    end
    if @user.update_attributes(params[:user]) and
        object_class_error_message.nil?
      if previous_user_password != @user.user_password and @user.connected?
        @user.bind(@user.password)
      end
      flash[:notice] = _('User was successfully updated.')
      redirect_to :action => 'show', :id => @user
    else
      @user.password = @user.password_confirmation = nil
      @user.errors.add("objectClass", object_class_error_message)
      render :action => 'edit'
    end
  end

  def update_object_classes
    @user = find(params[:id])
    begin
      @user.replace_class(params["object-classes"])
    rescue ActiveLdap::RequiredObjectClassMissed
      flash.now[:inline_notice] = $!.message
      erb = "<%= flash_box(flash[:inline_notice], :need_container => true) %>"
      render(:inline => erb, :status => 400)
      return
    end
    available_attributes = @user.attribute_names(true)
    attributes = {}
    (params[:user] || {}).each do |key, value|
      attributes[key] = value if available_attributes.include?(key)
    end
    @user.attributes = attributes
    erb = "<div>\n<%= render(:partial => 'attributes_update_form') %>\n</div>"
    render(:inline => erb)
  end

  private
  def find(*args)
    current_ldap_user.find(*args)
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
activeldap-1.2.3 examples/al-admin/app/controllers/users_controller.rb
activeldap3-1.2.3 examples/al-admin/app/controllers/users_controller.rb
activeldap-1.2.2 examples/al-admin/app/controllers/users_controller.rb
activeldap-1.2.1 examples/al-admin/app/controllers/users_controller.rb
activeldap-1.2.0 examples/al-admin/app/controllers/users_controller.rb
activeldap-1.1.0 examples/al-admin/app/controllers/users_controller.rb
activeldap-0.10.0 examples/al-admin/app/controllers/users_controller.rb
activeldap-1.0.0 examples/al-admin/app/controllers/users_controller.rb
activeldap-1.0.9 examples/al-admin/app/controllers/users_controller.rb
activeldap-1.0.1 examples/al-admin/app/controllers/users_controller.rb
activeldap-1.0.2 examples/al-admin/app/controllers/users_controller.rb