Module: Leech::Handlers::Auth::ServerMethods

Defined in:
lib/leech/handlers/auth.rb

Instance Method Summary collapse

Instance Method Details

#authorize(passcode) ⇒ Object

Authorize client session using simple passcode.

Parameters:

  • passcode (String)

    Password sent by client



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/leech/handlers/auth.rb', line 27

def authorize(passcode)
  if options[:passcode].to_s.strip == passcode.to_s.strip
    Thread.current[:authorized] = true
    answer("AUTHORIZED\n")
    logger.info("Client #{info[:uri]} authorized")
  else
    Thread.current[:authorized] = false
    answer("UNAUTHORIZED\n")
    logger.info("Client #{info[:uri]} unauthorized: invalid passcode")
  end
end

#authorized?Boolean

Returns Is client session authorized?.

Returns:

  • (Boolean)

    Is client session authorized?



41
42
43
# File 'lib/leech/handlers/auth.rb', line 41

def authorized?
  !!Thread.current[:authorized]
end