feat(auth): add MizbanSMS OTP provider with per-flow messages and signup recovery

- Add MizbanSMS as selectable SMS provider (SMS_PROVIDER), keep Kavenegar
- Distinct OTP wording per flow via OtpMessageKind (register/login/change-phone)
- register() resumes an unverified account instead of blocking re-registration
- Hourly cleanup of abandoned unverified accounts (>24h) + expired OTP codes

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
keyhan
2026-06-17 17:44:58 +03:30
parent 7d7971744e
commit fc3d0a7e04
6 changed files with 265 additions and 33 deletions
+28 -1
View File
@@ -84,10 +84,37 @@ export default () => ({
port: parseInt(process.env.REDIS_PORT || '6379', 10),
},
// OTP SMS via Kavenegar (verify/lookup template API).
// OTP SMS. Provider selectable via SMS_PROVIDER ('mizbansms' | 'kavenegar').
sms: {
provider: (process.env.SMS_PROVIDER || 'mizbansms').trim().toLowerCase(),
// Kavenegar (verify/lookup template API) — kept for fallback.
kavenegarApiKey: process.env.KAVENEGAR_API_KEY || '',
kavenegarOtpTemplate: process.env.KAVENEGAR_OTP_TEMPLATE || '',
// MizbanSMS (services.mizbansms.com) — sends full message text over a
// dedicated line, so the OTP wording is composed here, not from a template.
mizban: {
baseUrl: process.env.MIZBANSMS_BASE_URL || 'http://services.mizbansms.com',
username: process.env.MIZBANSMS_USERNAME || '',
password: process.env.MIZBANSMS_PASSWORD || '',
from: process.env.MIZBANSMS_FROM || '5000467254',
api: parseInt(process.env.MIZBANSMS_API || '2016', 10),
userType: parseInt(process.env.MIZBANSMS_USERTYPE || '2', 10),
// Per-message-kind wording. `{code}` (or `{{CODE}}`) is replaced with the
// 6-digit OTP. \n is allowed for multi-line messages.
templates: {
register:
process.env.MIZBANSMS_OTP_TEMPLATE_REGISTER ||
'به ابربان خوش آمدید.\nکد تأیید شما: {code}',
login:
process.env.MIZBANSMS_OTP_TEMPLATE_LOGIN ||
'رمز یکبار مصرف ابربان:\n{code}',
changePhone:
process.env.MIZBANSMS_OTP_TEMPLATE_CHANGE_PHONE ||
'کد تأیید شماره جدید ابربان:\n{code}',
},
},
},
registry: {