Created
September 2, 2015 18:19
-
-
Save wookiecooking/6e7ccb831f4a953198bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.post('/login', function(req, res) { | |
var client = xmlrpc.createClient({ host: 'https://wordpress.url/xmlrpc.php', port: 80, path: '/'}) | |
client.methodCall('external.login', [req.body.username, req.body.password], function (error, value) { | |
if(value) { | |
req.session.user_id = value; | |
res.send('success'); | |
} else { | |
res.send('Error connecting to server'); | |
} | |
}) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LOGIN VIA NODE | |
add_filter('xmlrpc_methods', 'api_login_method' ); | |
function api_login_method( $methods ) | |
{ | |
$methods['external.login'] = 'external_check_login'; | |
return $methods; | |
} | |
function external_check_login( $args ) | |
{ | |
$username = $args[0]; | |
$password = $args[1]; | |
$user = wp_authenticate( $username, $password ); | |
if( is_wp_error( $user ) ) | |
{ | |
return false; | |
} | |
return $user->id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment