Class: Sponge::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/sponge/auth.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, users) ⇒ Auth

Returns a new instance of Auth.



4
5
6
7
8
# File 'lib/sponge/auth.rb', line 4

def initialize(client, users)
  @client = client
  @users = users
  @logged = []
end

Instance Method Details

#clearObject

Log all users out



36
37
38
# File 'lib/sponge/auth.rb', line 36

def clear
  @logged.clear
end

#countObject

How many users we have logged in



31
32
33
# File 'lib/sponge/auth.rb', line 31

def count
  @logged.size
end

#logged_in?(user) ⇒ Boolean

Check if a user is logged in

Returns:

  • (Boolean)


26
27
28
# File 'lib/sponge/auth.rb', line 26

def logged_in?(user)
  @logged.include?(user)
end

#login(user, pass) ⇒ Object

Log a user in, returns the user if the user has successfully logged in, and nil otherwise



12
13
14
15
16
# File 'lib/sponge/auth.rb', line 12

def (user, pass)
  return unless @users.key?(user) && @users[user] == pass
  @logged.push(user).uniq!
  user
end

#logout(user) ⇒ Object

Log a user out, returns nil if the user isn’t logged in



19
20
21
22
23
# File 'lib/sponge/auth.rb', line 19

def logout(user)
  return unless logged_in?(user)
  @logged.delete(user)
  true
end