Sha256: c46e4148a39d9caf2a08b06315ab8165219c288643e5b3018918932c7dad1a21

Contents?: true

Size: 1.62 KB

Versions: 4

Compression:

Stored size: 1.62 KB

Contents

# == Cadenero::Account::UsersController for creating the users associated to an account
#
#  Inherates methods from the [::ApplicationController] extender
# @author Manuel Vidaurre @mvidaurre <manuel.vidaurre@agiltec.com.mx>

require_dependency "cadenero/application_controller"

module Cadenero
  module V1
    # Controller for managing users for specific accounts
    class Account::UsersController < Cadenero::ApplicationController
      before_filter :authenticate_user!, except: :create
      # Create a [Cadenero::User] based on the params sended by the client as a JSON with the user inrormation
      #
      # @example Posting the user data to be created in an account via the subdomain
      #   post "http://#{account.subdomain}.example.com/v1/users",
      #   user: { email: "user@example.com", password: "password", password_confirmation: "password" }
      #
      # @return render JSON of [Cadenero::User] created and the status 201 Created: The request has been
      #   fulfilled and resulted in a new resource being created.
      def create
        account = Cadenero::V1::Account.where(subdomain: request.subdomain).first
        @user = account.users.create(params[:user])
        force_authentication!(@user)
        render json: @user, status: :created
      end

      # Send as JSON the user that match the params[:user]
      def show
        @user = current_account.users.where(id: params[:id]).first
        render json: @user, status: :ok
      end

      # Send as JSON the users for the current_account
      def index
        @users = current_account.users
        render json: @users, status: :ok
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cadenero-0.0.2.b8 app/controllers/cadenero/v1/account/users_controller.rb
cadenero-0.0.2.b7 app/controllers/cadenero/v1/account/users_controller.rb
cadenero-0.0.2.b6 app/controllers/cadenero/v1/account/users_controller.rb
cadenero-0.0.2.b5 app/controllers/cadenero/v1/account/users_controller.rb