mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: sudo mode: save referer
This commit is contained in:
1 parent
bb3351b212
commit
c4440be61d
2 files changed
+9
-4
No files matched your search
@@ -142,14 +142,14 @@ class UserLoginHandler extends Handler {
|
|||||||
|
|
||||||
class UserSudoHandler extends Handler {
|
class UserSudoHandler extends Handler {
|
||||||
async get() {
|
async get() {
|
||||||
if (!this.session.sudoArgs) throw new ForbiddenError();
|
if (!this.session.sudoArgs?.method) throw new ForbiddenError();
|
||||||
this.response.template = 'user_sudo.html';
|
this.response.template = 'user_sudo.html';
|
||||||
}
|
}
|
||||||
|
|
||||||
@param('password', Types.String)
|
@param('password', Types.String)
|
||||||
@param('tfa', Types.String, true)
|
@param('tfa', Types.String, true)
|
||||||
async post(domainId: string, password: string, tfa = '') {
|
async post(domainId: string, password: string, tfa = '') {
|
||||||
if (!this.session.sudoArgs) throw new ForbiddenError();
|
if (!this.session.sudoArgs?.method) throw new ForbiddenError();
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this.limitRate('user_sudo', 60, 5, true),
|
this.limitRate('user_sudo', 60, 5, true),
|
||||||
oplog.log(this, 'user.sudo', {}),
|
oplog.log(this, 'user.sudo', {}),
|
||||||
@@ -163,8 +163,8 @@ class UserSudoHandler extends Handler {
|
|||||||
if (this.session.sudoArgs.method.toLowerCase() !== 'get') {
|
if (this.session.sudoArgs.method.toLowerCase() !== 'get') {
|
||||||
this.response.template = 'user_sudo_redirect.html';
|
this.response.template = 'user_sudo_redirect.html';
|
||||||
this.response.body = this.session.sudoArgs;
|
this.response.body = this.session.sudoArgs;
|
||||||
this.session.sudoArgs = null;
|
|
||||||
} else this.response.redirect = this.session.sudoArgs.redirect;
|
} else this.response.redirect = this.session.sudoArgs.redirect;
|
||||||
|
this.session.sudoArgs.method = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +197,10 @@ export class UserRegisterHandler extends Handler {
|
|||||||
if (await user.getByEmail('system', mail)) throw new UserAlreadyExistError(mail);
|
if (await user.getByEmail('system', mail)) throw new UserAlreadyExistError(mail);
|
||||||
const mailDomain = mail.split('@')[1];
|
const mailDomain = mail.split('@')[1];
|
||||||
if (await BlackListModel.get(`mail::${mailDomain}`)) throw new BlacklistedError(mailDomain);
|
if (await BlackListModel.get(`mail::${mailDomain}`)) throw new BlacklistedError(mailDomain);
|
||||||
await this.limitRate('send_mail', 3600, 30);
|
await Promise.all([
|
||||||
|
this.limitRate('send_mail', 3600, 30),
|
||||||
|
oplog.log(this, 'user.register', {}),
|
||||||
|
]);
|
||||||
const t = await token.add(
|
const t = await token.add(
|
||||||
token.TYPE_REGISTRATION,
|
token.TYPE_REGISTRATION,
|
||||||
system.get('session.unsaved_expire_seconds'),
|
system.get('session.unsaved_expire_seconds'),
|
||||||
|
|||||||
@@ -216,10 +216,12 @@ export function requireSudo(target: any, funcName: string, obj: any) {
|
|||||||
const originalMethod = obj.value;
|
const originalMethod = obj.value;
|
||||||
obj.value = function sudo(this: Handler, ...args: any[]) {
|
obj.value = function sudo(this: Handler, ...args: any[]) {
|
||||||
if (this.session.sudo && Date.now() - this.session.sudo < Time.hour) {
|
if (this.session.sudo && Date.now() - this.session.sudo < Time.hour) {
|
||||||
|
this.request.headers.referer = this.session.sudoArgs.referer;
|
||||||
return originalMethod.call(this, ...args);
|
return originalMethod.call(this, ...args);
|
||||||
}
|
}
|
||||||
this.session.sudoArgs = {
|
this.session.sudoArgs = {
|
||||||
method: this.request.method,
|
method: this.request.method,
|
||||||
|
referer: this.request.headers.referer,
|
||||||
args: this.args,
|
args: this.args,
|
||||||
redirect: this.request.path,
|
redirect: this.request.path,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user