MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / post

Method post

packages/hydrooj/src/handler/user.ts:121–141  ·  view source on GitHub ↗
(domainId: string, password = '', tfa = '', authnChallenge = '')

Source from the content-addressed store, hash-verified

119 @param('tfa', Types.String, true)
120 @param('authnChallenge', Types.String, true)
121 async post(domainId: string, password = '', tfa = '', authnChallenge = '') {
122 if (!this.session.sudoArgs?.method) throw new ForbiddenError();
123 await Promise.all([
124 this.limitRate('user_sudo', 60, 5, '{{user}}'),
125 oplog.log(this, 'user.sudo', {}),
126 ]);
127 if (this.user.authn && authnChallenge) {
128 const challenge = await token.get(authnChallenge, token.TYPE_WEBAUTHN);
129 if (challenge?.uid !== this.user._id) throw new InvalidTokenError(token.TYPE_TEXTS[token.TYPE_WEBAUTHN]);
130 if (!challenge.verified) throw new ValidationError('challenge');
131 await token.del(authnChallenge, token.TYPE_WEBAUTHN);
132 } else if (this.user.tfa && tfa) {
133 if (!verifyTFA(this.user._tfa, tfa)) throw new InvalidTokenError('2FA');
134 } else await this.user.checkPassword(password);
135 this.session.sudo = Date.now();
136 if (this.session.sudoArgs.method.toLowerCase() !== 'get') {
137 this.response.template = 'user_sudo_redirect.html';
138 this.response.body = this.session.sudoArgs;
139 } else this.response.redirect = this.session.sudoArgs.redirect;
140 this.session.sudoArgs.method = null;
141 }
142}
143
144class UserTFAHandler extends Handler {

Callers 2

commandFunction · 0.45
feedbackFunction · 0.45

Calls 7

verifyTFAFunction · 0.90
limitRateMethod · 0.80
logMethod · 0.80
checkPasswordMethod · 0.80
allMethod · 0.45
getMethod · 0.45
delMethod · 0.45

Tested by

no test coverage detected