Skip to content

Instantly share code, notes, and snippets.

@wookiecooking
Created September 2, 2015 18:19
Show Gist options
  • Save wookiecooking/6e7ccb831f4a953198bb to your computer and use it in GitHub Desktop.
Save wookiecooking/6e7ccb831f4a953198bb to your computer and use it in GitHub Desktop.

Revisions

  1. wookiecooking created this gist Sep 2, 2015.
    11 changes: 11 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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');
    }
    })
    });
    23 changes: 23 additions & 0 deletions gistfile2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@

    // 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;
    }