Sha256: 426101d217dfd89fd438de010e959c5b1529b9a40249c0405a4a03dd7c70ac36

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

require_dependency "cadenero/application_controller"

module Cadenero
  module V1
    # Handles the Accounts for the multitenant. An account creates a subdomain in the server as a route
    # the account has an owner that is the default admin for that account
    class AccountsController < Cadenero::ApplicationController
      # For API consistency provides the example for creating a new account
      def new
        errors = %Q{Please sign up. posting the account json data as {account: { name: "Testy", subdomain: "test", owner_attributes: {email: "testy@example.com", password: "changeme", password_confirmation: "changeme"} }} to /v1/accounts/sign_up}
        render json: {errors: errors, links: "/v1/accounts/sign_up"}, status: :unprocessable_entity
      end
      # Create a [Cadenero::V1::Account] based on the params sended by the client as a JSON with the account inrormation
      #
      # @example Posting the account data to be created in a subdomain
      #   post "http://www.example.com/v1/accounts", 
      #   account: { name: "Testy", subdomain: "test", 
      #     owner_attributes: {email: "testy@example.com", password: "changeme", password_confirmation: "changeme"} }
      #
      # @return render JSON of [Cadenero::V1::Account] 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.create_with_owner(params[:account])
        if @account.valid?
          @account.create_schema
          @account.ensure_authentication_token!
          force_authentication!(@account.owner)
          render json: @account, status: :created
        else
          @data = {
            errors: @account.errors
          }
          render json: @data, status: :unprocessable_entity
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cadenero-0.0.2.b4 app/controllers/cadenero/v1/accounts_controller.rb
cadenero-0.0.2.b2 app/controllers/cadenero/v1/accounts_controller.rb
cadenero-0.0.2.b1 app/controllers/cadenero/v1/accounts_controller.rb