Class: OpenIDDataMapper::DataMapperStore

Inherits:
OpenID::Store::Interface
  • Object
show all
Defined in:
lib/openid_dm_store.rb

Instance Method Summary collapse

Instance Method Details

#cleanup_associationsObject



60
61
62
63
64
# File 'lib/openid_dm_store.rb', line 60

def cleanup_associations
  now = Time.now.to_i
  # Association.delete_all(['issued + lifetime > ?',now])
  Association.all(:conditions => ['issued + lifetime > ?', now]).destroy
end

#cleanup_noncesObject



54
55
56
57
58
# File 'lib/openid_dm_store.rb', line 54

def cleanup_nonces
  now = Time.now.to_i
  # Nonce.delete_all(["timestamp > ? OR timestamp < ?", now + OpenID::Nonce.skew, now - OpenID::Nonce.skew])
  Nonce.all(:conditions => ["timestamp > ? OR timestamp < ?", now + OpenID::Nonce.skew, now - OpenID::Nonce.skew]).destroy
end

#get_association(server_url, handle = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/openid_dm_store.rb', line 18

def get_association(server_url, handle=nil)
  assocs = if handle.blank?
      # Association.find_all_by_server_url(server_url)
      Association.all(:server_url => server_url)
    else
      # Association.find_all_by_server_url_and_handle(server_url, handle)
      Association.all(:server_url => server_url, :handle => handle)
    end

  # assocs.reverse.each do |assoc|
  assocs.to_a.reverse.each do |assoc|
    a = assoc.from_record    
    if a.expires_in == 0
      # assoc.destroy
      assoc.destroy
    else
      return a
    end
  end if assocs.any?

  return nil
end

#remove_association(server_url, handle) ⇒ Object



41
42
43
44
# File 'lib/openid_dm_store.rb', line 41

def remove_association(server_url, handle)
  # Association.delete_all(['server_url = ? AND handle = ?', server_url, handle]) > 0
  Association.all(:server_url => server_url, :handle => handle).destroy
end

#store_association(server_url, assoc) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/openid_dm_store.rb', line 8

def store_association(server_url, assoc)
  remove_association(server_url, assoc.handle)    
  Association.create(:server_url => server_url,
                     :handle     => assoc.handle,
                     :secret     => assoc.secret,
                     :issued     => assoc.issued,
                     :lifetime   => assoc.lifetime,
                     :assoc_type => assoc.assoc_type)
end

#use_nonce(server_url, timestamp, salt) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/openid_dm_store.rb', line 46

def use_nonce(server_url, timestamp, salt)
  # return false if Nonce.find_by_server_url_and_timestamp_and_salt(server_url, timestamp, salt)
  return false if Nonce.first(:server_url => server_url, :timestamp => timestamp, :salt => salt)
  return false if (timestamp - Time.now.to_i).abs > OpenID::Nonce.skew
  Nonce.create(:server_url => server_url, :timestamp => timestamp, :salt => salt)
  return true
end