Sha256: f31dd6d27ce6aecb80cf76ffb2eff0c604e9d725d726b3231e3c23afc4a33277
Contents?: true
Size: 1.52 KB
Versions: 2
Compression:
Stored size: 1.52 KB
Contents
module WpWrapper module Modules module Authorization def login(retries = 3) success = logged_in? if (!success && retries > 0) login_page = self.mechanize_client.open_url(get_url(:admin)) agent = self.mechanize_client.agent if (login_page) login_form = login_page.form_with(:name => 'loginform') if (login_form) login_form.field_with(:name => 'log').value = self.username login_form.field_with(:name => 'pwd').value = self.password begin logged_in_page = login_form.submit log_out_link = logged_in_page.link_with(:href => /wp-login\.php\?action=logout/i) self.logged_in = !log_out_link.nil? success = self.logged_in puts "#{Time.now}: Url: #{self.url}. Successfully logged in? #{self.logged_in}" rescue Exception => e puts "#{Time.now}: Url: #{self.url}. Failed to login. Error Class: #{e.class.name}. Error Message: #{e.message}" login(retries - 1) if (retries > 0) end else puts "\n\n#{Time.now}: Url: #{self.url}. Something's broken! Can't find wp-admin login form! Retrying...\n\n" login(retries - 1) if (retries > 0) end end end return success end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wp_wrapper-0.0.3 | lib/wp_wrapper/modules/authorization.rb |
wp_wrapper-0.0.2 | lib/wp_wrapper/modules/authorization.rb |