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 included from AuthenticateHelper

#auth_params, #auth_token, #authenticate, #entity

Instance Method Details

#create ⇒ Object



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

def create
  user_form = form_class_name(Tramway::Api.user_based_model).new Tramway::Api.user_based_model.new
  if user_form.validate params
    user_form.save
    token = ::Knock::AuthToken.new(payload: { sub: user_form.model.id }).token
    serialized_user = OpenStruct.new user_form.model.attributes.merge authentication_token: token
    render json: serialized_user, status: :created
  else
    render json: user_form.errors.details, status: :unprocessable_entity
  end
end

#show ⇒ Object



19
20
21
# File 'app/controllers/tramway/api/v1/users_controller.rb', line 19

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