Sha256: 32f6669dc237f5acf6e4e5b0c735bb678114fbd060c08eba0044707c0af3f73b

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module NoPassword
  class SessionsController < ApplicationController
    include NoPassword::ControllerHelpers

    def new
      @return_to = params[:return_to].to_s
      @resource = Session.new
    end

    def create
      return_to = params[:return_to].to_s
      current_session = SessionManager.new.create(request.user_agent, params.dig(:session, :email), request.remote_ip, referrer_path(return_to))

      if current_session.present?
        SessionsMailer.with(session: current_session).send_token.deliver_later

        after_session_request if respond_to?(:after_session_request)

        respond_to do |format|
          format.html { redirect_to no_password.edit_session_confirmations_path }
          format.turbo_stream
        end
      end
    end

    def destroy
      sign_out
      redirect_to main_app.root_path
    end

    private

    def referrer_path(return_to)
      referrer = CGI.unescape(return_to)
      return nil if referrer.blank?

      referrer.include?(no_password.new_session_path) || referrer.include?(no_password.edit_session_confirmations_path) ? nil : referrer
    end

    def sign_out(key = nil)
      session.delete(session_key)
      session.delete(session_key(key)) if key.present?
      @session = nil
      true
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
no_password_auth-0.2.1 app/controllers/no_password/sessions_controller.rb