Sha256: 4494482eb40076706de6d3045348afc59f9a24d7db5353e72284ad8e513ee9ae

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module Nyauth
  class SessionsController < ApplicationController
    include Nyauth::ApplicationConcern
    include Nyauth::ClientConcern
    include Nyauth::SessionConcern
    before_action -> { require_authentication! as: client_name }
    allow_everyone only: [:new, :create]
    self.responder = Nyauth::AppResponder
    respond_to :html, :json
    before_action :set_session_service

    def new
    end

    def create
      sign_in(@session_service.client) if @session_service.save(as: client_name)
      respond_with @session_service, location: Nyauth.configuration.redirect_path_after_sign_in.call(client_name) || main_app.root_path
    end

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

    private

    def set_session_service
      @session_service = Nyauth::SessionService.new(session_service_params)
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nyauth-0.2.8 app/controllers/nyauth/sessions_controller.rb
nyauth-0.2.7 app/controllers/nyauth/sessions_controller.rb