- 新增 user_app / user_identity 模型、应用注册表与成员关系服务,启动时校验配置覆盖 - 新增微信开放平台扫码登录:二维码地址、回调与 ticket 换取 token - 管理端接口改为路由层声明 appIds + 角色鉴权,新增批量用户信息、锁定、授权与个人配置 - 删除账号同步清理成员关系与外部身份,避免关系被新账号复用 - 补充多应用、应用配置、注册表测试与迁移/建号脚本
50 lines
1.7 KiB
JavaScript
50 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
import mongoose from 'mongoose';
|
|
import { UserSchema } from "./schema/user.js"
|
|
import { UserAppSchema } from "./schema/user_app.js"
|
|
import { UserIdentitySchema } from "./schema/user_identity.js"
|
|
import config from '../conf.json' with { type: 'json' };
|
|
import logger from '../utils/logger.js';
|
|
|
|
class MongoDBSchema {
|
|
constructor() {
|
|
this.dbConnection = null;
|
|
this.User = null;
|
|
this.UserApp = null;
|
|
this.UserIdentity = null;
|
|
}
|
|
|
|
init() {
|
|
mongoose.set("debug", config.mongodb.debug);
|
|
|
|
this.dbConnection = mongoose.createConnection(config.mongodb.str, config.mongodb.option);
|
|
this.dbConnection.on("error", () => {
|
|
logger.error("...mongodb connect error ...");
|
|
});
|
|
this.dbConnection.on("connected", async () => {
|
|
logger.info(`Mongodb: ${config.mongodb.host}/${config.mongodb.option.dbName} connected`);
|
|
});
|
|
this.dbConnection.on("disconnected", () =>
|
|
logger.warn(`Mongodb: ${config.mongodb.host}/${config.mongodb.option.dbName} disconnected`)
|
|
);
|
|
this.dbConnection.on("reconnected", () =>
|
|
logger.info(`Mongodb: ${config.mongodb.host}/${config.mongodb.option.dbName} reconnected`)
|
|
);
|
|
this.dbConnection.on("disconnecting", () =>
|
|
logger.warn(`Mongodb: ${config.mongodb.host}/${config.mongodb.option.dbName} disconnecting`)
|
|
);
|
|
this.dbConnection.on("close", () =>
|
|
logger.warn(`Mongodb: ${config.mongodb.host}/${config.mongodb.option.dbName} closed`)
|
|
);
|
|
|
|
this.User = this.dbConnection.model('user', UserSchema)
|
|
this.UserApp = this.dbConnection.model('user_app', UserAppSchema)
|
|
this.UserIdentity = this.dbConnection.model('user_identity', UserIdentitySchema)
|
|
}
|
|
}
|
|
|
|
const DBModel = new MongoDBSchema()
|
|
export { DBModel };
|
|
|