Module: Rodbot::Plugins::Otp::App::RequestMethods

Includes:
Memoize
Defined in:
lib/rodbot/plugins/otp/app.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Memoize

included

Class Method Details

.argumentsObject



14
# File 'lib/rodbot/plugins/otp/app.rb', line 14

def self.arguments = params['arguments'].sub(/\s*\d{6}\s*\z/, '')

Instance Method Details

#require_valid_otp!Object



22
23
24
# File 'lib/rodbot/plugins/otp/app.rb', line 22

def require_valid_otp!
  halt [401, {}, ['Unauthorized']] unless valid_otp?
end

#valid_otp?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
# File 'lib/rodbot/plugins/otp/app.rb', line 13

def valid_otp?
  def self.arguments = params['arguments'].sub(/\s*\d{6}\s*\z/, '')
  return false unless password
  return false if Rodbot.db.get(:otp, password)   # already used
  !!if totp.verify(password, drift_behind: Rodbot.config(:otp, :drift).to_i)
    Rodbot.db.set(:otp, password) { true }
  end
end