diff options
| author | Marc Florisson | 2012-11-28 09:56:01 +0100 | 
|---|---|---|
| committer | Marc Florisson | 2012-11-28 09:56:01 +0100 | 
| commit | a018c33f2792033e5c0829252775f9831950b3ae (patch) | |
| tree | f62dbaad883d51f434756be6407884c72b53184b /app/controllers/api | |
| parent | 1ee37c6b375e52daf3dd2f65d138594b3647a86b (diff) | |
| download | chouette-core-a018c33f2792033e5c0829252775f9831950b3ae.tar.bz2 | |
restrict access to api
Diffstat (limited to 'app/controllers/api')
| -rw-r--r-- | app/controllers/api/v1/networks_controller.rb | 20 | 
1 files changed, 11 insertions, 9 deletions
diff --git a/app/controllers/api/v1/networks_controller.rb b/app/controllers/api/v1/networks_controller.rb index 4404f1496..2ecc23ed0 100644 --- a/app/controllers/api/v1/networks_controller.rb +++ b/app/controllers/api/v1/networks_controller.rb @@ -3,13 +3,13 @@ module Api      class NetworksController < ActionController::Base        respond_to :json, :xml        layout false -      before_filter :restrict_access +      before_filter :restrict_access_and_switch        def referential -        @referential ||= organisation.referentials.find @referential_id +        @referential ||= organisation.referentials.find_by_id @referential_id        end         def organisation -        @organisation ||= Organisation.find @organisation_id +        @organisation ||= Organisation.find_by_id @organisation_id        end         def networks          @networks ||= referential.networks @@ -17,6 +17,7 @@ module Api        def network          @network ||= networks.where( :objectid => params[:id])        end +              def index          respond_to do |format| @@ -32,13 +33,14 @@ module Api        end  private -      def restrict_access -        parse_key -        head :unauthorized unless organisation && referential +      def restrict_access_and_switch +        authenticate_or_request_with_http_token do |token, options| +          switch_referential if key_exists?( token) +        end        end -      def parse_key -        @organisation_id, @referential_id = params[:access_token].split('-') -        switch_referential +      def key_exists?( token) +        @organisation_id, @referential_id = token.split('-') +        organisation && referential        end        def switch_referential          Apartment::Database.switch(referential.slug)  | 
