Sha256: bbdd0e8b106000ed4146dd629397e16d1851d91213a7212ef5bf1d30bc1cabfb

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

module Applicaster
  module SessionsControllerMixin
    def new
      Rails.logger.info("New session initiated. Redirecting to /auth/applicaster. IP: #{request.remote_ip}, User Agent: #{request.user_agent}")
      redirect_to "/auth/applicaster"
    end

    def create
      session[:omniauth_credentials] = omniauth_credentials
      Rails.logger.info("Session created successfully for user. IP: #{request.remote_ip}, User Agent: #{request.user_agent}, Params: #{params[:origin].inspect}")

      redirect_to(session.delete(:path_before_login) || '/')
    end

    def destroy
      user_email = current_user.email rescue "Unknown"
      Rails.logger.info("Session destroyed for user: #{user_email}. IP: #{request.remote_ip}, User Agent: #{request.user_agent}")

      reset_session
      redirect_to "/"
    end

    def failure
      Rails.logger.error({
        message: "[Login Failed] - Omniauth error with strategy '#{params[:strategy]}': #{params[:message]}",
        IP: request.remote_ip,
        UserAgent: request.user_agent,
        Params: params[:origin],
      })
      flash[:notice] = "There was a problem logging in"
      redirect_to "/"
    end

    protected

    def omniauth_credentials
      request.env['omniauth.auth'].credentials.to_hash.symbolize_keys
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-applicaster-2.0.0 lib/applicaster/sessions_controller_mixin.rb