Module: Wpxf::WordPress::Login
- Included in:
- Module
- Defined in:
- lib/wpxf/wordpress/login.rb
Overview
Provides functionality required to login to WordPress.
Instance Method Summary collapse
-
#valid_wordpress_cookie?(cookies) ⇒ Boolean
True if a valid WordPress cookie was found.
-
#wordpress_login(user, pass) ⇒ Array?
Log in to WordPress and return the session cookies.
-
#wordpress_login_post_body(user, pass) ⇒ String
Build a request body string for a WordPress login request.
Instance Method Details
#valid_wordpress_cookie?(cookies) ⇒ Boolean
Returns true if a valid WordPress cookie was found.
23 24 25 26 27 28 29 30 31 |
# File 'lib/wpxf/wordpress/login.rb', line 23 def () !( =~ /wordpress(?:_sec)?_logged_in_[^=]+=[^;]+;/i || # WordPress 2.0 =~ /wordpress(?:user|pass)_[^=]+=[^;]+;/i || # WordPress 2.5 =~ /wordpress_[a-z0-9]+=[^;]+;/i ).nil? end |
#wordpress_login(user, pass) ⇒ Array?
Log in to WordPress and return the session cookies.
38 39 40 41 42 43 44 45 46 |
# File 'lib/wpxf/wordpress/login.rb', line 38 def wordpress_login(user, pass) res = _execute_wp_login_request(user, pass) if res&. return res. if (res..to_s) end nil end |
#wordpress_login_post_body(user, pass) ⇒ String
Build a request body string for a WordPress login request.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/wpxf/wordpress/login.rb', line 9 def wordpress_login_post_body(user, pass) redirect = Wpxf::Utility::Text.rand_alpha(10) builder = Wpxf::Utility::BodyBuilder.new builder.add_field('log', user) builder.add_field('pwd', pass) builder.add_field('redirect_to', normalize_uri(target_uri, redirect)) builder.add_field('wp-submit', 'Login') builder.create do |body| return body end end |