Sha256: e08dcc3de4a5cb7f43437c97c02dc09897bdcc8de26632271579556590707d69

Contents?: true

Size: 789 Bytes

Versions: 8

Compression:

Stored size: 789 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
    if user = User.authenticate_by(email: params[:email], password: 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

8 entries across 8 versions & 1 rubygems

Version Path
authentication-zero-4.0.3 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-4.0.2 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-4.0.1 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-4.0.0 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-3.0.2 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-3.0.1 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-3.0.0 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-3.0.0.alpha1 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt