Class: ForestLiana::SessionsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/forest_liana/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/forest_liana/sessions_controller.rb', line 4

def create
  @error_message = nil
  @user_class = ForestLiana.user_class_name.constantize rescue nil

  user = check_user
  token = encode_token(user) if user

  if token
    render json: { token: token }, serializer: nil
  else
    if @error_message
      render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
        [{ detail: @error_message }]), status: :unauthorized
    elsif !has_internal_authentication? && ForestLiana.allowed_users.empty?
      render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
        [{ detail: 'Forest cannot retrieve any users for the project ' \
          'you\'re trying to unlock.' }]), status: :unauthorized
    else
      head :unauthorized
    end
  end
end