Sha256: cdfdaff5ca805c85161d55dc78ea0750472d677e0372d0286581961e74fcb740

Contents?: true

Size: 1.78 KB

Versions: 57

Compression:

Stored size: 1.78 KB

Contents

module Cmor
  module UserArea
    module Sessions
      class BaseController < Cmor::UserArea::Configuration.base_controller.constantize
        include Rao::ResourcesController::ResourcesConcern
        include Rao::ResourcesController::ResourceInflectionsConcern
        include Rao::ResourcesController::RestResourceUrlsConcern
        include Rao::ResourcesController::RestActionsConcern
        include Rao::ResourcesController::LocationHistoryConcern

        skip_before_action :authenticate_user!, only: [:new, :create], raise: false
        skip_before_action :store_location, only: [:new, :create]

        def new
          @session = initialize_resource
          respond_with @session
        end

        def create
          @session = resource_class.new(permitted_params)

          if @session.save
            flash[:notice] = I18n.t('messages.success.cmor_user_area.signed_in') unless request.xhr?
            redirect_to(instance_eval(&Configuration.after_sign_in_url))
            return
          else
            render action: :new
          end
        end

        def destroy
          current_session(resource_class.name.demodulize.underscore.to_sym).destroy
          flash[:notice] = I18n.t('messages.success.cmor_user_area.signed_out') unless request.xhr?
          redirect_to after_sign_out_url
        end

        def self.resource_class
          fail 'please define self.session_class in your controller.'
        end

        private

        def permitted_params
          if Rails.version < '5'
            params.require(resource_class.name.demodulize.underscore.tr('/', '_')).permit(:email, :password)
          else
            params.require(resource_class.name.demodulize.underscore.tr('/', '_')).permit(:email, :password).to_h
          end
        end
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
cmor_user_area-0.0.60.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.59.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.58.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.57.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.56.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.55.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.54.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.53.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.52.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.51.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.50.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.49.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.48.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.45.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.44.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.43.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.42.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.41.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.40.pre app/controllers/cmor/user_area/sessions/base_controller.rb
cmor_user_area-0.0.39.pre app/controllers/cmor/user_area/sessions/base_controller.rb