Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const WPAPI = require('wpapi'),
- wp = require('./wp');
- module.exports = function(){
- return {
- findById: function(id, cb) {
- process.nextTick(function() {
- wp.users().id(id).get(function( err, data ) {
- if ( err || !data.id ) {
- cb(new Error('User ' + id + ' does not exist'));
- }
- return cb(null, data);
- });
- });
- },
- findByUsername: function(username, cb) {
- process.nextTick(function() {
- wp.users().slug(username).get(function( err, data ) {
- user = data[0];
- if ( err || !user.id ) {
- cb(new Error('User ' + username + ' does not exist'));
- }
- return cb(null, user);
- });
- });
- },
- authUser: function(username, password, cb) {
- // JUST checks if the user CAN login to WP and has a user Profile, but DOESN'T authenticate them towards it
- var testAuth;
- process.nextTick(function() {
- testAuth = new WPAPI({
- endpoint: config.auth.endpoint,
- username: username,
- password: password,
- auth: false
- });
- return testAuth.users().me().get(function( err, data ) {
- if ( err ) {
- // console.log('oh no',err.code )
- cb(new Error('Cannot authenticate ' + username + ''));
- // cb(new Error(err.code));
- }
- return cb(null, data); //the ME user data
- });
- });
- }
- }
- }();
Add Comment
Please, Sign In to add comment