Sha256: aeb40dee8f251bd46b580ba931afcd7ebff58609b1e6f7647499ca7522f3c86d

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

class SessionsController < ApplicationController
  skip_before_action :authenticate, only: :create

  before_action :set_session, only: %i[ show destroy ]

  def index
    render json: Current.<%= singular_table_name %>.sessions.order(created_at: :desc)
  end

  def show
    render json: @session
  end

  def create
    <%= singular_table_name %> = <%= class_name %>.find_by(email: params[:email])

    if <%= singular_table_name %> && <%= singular_table_name %>.authenticate(params[:password])
      @session = <%= singular_table_name %>.sessions.create!(session_params)
      response.set_header("X-Session-Token", @session.signed_id)

      render json: @session, status: :created
    else
      render json: { error: "That email or password is incorrect" }, status: :unauthorized
    end
  end

  def destroy
    @session.destroy
  end

  private
    def set_session
      @session = Current.<%= singular_table_name %>.sessions.find(params[:id])
    end

    def session_params
      { user_agent: request.user_agent, ip_address: request.remote_ip, sudo_at: Time.current }
    end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
authentication-zero-2.8.4 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.8.3 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.8.2 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.8.1 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.8.0 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.7.0 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.6.0 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.5.1 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.5.0 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.4.0 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt