Skip to content

Instantly share code, notes, and snippets.

@wookiecooking
Created September 2, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wookiecooking/6e7ccb831f4a953198bb to your computer and use it in GitHub Desktop.
Save wookiecooking/6e7ccb831f4a953198bb to your computer and use it in GitHub Desktop.
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');
}
})
});
// 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