nodebb-plugin-freelog
Advanced tools
Comparing version 0.0.35 to 1.0.0
52
index.js
@@ -5,5 +5,3 @@ const plugin = {}; | ||
const userController = require.main.require('./src/controllers/user'); | ||
const User = require.main.require('./src/user'); | ||
const nconf = module.parent.require('nconf'); | ||
const async = module.parent.require('async'); | ||
@@ -35,3 +33,2 @@ const freelogAPI = require('./api'); | ||
}, function(req, username, password, next) { | ||
console.log('进入代理登录接口'); | ||
if (!username) { | ||
@@ -46,3 +43,2 @@ return next(new Error('[[error:invalid-username]]')); | ||
}).catch(error => { | ||
console.error('登录错误', error); | ||
next(error); | ||
@@ -53,50 +49,2 @@ }); | ||
function jwtLogin(token, next) { | ||
const userInfo = jwtHelper.jwtVerify(token); | ||
if (!userInfo) { | ||
next(new Error('JWT校验失败')); // 一般不会出现此问题,除非能篡改JWT内容 | ||
return; | ||
} | ||
async.waterfall([ | ||
// 根据登录信息获取nodeBB用户信息 | ||
function(callback) { | ||
User.getUserData(userInfo.userId).then(userData => { | ||
callback(null, userData, userInfo); | ||
}).catch(error => callback(error)); | ||
}, | ||
// 判定nodeBB用户是否已同步,如果没同步,则同步 | ||
function(nodeUserInfo, freelogUserInfo, callback) { | ||
if (nodeUserInfo && nodeUserInfo.uid > 0) { | ||
callback(null, nodeUserInfo); | ||
return; | ||
} | ||
User.create({ | ||
uid: freelogUserInfo.userId, | ||
username: freelogUserInfo.username, | ||
password: 'password', // 填啥都无所谓,反正不用nodeBB自身的登录系统. | ||
fullname: freelogUserInfo.username, | ||
picture: 'https://image.freelog.com/headImage/' + userInfo.userId | ||
// 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]]'); | ||
}); | ||
} | ||
module.exports = plugin; |
@@ -11,2 +11,3 @@ const crypto = require('crypto'); | ||
// 后面可以改造一下,直接通过jwt自动登录. 把登录也跳转逻辑和界面重写.如果判定有jwt-cookie.直接验证之后走登录流程. | ||
module.exports.jwtVerify = function(token) { | ||
@@ -13,0 +14,0 @@ if (!token) { |
@@ -5,3 +5,3 @@ { | ||
"description": "NodeBB Forum", | ||
"version": "0.0.35", | ||
"version": "1.0.0", | ||
"homepage": "http://www.nodebb.org", | ||
@@ -8,0 +8,0 @@ "repository": { |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
8585
183