Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nodebb-plugin-freelog

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodebb-plugin-freelog - npm Package Compare versions

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;

1

jwt-helper.js

@@ -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": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc