添加分页功能、打包优化、ts编译优化
parent
fd85fcef74
commit
6a1f9a3f6b
@ -1,30 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
||||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
||||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
||||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
||||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
||||||
};
|
|
||||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
||||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
exports.PostAdminMemberDto = void 0;
|
|
||||||
var class_transformer_1 = require("class-transformer");
|
|
||||||
var class_validator_1 = require("class-validator");
|
|
||||||
var PostAdminMemberDto = /** @class */ (function () {
|
|
||||||
function PostAdminMemberDto() {
|
|
||||||
}
|
|
||||||
__decorate([
|
|
||||||
class_transformer_1.Expose(),
|
|
||||||
class_validator_1.IsNotEmpty({ message: '登录用户名不能为空' }),
|
|
||||||
__metadata("design:type", String)
|
|
||||||
], PostAdminMemberDto.prototype, "username", void 0);
|
|
||||||
__decorate([
|
|
||||||
class_transformer_1.Expose(),
|
|
||||||
class_validator_1.IsNotEmpty({ message: '登录密码不能为空' }),
|
|
||||||
__metadata("design:type", String)
|
|
||||||
], PostAdminMemberDto.prototype, "password", void 0);
|
|
||||||
return PostAdminMemberDto;
|
|
||||||
}());
|
|
||||||
exports.PostAdminMemberDto = PostAdminMemberDto;
|
|
@ -1,4 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
require("reflect-metadata");
|
|
||||||
require("es6-shim");
|
|
@ -0,0 +1,4 @@
|
|||||||
|
PORT=5500
|
||||||
|
GITHUB_CLIENTID=xxx
|
||||||
|
GITHUB_SECRET=xxx
|
||||||
|
AES=xxx
|
@ -0,0 +1,34 @@
|
|||||||
|
const AuthUtils = require('../utils/auth')
|
||||||
|
const { Account } = require('../entity/account')
|
||||||
|
const { getManager } = require('typeorm')
|
||||||
|
|
||||||
|
module.exports = async function (req,res,next) {
|
||||||
|
|
||||||
|
try{
|
||||||
|
const session = req.cookies.IM_SESS
|
||||||
|
|
||||||
|
if(!session) return res.error('未登录',401)
|
||||||
|
|
||||||
|
try{
|
||||||
|
var payload = AuthUtils.decode(session)
|
||||||
|
}catch(err) {
|
||||||
|
return res.error(err.message,401)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.auth_session = payload
|
||||||
|
|
||||||
|
const manager = getManager()
|
||||||
|
|
||||||
|
const detail = await manager.findOne(Account,{ aid:payload.aid })
|
||||||
|
|
||||||
|
if(!detail.isActive) return res.error('账号不可用',403)
|
||||||
|
|
||||||
|
req.account_detail = detail
|
||||||
|
}catch(err) {
|
||||||
|
console.error('登录认证中间件报错:',err);
|
||||||
|
return res.error('登录凭证已过期',401)
|
||||||
|
}
|
||||||
|
|
||||||
|
next()
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
const AuthUtils = require('../utils/auth')
|
||||||
|
const { Account } = require('../entity/account')
|
||||||
|
const { getManager } = require('typeorm')
|
||||||
|
|
||||||
|
module.exports = async function (req,res,next) {
|
||||||
|
|
||||||
|
const session = req.cookies.IM_SESS
|
||||||
|
|
||||||
|
if(!session) return res.redirect('/oauth/login')
|
||||||
|
|
||||||
|
try{
|
||||||
|
var payload = AuthUtils.decode(session)
|
||||||
|
}catch(err) {
|
||||||
|
return res.redirect('/oauth/login')
|
||||||
|
}
|
||||||
|
|
||||||
|
req.auth_session = payload
|
||||||
|
|
||||||
|
const manager = getManager()
|
||||||
|
|
||||||
|
const detail = await manager.findOne(Account,{ aid:payload.aid })
|
||||||
|
|
||||||
|
req.account_detail = detail
|
||||||
|
|
||||||
|
next()
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
const isJSON = require('is-json')
|
||||||
|
const CryptoJS = require('crypto-js')
|
||||||
|
|
||||||
|
const keyHex = process.env.AES
|
||||||
|
|
||||||
|
function encode (payload, timestamp = 0) {
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
payload,
|
||||||
|
expired_timestamp: timestamp ? timestamp + Date.now() : 0,
|
||||||
|
}
|
||||||
|
const messageHex = CryptoJS.enc.Utf8.parse(JSON.stringify(data))
|
||||||
|
var encrypted = CryptoJS.AES.encrypt(messageHex, keyHex, {
|
||||||
|
mode: CryptoJS.mode.ECB,
|
||||||
|
padding: CryptoJS.pad.Pkcs7,
|
||||||
|
})
|
||||||
|
|
||||||
|
return encrypted.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
function decode (encrypted) {
|
||||||
|
|
||||||
|
const errmsg = '登录凭证无效'
|
||||||
|
|
||||||
|
try{
|
||||||
|
var decrypt = CryptoJS.enc.Utf8.stringify(
|
||||||
|
CryptoJS.AES.decrypt(encrypted, keyHex, {
|
||||||
|
mode: CryptoJS.mode.ECB,
|
||||||
|
padding: CryptoJS.pad.Pkcs7,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
}catch(err) {
|
||||||
|
throw new Error(errmsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isJSON(decrypt)) {
|
||||||
|
throw new Error(errmsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload = JSON.parse(decrypt)
|
||||||
|
|
||||||
|
if (!payload.payload) {
|
||||||
|
throw new Error(errmsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Date.now() >= payload.expired_timestamp) {
|
||||||
|
throw new Error('登录凭证已过期')
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload.payload
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
encode,
|
||||||
|
decode
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
import { v4 as uuid } from 'uuid'
|
||||||
|
import md5 from 'md5'
|
||||||
|
|
||||||
|
export function md5_uuid ():string {
|
||||||
|
return md5(uuid())
|
||||||
|
}
|
Loading…
Reference in New Issue