Sha256: 89e738120784fc0ca4ddb622d9e6e460722e1fef7c247616b3ed97ba8519cf1a

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module Nyauth
  class SessionsController < ApplicationController
    include Nyauth::ControllerConcern
    before_action -> { require_authentication! as: nyauth_client_name }
    allow_everyone only: [:new, :create]
    self.responder = Nyauth::AppResponder
    respond_to :html, :json
    before_action :set_service

    def new
    end

    def create
      sign_in(@service.client) if @service.save(as: nyauth_client_name)
      redirect_path =  session.delete("#{nyauth_client_name}_return_to")
      respond_with @service,
                   location: redirect_path || \
                   Nyauth.configuration.redirect_path_after_sign_in.call(nyauth_client_name) || \
                   main_app.root_path
    end

    def destroy
      sign_out
      respond_with @service, location: Nyauth.configuration.redirect_path_after_sign_out.call(nyauth_client_name) || new_session_path_for(nyauth_client_name)
    end

    private

    def set_service
      @service = Nyauth::Session.new(session_service_params)
    end

    def session_service_params
      params.fetch(:session, {})
            .permit(:email, :password)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nyauth-0.5.0 app/controllers/nyauth/sessions_controller.rb
nyauth-0.4.0 app/controllers/nyauth/sessions_controller.rb