mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: auto-redirect
This commit is contained in:
1 parent
a2f6d1460e
commit
b1eab219f8
3 files changed
+9
-4
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.32.33",
|
"version": "2.32.34",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -33,17 +33,18 @@ class UserLoginHandler extends Handler {
|
|||||||
@param('uname', Types.String)
|
@param('uname', Types.String)
|
||||||
@param('password', Types.String)
|
@param('password', Types.String)
|
||||||
@param('rememberme', Types.Boolean)
|
@param('rememberme', Types.Boolean)
|
||||||
async post(domainId: string, uname: string, password: string, rememberme = false) {
|
@param('redirect', Types.String, true)
|
||||||
|
async post(domainId: string, uname: string, password: string, rememberme = false, redirect = '') {
|
||||||
if (!system.get('server.login')) throw new LoginError('Builtin login disabled.');
|
if (!system.get('server.login')) throw new LoginError('Builtin login disabled.');
|
||||||
const udoc = await user.getByUname(domainId, uname);
|
const udoc = await user.getByUname(domainId, uname);
|
||||||
if (!udoc) throw new UserNotFoundError(uname);
|
if (!udoc) throw new UserNotFoundError(uname);
|
||||||
udoc.checkPassword(password);
|
udoc.checkPassword(password);
|
||||||
await user.setById(udoc._id, { loginat: new Date(), loginip: this.request.ip });
|
await user.setById(udoc._id, { loginat: new Date(), loginip: this.request.ip });
|
||||||
if (udoc.priv === PRIV.PRIV_NONE) throw new BlacklistedError(uname);
|
if (!udoc.hasPriv(PRIV.PRIV_USER_PROFILE)) throw new BlacklistedError(uname);
|
||||||
this.session.uid = udoc._id;
|
this.session.uid = udoc._id;
|
||||||
this.session.scope = PERM.PERM_ALL.toString();
|
this.session.scope = PERM.PERM_ALL.toString();
|
||||||
this.session.save = rememberme;
|
this.session.save = rememberme;
|
||||||
this.response.redirect = (this.request.referer || '/login').endsWith('/login')
|
this.response.redirect = redirect || (this.request.referer || '/login').endsWith('/login')
|
||||||
? this.url('homepage')
|
? this.url('homepage')
|
||||||
: this.request.referer;
|
: this.request.referer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -650,11 +650,15 @@ export class Handler extends HandlerCommon {
|
|||||||
logger.error(`User: ${this.user._id}(${this.user.uname}) Path: ${this.request.path}`, error.msg(), error.params);
|
logger.error(`User: ${this.user._id}(${this.user.uname}) Path: ${this.request.path}`, error.msg(), error.params);
|
||||||
if (error.stack) logger.error(error.stack);
|
if (error.stack) logger.error(error.stack);
|
||||||
}
|
}
|
||||||
|
if (this.user?._id === 0) {
|
||||||
|
this.response.redirect = this.url('user_login', { query: { redirect: this.request.path + this.ctx.search } });
|
||||||
|
} else {
|
||||||
this.response.status = error instanceof UserFacingError ? error.code : 500;
|
this.response.status = error instanceof UserFacingError ? error.code : 500;
|
||||||
this.response.template = error instanceof UserFacingError ? 'error.html' : 'bsod.html';
|
this.response.template = error instanceof UserFacingError ? 'error.html' : 'bsod.html';
|
||||||
this.response.body = {
|
this.response.body = {
|
||||||
error: { message: error.msg(), params: error.params, stack: errorMessage(error.stack) },
|
error: { message: error.msg(), params: error.params, stack: errorMessage(error.stack) },
|
||||||
};
|
};
|
||||||
|
}
|
||||||
await this.finish().catch(() => { });
|
await this.finish().catch(() => { });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user