module Wpxf::ModuleAuthentication

Provides functionality for authenticating modules with a WordPress target.

Public Class Methods

new() click to toggle source

Initialize a new instance of {ModuleAuthentication}.

Calls superclass method
# File lib/wpxf/core/module_authentication.rb, line 7
def initialize
  super
  return unless requires_authentication

  register_options([
    StringOption.new(
      name: 'username',
      desc: 'The WordPress username to authenticate with',
      required: true
    ),
    StringOption.new(
      name: 'password',
      desc: 'The WordPress password to authenticate with',
      required: true
    )
  ])
end

Public Instance Methods

authenticate_with_wordpress(username, password) click to toggle source

Authenticate with WordPress and return the cookie. @param username [String] the username to authenticate with. @param password [String] the password to authenticate with. @return [CookieJar, Boolean] the cookie in a CookieJar if successful,

otherwise, returns false.
# File lib/wpxf/core/module_authentication.rb, line 35
def authenticate_with_wordpress(username, password)
  emit_info "Authenticating with WordPress using #{username}:#{password}..."
  cookie = wordpress_login(username, password)
  if cookie.nil?
    emit_error 'Failed to authenticate with WordPress'
    return false
  else
    store_credentials username, password
    emit_success 'Authenticated with WordPress', true
    return cookie
  end
end
requires_authentication() click to toggle source

@return [Boolean] true if the module requires the user to authenticate.

# File lib/wpxf/core/module_authentication.rb, line 26
def requires_authentication
  false
end