Sha256: 1fe3c1421ff767aeda2c6ad920f8b0fe8471ef759f52312471ad787fb7d0c359

Contents?: true

Size: 687 Bytes

Versions: 3

Compression:

Stored size: 687 Bytes

Contents

module Dune::Api
  module V1
    class SessionsController < BaseController
      skip_before_action :check_authorization!, only: :create

      def create
        user = User.find_by(email: params.fetch(:email))
        if user && user.valid_password?(params.fetch(:password))
          render status: :created, json: {
            access_token: user.get_access_token,
            user_id:      user.id
          }
        else
          render status: :unauthorized, json: {}
        end
      rescue KeyError
        render status: :bad_request, json: {}
      end

      def destroy
        access_token.try(:expire!)

        render status: :ok, json: {}
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dune-api-1.1.0 app/controllers/dune/api/v1/sessions_controller.rb
dune-api-1.0.2 app/controllers/dune/api/v1/sessions_controller.rb
dune-api-1.0.1 app/controllers/dune/api/v1/sessions_controller.rb