Class: Dune::Api::V1::SessionsController
Constant Summary
BaseController::MODULES
Instance Method Summary
collapse
#access_token, #check_authorization!, #current_user, #handle_forbidden, #handle_unauthorized, #require_admin!
Instance Method Details
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|