Commit 448f7f5e authored by ml's avatar ml

资产管理后台-账户管理、登陆、谷歌等

parent c6a45512
......@@ -121,7 +121,7 @@ export const getInfoDetailByUserId = async (req: any, abkUserInfoVO: AbkUserInfo
/**
* 重置谷歌-生成一个新的密钥返回,保存时重新绑定谷歌
* 重置谷歌
* @param req
* @param authConfigVO
*/
......@@ -131,6 +131,9 @@ export const resetTotp = async (req: any, abkUserInfoVO: AbkUserInfoVO) => {
try {
let currentUserId = await getCurrentUserId(req.cookies.session_id);
await isSuperUser(currentUserId)
if (!abkUserInfoVO.user_id){
throw ErrorCode.PARAM_MISS;
}
let res = await abkUserService.resetAbkTotp(abkUserInfoVO.user_id);
return Res3Utils.result(res);
}
......@@ -141,6 +144,27 @@ export const resetTotp = async (req: any, abkUserInfoVO: AbkUserInfoVO) => {
};
/**
* 获取谷歌密钥-生成一个新的密钥返回
* @param req
* @param authConfigVO
*/
export const getTotp = async (req: any, abkUserInfoVO: AbkUserInfoVO) => {
let func_name = "abkUserInfo.control.resetTotp";
let cmd = req.path;
try {
let currentUserId = await getCurrentUserId(req.cookies.session_id);
await isSuperUser(currentUserId)
let res = await abkUserService.getAbkTotp(abkUserInfoVO.user_id);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
/**
* 获取用户列表
* @param req
......@@ -192,8 +216,8 @@ export const updateStatus = async (req: any, abkUserInfoPageVO: AbkUserInfoPageV
function checkPwd(pwd: string) {
let reg = /^(?=.[0-9])(?=.[A-Z])(?=.[a-z])(?=.[!@#%^&*?]).{8,12}$/;
if (!reg.test(pwd)) {
let regExp = new RegExp('^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,12}$');
if (!regExp.test(pwd)) {
throw ErrorCode.PWD_FORMAT_ERR;
}
}
......
......@@ -209,6 +209,24 @@ export async function resetAbkTotp(userId: number | undefined) {
let userInfo = await getOneAbkUserByUid(Number(userId));
ApiAssert.isNotEmpty(ErrorCode.USER_NOT_EXIST, userInfo);
}
//生成新的密钥
let totpEncrypt = Otplib.authenticator.generateSecret();
let email = userId ? userId : 0 + '-' + totpEncrypt.slice(0, 3)
let uri = 'otpauth://totp/' + email + '?secret=' + totpEncrypt + '&issuer=team888';
await abkUserInfo.prototype.update({
totp_encrypt: totpEncrypt
},
{
where: {
user_id: Number(userId)
}
});
//踢出登陆
await deleteAllAbkSessionByUserId(Number(userId));
return { uri: uri, totpEncrypt: totpEncrypt };
}
export async function getAbkTotp(userId: number | undefined) {
//生成新的密钥
let totpEncrypt = Otplib.authenticator.generateSecret();
let email = userId ? userId : 0 + '-' + totpEncrypt.slice(0, 3)
......@@ -237,12 +255,25 @@ export async function userList(abkUserInfoPageVO: AbkUserInfoPageVO, currentUser
}
export async function updateStatus(user_id: number, user_status: number, currentUserId: any) {
await getOneAbkUserByUid(user_id)
await getOneAbkUserByUid(user_id);
await updateAbkUserStatus(user_id, user_status);
//停用或删除 踢出登陆
if ([AbkUserInfoConst.USER_STATUS.STOP,AbkUserInfoConst.USER_STATUS.DEL].includes(Number(user_status))){
await deleteAllAbkSessionByUserId(user_id);
}
return 'success';
}
export async function addAbkUser(abkUserInfoVO: AbkUserInfoVO) {
let dbInfo = await abkUserInfo.prototype.findOne({
where: {
account: abkUserInfoVO.account,
},
raw: true
});
if (dbInfo){
throw ErrorCode.USER_EXIST;
}
let insertData = {
account: abkUserInfoVO.account,
pwd: abkUserInfoVO.pwd,
......
......@@ -21,6 +21,7 @@ const postFunc = {
'abkUser/getInfo': abkUserCtrl.getInfo,
'abkUser/getInfoDetailByUserId': abkUserCtrl.getInfoDetailByUserId,
'abkUser/reset/totp': abkUserCtrl.resetTotp,
'abkUser/get/totp': abkUserCtrl.getTotp,
'abkUser/list': abkUserCtrl.userList,
'abkUser/updateStatus': abkUserCtrl.updateStatus,
'abkUser/addUser': abkUserCtrl.addAbkUser,
......
......@@ -12,25 +12,18 @@ import * as ReqUtils from "../utils/req-utils"
const CLASS_NAME = "login-filter";
const ExcludeApi = {
"user/login": 1,
"user/logout": 1,
"user/login/confirm": 1,
"mUser/fee/vip/level/list": 1,
"spotPair/getAllSubmitSuccess": 1,
"coinType/getAllSubmitSuccess": 1,
'acl/role/getAll': 1,
'position/allList': 1,
'department/allList': 1,
'operate/other/business/area/list': 1,
"abkUser/login": 1,
"abkUser/logout": 1,
};
let filter = function (app: any) {
app.use(function (req, res, next) {
let path = req.originalUrl;
let pathR = req.originalUrl.replace(Config.BASE_ABK_URL,"");
try {
// Madex 管理后台的接口 跳过
if (ExcludeApi[path] || path.startsWith(Config.BASE_URL)) {
if (ExcludeApi[pathR] || path.startsWith(Config.BASE_URL)) {
next();
}
else {
......
'use strict';
import * as ReqUtils from "../utils/req-utils";
import * as pairApplyCtrl from "../functional/mvc/control/pairApply.control";
import Config from "../../config";
const {
Res3Utils,
logger: Logger,
......@@ -233,17 +232,13 @@ let cmdWhiteList = {
'tech/other/reward/time/period/get': 1,
};
//资产管理后台
let abkCmdWhiteList = {
};
let filter = function (app: any) {
app.use(function (req, res, next) {
let path = ReqUtils.parsePath(req.originalUrl);
try {
if (!cmdWhiteList[path] && !abkCmdWhiteList[path]) {
if (!cmdWhiteList[path] && !path.startsWith(Config.BASE_ABK_URL)) {
throw '3000'
}
next();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment