Method: ChatBot#site_auth

Defined in:
lib/chatx/auth.rb

#site_auth(site) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chatx/auth.rb', line 29

def site_auth(site)
  # Get fkey
   = @agent.get "https://#{site}.com/users/login"
  fkey_input = .search "//input[@name='fkey']"
  fkey = fkey_input.attribute('value')

  @agent.post("https://#{site}.com/users/authenticate",
              fkey: fkey,
              openid_identifier: 'https://openid.stackexchange.com')

  home = @agent.get "https://chat.#{site}.com"
  if home.search(".topbar-links span.topbar-menu-links a").first.text.casecmp('log in').zero?
    @logger.warn "Login to #{site} failed :("
    false
  else
    @logger.info "Login to #{site} successful!"
    true
  end
end