Sha256: 9347973a772552296086ed82111a1eb0b9315fb85ab7101ab1cfa22000c5c115

Contents?: true

Size: 802 Bytes

Versions: 46

Compression:

Stored size: 802 Bytes

Contents

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

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

  def index
    render json: Current.user.sessions.order(created_at: :desc)
  end

  def show
    render json: @session
  end

  def create
    user = User.find_by(email: params[:email])

    if user && user.authenticate(params[:password])
      @session = user.sessions.create!
      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.user.sessions.find(params[:id])
    end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
authentication-zero-2.16.16 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.16.15 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.16.14 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.16.13 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.16.12 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.16.2 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.16.1 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.16.0 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.15.9 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.15.8 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.15.7 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.15.6 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.15.5 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.15.4 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.15.3 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.15.2 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.15.1 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.15.0 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.14.0 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-2.13.0 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt