nodebb-plugin-freelog
Advanced tools
Comparing version 0.0.34 to 0.0.35
@@ -23,3 +23,2 @@ const URL = require('url').URL; | ||
function requestInterceptor(config) { | ||
console.log('开始请求' + config.url); | ||
if (!config.url.startsWith('/client')) { | ||
@@ -26,0 +25,0 @@ return config; |
108
index.js
const plugin = {}; | ||
const passport = module.parent.require('passport'); | ||
const passportLocal = module.parent.require('passport-local').Strategy; | ||
const axios = require('axios'); | ||
const userController = require.main.require('./src/controllers/user'); | ||
const User = require.main.require('./src/user'); | ||
const db = require.main.require('./src/database'); | ||
const slugify = require.main.require('./src/slugify'); | ||
const nconf = module.parent.require('nconf'); | ||
const async = module.parent.require('async'); | ||
const jwtHelper = require('./jwt-helper'); | ||
const freelogAPI = require('./api'); | ||
@@ -28,22 +24,4 @@ const nodebbAPI = require('./nodebb-login-register'); | ||
plugin.auth = async function() { | ||
}; | ||
plugin.loadHandler = async function(params) { | ||
console.log('freelog-loadHandler', JSON.stringify(params)); | ||
return params; | ||
}; | ||
plugin.authValidate = async function(param) { | ||
console.log('authValidate', param); | ||
}; | ||
// 拦截一下用户注册. | ||
plugin.userCreateFilter = async function(param) { | ||
// if (!param.data.uid) { | ||
// throw new Error('缺少uid,无法创建成功.'); | ||
// } | ||
// // 把freelog-userId赋值给nodebb-uid | ||
// param.user.uid = param.data.uid; | ||
return param; | ||
@@ -56,76 +34,20 @@ }; | ||
passReqToCallback: true | ||
}, plugin.login)); | ||
}, function(req, username, password, next) { | ||
console.log('进入代理登录接口'); | ||
if (!username) { | ||
return next(new Error('[[error:invalid-username]]')); | ||
} | ||
if (!password) { | ||
return next(new Error('[[error:invalid-password]]')); | ||
} | ||
nodebbAPI.loginOrRegister(username, password).then(nodebbUserInfo => { | ||
next(null, nodebbUserInfo, '[[success:authentication-successful]]'); | ||
}).catch(error => { | ||
console.error('登录错误', error); | ||
next(error); | ||
}); | ||
})); | ||
}; | ||
plugin.login = function(req, username, password, next) { | ||
console.log('进入代理登录接口'); | ||
if (!username) { | ||
return next(new Error('[[error:invalid-username]]')); | ||
} | ||
if (!password) { | ||
return next(new Error('[[error:invalid-password]]')); | ||
} | ||
nodebbAPI.loginOrRegister(username, password).then(nodebbUserInfo => { | ||
console.log('登录成功'); | ||
next(null, nodebbUserInfo, '[[success:authentication-successful]]'); | ||
}).catch(error => { | ||
console.error('登录错误', error); | ||
next(error); | ||
}); | ||
// | ||
// async.waterfall([ | ||
// // 登录freelog | ||
// function(callback) { | ||
// freelogAPI.getUserInfo(username, password).then(data => callback(null, data)).catch(error => callback(error)); | ||
// }, | ||
// // 根据登录信息获取nodeBB用户信息(主要根据用户名来查找) | ||
// function(userInfo, callback) { | ||
// User.getUidByUserslug(slugify(userInfo.username)).then(nodebbUid => { | ||
// callback(null, nodebbUid); | ||
// }); | ||
// }, | ||
// function(nodebbUid, callback) { | ||
// if (nodebbUid) { | ||
// callback(null, nodebbUid); | ||
// } else { | ||
// | ||
// } | ||
// }, | ||
// // 判定nodeBB用户是否已同步,如果没同步,则同步 | ||
// function(nodeUserInfo, freelogUserInfo, callback) { | ||
// if (nodeUserInfo && nodeUserInfo.uid > 0) { | ||
// callback(null, nodeUserInfo); | ||
// return; | ||
// } | ||
// User.create({ | ||
// uid: freelogUserInfo.userId, | ||
// username: freelogUserInfo.username, | ||
// password: password, | ||
// fullname: freelogUserInfo.username, | ||
// picture: freelogUserInfo.headImage | ||
// // email: freelogUserInfo.email 会报错,nodebb会校验邮箱 | ||
// }).then(() => { | ||
// User.getUserData(freelogUserInfo.userId).then(userData => { | ||
// callback(null, userData); | ||
// }).catch(error => callback(error)); | ||
// }).catch(error => callback(error)); | ||
// }, function(nodebbUserInfo, callback) { | ||
// // condition = {_key:"group:administrators:members",value:uid } | ||
// User.isAdministrator(nodebbUserInfo.uid).then(isAdmin => { | ||
// nodebbUserInfo.isAdmin = isAdmin; | ||
// callback(null, nodebbUserInfo); | ||
// }).catch(error => callback(error)); | ||
// } | ||
// ], function(error, result) { | ||
// if (error) { | ||
// next(error); | ||
// return; | ||
// } | ||
// next(null, result, '[[success:authentication-successful]]'); | ||
// }); | ||
}; | ||
function jwtLogin(token, next) { | ||
@@ -132,0 +54,0 @@ const userInfo = jwtHelper.jwtVerify(token); |
@@ -5,3 +5,3 @@ { | ||
"description": "NodeBB Forum", | ||
"version": "0.0.34", | ||
"version": "0.0.35", | ||
"homepage": "http://www.nodebb.org", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -9,6 +9,2 @@ { | ||
{ | ||
"hook": "static:app.load", | ||
"method": "loadHandler" | ||
}, | ||
{ | ||
"hook": "action:topic.reply", | ||
@@ -24,8 +20,4 @@ "method": "topicReplyHandler" | ||
"method": "userCreateFilter" | ||
}, | ||
{ | ||
"hook": "static:auth.validate", | ||
"method": "authValidate" | ||
} | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10424
232