Class: Tramway::Api::V1::UsersController

Inherits:
ApplicationController show all
Includes:
ClassNameHelpers
Defined in:
app/controllers/tramway/api/v1/users_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#render_error_with_text, #render_errors_for

Instance Method Details

#create ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/tramway/api/v1/users_controller.rb', line 7

def create
  user_form = (Tramway::Api.user_based_model).new Tramway::Api.user_based_model.new
  # Implement JSON API spec here
  if user_form.submit params[Tramway::Api.user_based_model.name.underscore]
    token = ::Knock::AuthToken.new(payload: { sub: user_form.model.id }).token
    # FIXME refactor this bullshit
    serialized_user = OpenStruct.new(
      user_form.model.attributes.merge(
        authentication_token: token,
        id: user_form.model.uid
      )
    )
    render json: serialized_user, status: :created
  else
    render_errors_for user_form
  end
end

#show ⇒ Object



25
26
27
# File 'app/controllers/tramway/api/v1/users_controller.rb', line 25

def show
  render json: current_user, status: :ok
end