mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
remove domain system
This commit is contained in:
1 parent
7fa4a58abe
commit
fc26af30ef
31 files changed
+709
-1242
No files matched your search
+2
-25
@@ -1,20 +1,17 @@
|
||||
const
|
||||
{ MIDDLEWARE } = require('../service/server.js'),
|
||||
user = require('../model/user'),
|
||||
domain = require('../model/domain'),
|
||||
blacklist = require('../model/blacklist'),
|
||||
token = require('../model/token'),
|
||||
options = require('../options'),
|
||||
{
|
||||
UserNotFoundError,
|
||||
BlacklistedError,
|
||||
PermissionError,
|
||||
PrivilegeError
|
||||
PermissionError
|
||||
} = require('../error');
|
||||
|
||||
MIDDLEWARE(async (ctx, next) => {
|
||||
try {
|
||||
ctx.state.domainId = 'system';
|
||||
let sid = ctx.cookies.get('sid');
|
||||
let save = ctx.cookies.get('save');
|
||||
let tokenType, expireSeconds;
|
||||
@@ -33,11 +30,7 @@ MIDDLEWARE(async (ctx, next) => {
|
||||
if (!ctx.session) ctx.session = { uid: 1 };
|
||||
let bdoc = await blacklist.get(ctx.request.ip);
|
||||
if (bdoc) throw new BlacklistedError(ctx.request.ip);
|
||||
console.log(ctx.session.uid);
|
||||
[ctx.state.user, ctx.state.domain] = await Promise.all([
|
||||
user.getById(ctx.session.uid, ctx.state.domainId),
|
||||
domain.get(ctx.state.domainId)
|
||||
]);
|
||||
ctx.state.user = await user.getById(ctx.session.uid);
|
||||
if (!ctx.state.user) throw new UserNotFoundError(ctx.session.uid);
|
||||
ctx.checkPerm = function (perm) {
|
||||
for (let i in arguments) {
|
||||
@@ -55,22 +48,6 @@ MIDDLEWARE(async (ctx, next) => {
|
||||
}
|
||||
}
|
||||
};
|
||||
ctx.checkPriv = function (priv) {
|
||||
for (let i in arguments) {
|
||||
if (arguments[i] instanceof Array) {
|
||||
let p = false;
|
||||
for (let j in arguments)
|
||||
if (ctx.state.user.hasPriv(arguments[i][j])) {
|
||||
p = true;
|
||||
break;
|
||||
}
|
||||
if (!p) throw new PrivilegeError([arguments[i]]);
|
||||
} else {
|
||||
if (ctx.state.user.hasPriv(arguments[i])) continue;
|
||||
else throw new PrivilegeError([[arguments[i]]]);
|
||||
}
|
||||
}
|
||||
};
|
||||
await next();
|
||||
if (ctx.session.sid)
|
||||
await token.update(ctx.session.sid, tokenType, expireSeconds, Object.assign({
|
||||
|
||||
Reference in new issue
Block a user