Sha256: af60b558a706ca0269046fdab1d09913e9ef4113e6c29615b352e82c1be01b59

Contents?: true

Size: 1.75 KB

Versions: 16

Compression:

Stored size: 1.75 KB

Contents

require_dependency "egov_utils/application_controller"
require_dependency "egov_utils/auth_source"

module EgovUtils
  class UsersController < ApplicationController

    load_and_authorize_resource only: :index

    def index
      providers
    end

    def new
      @user = User.new
    end

    def create
      @user = User.new(create_params)
      respond_to do |format|
        if @user.save
          format.html{ redirect_to main_app.root_path, notice: t('activerecord.successful.messages.created', model: Group.model_name.human) }
          format.json{ render json: @user, status: :created }
        else
          format.html{ render 'new' }
          format.json{ render json: @user.errors.full_messages, status: :unprocessable_entity }
        end
      end
    end

    def show
    end

    def approve
      @user = User.find_by(id: params[:id])
      render_404 and return unless @user || @user.active?
      authorize!(:manage, User)
      @user.update(active: true)
      redirect_back(fallback_location: @user)
    end

    def search
      authorize!(:read, User)
      authorize!(:read, Group)
      user_results = []; group_results = []
      providers.each do |provider|
        user_results.concat( provider.search_user(params[:q]) )
        group_results.concat( provider.search_group(params[:q]) )
      end if params[:q].present?
      respond_to do |format|
        format.json{ render json: {users: user_results, groups: group_results} }
      end
    end

    private

      def providers
         @providers = EgovUtils::AuthSource.providers.collect{|p| EgovUtils::AuthSource.new(p)}
      end

      def create_params
        params.require(:user).permit(:login, :mail, :password, :password_confirmation, :provider, :firstname, :lastname)
      end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
egov_utils-0.1.17 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.16 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.15 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.14 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.13 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.12 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.11 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.10 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.9 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.8 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.7 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.6 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.5 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.4 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.1 app/controllers/egov_utils/users_controller.rb
egov_utils-0.1.0 app/controllers/egov_utils/users_controller.rb