aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/api/v1
diff options
context:
space:
mode:
authorMarc Florisson2012-12-13 19:14:45 +0100
committerMarc Florisson2012-12-13 19:14:45 +0100
commit988800310d2e6ae3dfc0935506eeae12f21c9ed6 (patch)
treed1bae0fe02f052006309755347a48f9f48537235 /app/models/api/v1
parent3a4ee94cd91de749521ac190656c65266861270f (diff)
downloadchouette-core-988800310d2e6ae3dfc0935506eeae12f21c9ed6.tar.bz2
refactor api/v1
Diffstat (limited to 'app/models/api/v1')
-rw-r--r--app/models/api/v1/api_key.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/app/models/api/v1/api_key.rb b/app/models/api/v1/api_key.rb
index 0b045e58f..40719127a 100644
--- a/app/models/api/v1/api_key.rb
+++ b/app/models/api/v1/api_key.rb
@@ -5,19 +5,21 @@ module Api
belongs_to :referential, :class_name => '::Referential'
def eql?(other)
- other.token == self.token && other.referential_id == self.referential_id
+ other.token == self.token
+ end
+
+ def self.referential_from_token(token)
+ array = token.split('-')
+ return nil unless array.size==2
+ ::Referential.find( array.first)
end
private
def generate_access_token
begin
- self.token = SecureRandom.hex
- puts "self.token=#{self.token}"
+ self.token = "#{referential.id}-#{SecureRandom.hex}"
end while self.class.exists?(:token => self.token)
end
- def organisation
- @organisation ||= Organisation.find_by_id @organisation_id
- end
end
end
end