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

Method post

packages/hydrooj/src/handler/user.ts:349–373  ·  view source on GitHub ↗
(domainId: string, mail: string)

Source from the content-addressed store, hash-verified

347
348 @param('mail', Types.Email)
349 async post(domainId: string, mail: string) {
350 if (!system.get('smtp.user')) throw new SystemError('Cannot send mail');
351 const udoc = await user.getByEmail('system', mail);
352 if (!udoc) throw new UserNotFoundError(mail);
353 await Promise.all([
354 this.limitRate('send_mail', 3600, 30),
355 this.limitRate('send_mail', 60, 1, mail),
356 oplog.log(this, 'user.lostpass', {}),
357 ]);
358 const [tid] = await token.add(
359 token.TYPE_LOSTPASS,
360 system.get('session.unsaved_expire_seconds'),
361 { uid: udoc._id },
362 );
363 const prefix = this.domain.host
364 ? `${this.domain.host instanceof Array ? this.domain.host[0] : this.domain.host}`
365 : system.get('server.url');
366 const m = await this.renderHTML('user_lostpass_mail.html', {
367 url: `/lostpass/${tid}`,
368 url_prefix: prefix.endsWith('/') ? prefix.slice(0, -1) : prefix,
369 uname: udoc.uname,
370 });
371 await sendMail(mail, 'Lost Password', 'user_lostpass_mail', m.toString());
372 this.response.template = 'user_lostpass_mail_sent.html';
373 }
374}
375
376class UserLostPassWithCodeHandler extends Handler {

Callers

nothing calls this directly

Calls 8

sendMailFunction · 0.90
getByEmailMethod · 0.80
limitRateMethod · 0.80
logMethod · 0.80
renderHTMLMethod · 0.80
getMethod · 0.45
allMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected