HEX
Server: Apache
System: Linux srv4.garantili.com.tr 4.18.0-477.21.1.lve.1.el8.x86_64 #1 SMP Tue Sep 5 23:08:35 UTC 2023 x86_64
User: ekspardev (1006)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/ekspardev/tubisad-backend/src/app/sms-verification/controller/sms-verification.controller.js
const { emptyDirSync } = require("fs-extra");
const { mainMessageBody } = require("../constants/send-sms.const");
const SMSVerificationModel = require("../model/save-verification-code.model");

const axios = require('axios');

exports.sendSMS = async (req, res) => {
    const phone = req.body.phone;

    if (phone) {
        //*GENERATE RANDOM CODE
        const code = Math.floor(Math.random() * 9999) + 1000

        await SMSVerificationModel.create({ phone: phone, code: code });

        const config = {
            method: 'post',
            url: 'https://processor.smsorigin.com/xml/process.aspx',
            headers: {
                'Content-Type': 'application/xml'
            },
            data: mainMessageBody(code, phone)
        };

        await axios(config)
            .then((response) => {
                return res.status(200).json({ message: 'success' });
            })
            .catch(function (error) {
                console.log(error);
            });
    }
};

exports.verification = async (req, res) => {
    const { phoneNumber, code } = req.body;

    if (phoneNumber && code) {
        const verification = await SMSVerificationModel.findOne({ where: { phone: phoneNumber, code: code } });

        if (verification) {
            return res.status(200).json({ success: true, status: true, data: verification });
        } else {
            return res.status(200).json({ success: true, status: false, data: 'Kod Bulunamadı!' });
        }
    } else {
        return res.status(200).json({ success: false, status: false, data: 'Hata Oluştu!' });
    }
};