Class: Little::User

Inherits:
Object
  • Object
show all
Defined in:
lib/little/user.rb

Overview

log and retrieve login attempts

Class Method Summary collapse

Class Method Details

.attempts(user, count = 1) ⇒ Object

gets the login attempts for the user

Parameters:

  • user (String)

    the user who attempted to login

  • count (int) (defaults to: 1)

    the number of past attempts to retrieve



21
22
23
# File 'lib/little/user.rb', line 21

def self.attempts(user, count = 1)
  Little.get(:users, {:user => user, :count => count}, [:user], 'attempts')
end

.delete(user) ⇒ Object

deletes the user from the system, irrevocably purging all login attempts, assets, tags, notifications responses and so on for the user



32
33
34
# File 'lib/little/user.rb', line 32

def self.delete(user)
  Little.delete(:users, {:user => user, :verify => 'kludge'}, [:user, :verify])
end

.login_attempt(user, ip, ok) ⇒ Hash

adds a login attempt

Parameters:

  • user (String)

    the user who attempted to login

  • ip (String)

    the user’s ip address (use request.remote_ip in rails)

  • ok (bool)

    whether or not the login was successful

Returns:

  • (Hash)

    the number of failed attempts in the last 0.5, 1, 3 and 5 minutes



9
10
11
# File 'lib/little/user.rb', line 9

def self.(user, ip, ok)
  Little.post(:users, {:user => user, :ip => ip, :ok => ok}, [:user, :ip, :ok], 'attempt')
end

.previous_successful_attempt(user) ⇒ Object

gets the previous (2nd last) successful login attempt



14
15
16
# File 'lib/little/user.rb', line 14

def self.previous_successful_attempt(user)
  Little.get(:users, {:user => user}, [:user], 'attempts')
end

.sign_attempts(user) ⇒ Object

generates a signature for getting attempts(useful when using the javascript library)



26
27
28
# File 'lib/little/user.rb', line 26

def self.sign_attempts(user)
  Little.sign(:users, {:user => user})
end