@@ -9,6 +9,7 @@ class Module
99 include Wpxf ::WordPress ::Login
1010 include Wpxf ::WordPress ::Options
1111 include Wpxf ::WordPress ::Urls
12+ include Wpxf ::ModuleAuthentication
1213
1314 def initialize
1415 super
@@ -31,29 +32,9 @@ def initialize
3132 )
3233 ] )
3334
34- if requires_authentication
35- register_options ( [
36- StringOption . new (
37- name : 'username' ,
38- desc : 'The WordPress username to authenticate with' ,
39- required : true
40- ) ,
41- StringOption . new (
42- name : 'password' ,
43- desc : 'The WordPress password to authenticate with' ,
44- required : true
45- )
46- ] )
47- end
48-
4935 self . event_emitter = EventEmitter . new
5036 end
5137
52- # @return [Boolean] true if the module requires the user to authenticate.
53- def requires_authentication
54- false
55- end
56-
5738 # @return [Boolean] true if all the required options are set.
5839 def can_execute?
5940 all_options_valid? && (
@@ -93,11 +74,8 @@ def set_option_value(name, value)
9374 res = super ( name , value )
9475
9576 if payload
96- if res == :not_found
97- return payload . set_option_value ( name , value )
98- else
99- payload . set_option_value ( name , value )
100- end
77+ return payload . set_option_value ( name , value ) if res == :not_found
78+ payload . set_option_value ( name , value )
10179 end
10280
10381 res
@@ -110,23 +88,6 @@ def unset_option(name)
11088 payload . unset_option ( name ) if payload
11189 end
11290
113- # Authenticate with WordPress and return the cookie.
114- # @param username [String] the username to authenticate with.
115- # @param password [String] the password to authenticate with.
116- # @return [CookieJar, Boolean] the cookie in a CookieJar if successful,
117- # otherwise, returns false.
118- def authenticate_with_wordpress ( username , password )
119- emit_info "Authenticating with WordPress using #{ username } :#{ password } ..."
120- cookie = wordpress_login ( username , password )
121- if cookie . nil?
122- emit_error 'Failed to authenticate with WordPress'
123- return false
124- else
125- emit_success 'Authenticated with WordPress' , true
126- return cookie
127- end
128- end
129-
13091 # Run the module.
13192 # @return [Boolean] true if successful.
13293 def run
0 commit comments