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

Method post

packages/hydrooj/src/handler/user.ts:314–338  ·  view source on GitHub ↗
(
        domainId: string, password: string, verify: string,
        uname = '', code: string,
    )

Source from the content-addressed store, hash-verified

312 @param('uname', Types.Username, true)
313 @param('code', Types.String)
314 async post(
315 domainId: string, password: string, verify: string,
316 uname = '', code: string,
317 ) {
318 const provider = this.ctx.oauth.providers[this.tdoc.identity.provider];
319 if (!provider) throw new SystemError(`OAuth provider ${this.tdoc.identity.provider} not found`);
320 if (provider.lockUsername) uname = this.tdoc.identity.username;
321 if (!Types.Username[1](uname)) throw new ValidationError('uname');
322 if (password !== verify) throw new VerifyPasswordError();
323 const randomEmail = `${randomstring(12)}@invalid.local`; // some random email to remove in the future
324 const uid = await user.create(this.tdoc.mail || randomEmail, uname, password, undefined, this.request.ip);
325 await token.del(code, token.TYPE_REGISTRATION);
326 const [id, mailDomain] = this.tdoc.mail.split('@');
327 const $set: any = this.tdoc.set || {};
328 if (mailDomain === 'qq.com' && !Number.isNaN(+id)) {
329 $set.avatar = `qq:${id}`;
330 $set.qq = `${id}`;
331 }
332 if (this.session.viewLang) $set.viewLang = this.session.viewLang;
333 if (Object.keys($set).length) await user.setById(uid, $set);
334 if (Object.keys(this.tdoc.setInDomain || {}).length) await domain.setUserInDomain(domainId, uid, this.tdoc.setInDomain);
335 await this.ctx.oauth.set(this.tdoc.identity.platform, this.tdoc.identity.id, uid);
336 await successfulAuth.call(this, await user.getById(domainId, uid));
337 this.response.redirect = this.tdoc.redirect || this.url('home_settings', { category: 'preference' });
338 }
339}
340
341class UserLostPassHandler extends Handler {

Callers

nothing calls this directly

Calls 8

randomstringFunction · 0.90
createMethod · 0.80
setByIdMethod · 0.80
setUserInDomainMethod · 0.80
getByIdMethod · 0.80
urlMethod · 0.80
delMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected