Sha256: 6447275f97a0c4e2e474c37ca828f2c16c700579117145905677803c9b627410

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Masks
  # @visibility private
  class SessionsController < ApplicationController
    def new
      respond_to do |format|
        format.json { render json: resource_cls.new(masked_session) }
        format.html { render(:new) }
      end
    end

    def create
      flash[
        :errors
      ] = masked_session.errors.full_messages unless request.format == :json

      respond_to do |format|
        format.json { render json: resource_cls.new(masked_session) }
        format.html do
          path =
            (
              if masked_session.passed?
                masked_session.mask.pass ||
                  Masks.configuration.site_links[:after_login]
              else
                masked_session.mask.fail ||
                  Masks.configuration.site_links[:login]
              end
            )
          redirect_to path
        end
      end
    end

    def destroy
      masked_session.cleanup!

      respond_to do |format|
        format.json { render json: resource_cls.new(masked_session) }
        format.html do
          redirect_to Masks.configuration.site_links[:after_logout]
        end
      end
    end

    private

    def resource_cls
      Masks.configuration.model(:session_json)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
masks-0.3.2 app/controllers/masks/sessions_controller.rb
masks-0.3.1 app/controllers/masks/sessions_controller.rb
masks-0.3.0 app/controllers/masks/sessions_controller.rb
masks-0.2.0 app/controllers/masks/sessions_controller.rb