Module: MailruSession::InstanceMethods

Defined in:
lib/authlogic_connect_mailru/mailru_session.rb

Instance Method Summary collapse

Instance Method Details

#authenticating_with_mailru?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/authlogic_connect_mailru/mailru_session.rb', line 13

def authenticating_with_mailru?
  mailru_credentials
end

#validate_by_mailruObject



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

def validate_by_mailru
  return if attempted_record

  if mailru_credentials[:sig] == MailruToken.sign( mailru_credentials )
    if token = MailruToken.find_by_key( mailru_credentials[:oid], :include => :user ) # Try to find token by user id
      token.token = mailru_token_value
      token.save!

      self.attempted_record = token.user
    elsif auto_register?
      self.attempted_record = klass.new
      self.attempted_record.access_tokens << MailruToken.new( :key => mailru_credentials[:oid], :token => mailru_token_value )
      self.attempted_record.save
    else
      Rails.logger.warn "Could not find user in our database, have you registered with your mailru account?"

      errors.add(:user, "Could not find user in our database, have you registered with your mailru account?")
    end
  else
    Rails.logger.warn "Wrong MailRu credentials signature"
  end
end