Sha256: f0e28b0856e9f3c244fc55074bc9aa1c4fc7c26ff459941468ffd3fbed1c0b7d

Contents?: true

Size: 1.65 KB

Versions: 9

Compression:

Stored size: 1.65 KB

Contents

module Ecm
  module UserArea
    module Users
      class BaseController < Ecm::UserArea::Configuration.base_controller.constantize
        include ResourcesController::Resources
        include ResourcesController::ResourceInflections
        include ResourcesController::RestResourceUrls
        include ResourcesController::RestActions
        include ResourcesController::LocationHistory

        before_action :authenticate_user!, except: [:new, :create]

        def create
          @resource = resource_class.new(permitted_params)
          flash[:notice] = I18n.t('messages.confirmations.ecm_user_area.send_instructions') if @resource.save && !request.xhr?
          respond_with @resource, location: after_registration_url
        end

        def update
          @resource = load_resource
          # do not assign password/confirmation if they are empty
          @resource.attributes = permitted_params.delete_if { |_k, v| v.empty? }

          if @resource.save && (@resource.previous_changes.keys.map(&:to_sym) & [:email, :crypted_password]).any?
            current_session(:user).destroy
            redirect_to(new_user_session_path)
            return
          end
          respond_with @resource, location: edit_current_user_path
        end

        private

        def after_registration_url
          new_user_session_path
        end

        def load_resource
          @resource = send("current_#{resource_class.name.demodulize.underscore}".to_sym)
        end

        def permitted_params
          params.require(resource_class.name.demodulize.underscore.to_sym).permit(:email, :password, :password_confirmation)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ecm_user_area2-4.0.2 app/controllers/ecm/user_area/users/base_controller.rb
ecm_user_area2-4.0.1 app/controllers/ecm/user_area/users/base_controller.rb
ecm_user_area2-3.1.2 app/controllers/ecm/user_area/users/base_controller.rb
ecm_user_area2-3.1.1 app/controllers/ecm/user_area/users/base_controller.rb
ecm_user_area2-3.1.0 app/controllers/ecm/user_area/users/base_controller.rb
ecm_user_area2-3.0.3 app/controllers/ecm/user_area/users/base_controller.rb
ecm_user_area2-3.0.2 app/controllers/ecm/user_area/users/base_controller.rb
ecm_user_area2-3.0.1 app/controllers/ecm/user_area/users/base_controller.rb
ecm_user_area2-3.0.0 app/controllers/ecm/user_area/users/base_controller.rb