Sha256: ff40c6cbaa1ed7935a85cb5828e08c8f1eead21e7a1d2acf81d153a95f782b30

Contents?: true

Size: 1.91 KB

Versions: 8

Compression:

Stored size: 1.91 KB

Contents

module Locomotive
  module Api
    class TokensController < Locomotive::Api::BaseController

      skip_before_filter :require_account, :require_site, :set_current_thread_variables

      def create
        begin
          token = Account.create_api_token(current_site, params[:email], params[:password], params[:api_key])
          respond_with({ token: token }, location: root_url)
        rescue Exception => e
          respond_with({ message: e.message }, status: 401, location: root_url)
        end
      end

      def destroy
        begin
          token = Account.invalidate_api_token(params[:id])
          respond_with({ token: token }, location: root_url)
        rescue Exception => e
          respond_with({ message: e.message }, status: 404, location: root_url)
        end
      end

      protected

      def set_locale
        I18n.locale = Locomotive.config.locales.first
      end

      def self.description
        {
          overall: %{Manage a session token which will be passed to all the other REST calls},
          actions: {
            create: {
              description: %{Generate a session token from either an email and a password OR an api key},
              params: { email: 'String', password: 'String' },
              response: { token: 'String' },
              example: {
                command: %{curl -d 'email=john.doe@acme.org&password=secret' 'http://mysite.com/locomotive/api/tokens.json'},
                response: %({ "token": "dtsjkqs1TJrWiSiJt2gg" })
              }
            },
            destroy: {
              description: %{Make a session token invalid},
              response: { token: 'String' },
              example: {
                command: %{curl -X DELETE 'http://mysite.com/locomotive/api/tokens/dtsjkqs1TJrWiSiJt2gg.json'},
                response: %({ "token": "dtsjkqs1TJrWiSiJt2gg" })
              }
            }
          }
        }
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
locomotive_cms-2.5.0 app/controllers/locomotive/api/tokens_controller.rb
locomotive_cms-2.5.0.rc3 app/controllers/locomotive/api/tokens_controller.rb
locomotive_cms-2.5.0.rc2 app/controllers/locomotive/api/tokens_controller.rb
locomotive_cms-2.5.0.rc1 app/controllers/locomotive/api/tokens_controller.rb
locomotive_cms-2.4.1 app/controllers/locomotive/api/tokens_controller.rb
locomotive_cms-2.4.0 app/controllers/locomotive/api/tokens_controller.rb
locomotive_cms-2.3.1 app/controllers/locomotive/api/tokens_controller.rb
locomotive_cms-2.3.0 app/controllers/locomotive/api/tokens_controller.rb