const bcrypt = require('bcrypt'); const crypto = require('crypto'); const moment = require('moment'); const { sendMail } = require('../config/mail.config'); // π Generate OTP (panjang default 6 digit) function generateOTP(length = 6) { const digits = '0123456789'; let otp = ''; for (let i = 0; i < length; i++) { otp += digits[Math.floor(Math.random() * 10)]; } return otp; } // π€ Kirim OTP via WhatsApp atau Email async function sendOTP(type, otp, via, phone, email) { if (via === 'EMAIL') { const subject = `${type} Kode Verifikasi`; const html = `
Kode verifikasi Anda adalah:
Gunakan kode ini untuk melanjutkan proses.
`; await sendMail(email, subject, html); } else if (via === 'WHATSAPP') { // Simulasi WhatsApp - bisa diintegrasi ke API WhatsApp asli console.log(`[WhatsApp] Kirim OTP ke ${phone}: ${otp}`); // TODO: Ganti dengan pengiriman lewat API WhatsApp nyata } else { throw new Error('Metode pengiriman OTP tidak valid.'); } } // π Kirim Link Reset Password via Email const sendForgotPassword = async (email, token) => { const resetLink = `http://localhost:3000/auth/reset/${token}`; const subject = 'Reset Password'; const html = `Halo, User!
Hereβs the link to reset your Cashfio Account:
For your security, do not share the link with anyone!