Class: Dune::Api::V1::SessionsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/dune/api/v1/sessions_controller.rb

Constant Summary

Constants inherited from BaseController

BaseController::MODULES

Instance Method Summary collapse

Methods inherited from BaseController

#access_token, #check_authorization!, #current_user, #handle_forbidden, #handle_unauthorized, #require_admin!

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/dune/api/v1/sessions_controller.rb', line 6

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

#destroyObject



20
21
22
23
24
# File 'app/controllers/dune/api/v1/sessions_controller.rb', line 20

def destroy
  access_token.try(:expire!)

  render status: :ok, json: {}
end