mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: update sms logic
This commit is contained in:
1 file changed
+7
-4
@@ -1,6 +1,7 @@
|
|||||||
import { generateAuthenticationOptions, verifyAuthenticationResponse } from '@simplewebauthn/server';
|
import { generateAuthenticationOptions, verifyAuthenticationResponse } from '@simplewebauthn/server';
|
||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
import type { Binary } from 'mongodb';
|
import type { Binary } from 'mongodb';
|
||||||
|
import { Time } from '@hydrooj/utils';
|
||||||
import {
|
import {
|
||||||
AuthOperationError, BlacklistedError, BuiltinLoginError, ForbiddenError, InvalidTokenError,
|
AuthOperationError, BlacklistedError, BuiltinLoginError, ForbiddenError, InvalidTokenError,
|
||||||
SystemError, UserAlreadyExistError, UserFacingError,
|
SystemError, UserAlreadyExistError, UserFacingError,
|
||||||
@@ -264,13 +265,15 @@ export class UserRegisterHandler extends Handler {
|
|||||||
} else if (phoneNumber) {
|
} else if (phoneNumber) {
|
||||||
if (!global.Hydro.lib.sendSms) throw new SystemError('Cannot send sms');
|
if (!global.Hydro.lib.sendSms) throw new SystemError('Cannot send sms');
|
||||||
await this.limitRate('send_sms', 60, 3);
|
await this.limitRate('send_sms', 60, 3);
|
||||||
const t = await token.add(
|
const id = String.random(6, '0123456789');
|
||||||
|
await token.add(
|
||||||
token.TYPE_REGISTRATION,
|
token.TYPE_REGISTRATION,
|
||||||
system.get('session.unsaved_expire_seconds'),
|
10 * Time.minute,
|
||||||
{ phone: phoneNumber },
|
{ phone: phoneNumber },
|
||||||
String.random(6),
|
id,
|
||||||
);
|
);
|
||||||
await global.Hydro.lib.sendSms(phoneNumber, 'register', t[0]);
|
await global.Hydro.lib.sendSms(phoneNumber, 'register', id);
|
||||||
|
this.response.body = { phone: phoneNumber };
|
||||||
this.response.template = 'user_register_sms.html';
|
this.response.template = 'user_register_sms.html';
|
||||||
} else throw new ValidationError('mail');
|
} else throw new ValidationError('mail');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user