saran-surya / email_auth

A Flutter package to verify emails using OTP
https://pub.dev/packages/email_auth
MIT License
38 stars 14 forks source link

Request for source code snippet #5

Closed rupamking1 closed 3 years ago

rupamking1 commented 3 years ago

Please share source code of- https://app-authenticator.herokuapp.com/

saran-surya commented 3 years ago

The source is a node js a server that controls the process of sending Emails, Here is a complete snippet of the Get Request process for your reference.

router.get("/auth/:mail", async (req, res)=>{
    try {
        const {mail} = req.params;
        let {CompanyName} = req.query;
        console.log(CompanyName)
        if(CompanyName == undefined || CompanyName.length <= 0){
            CompanyName = "";
        }
        if(validateEmail(mail) && mail.length > 0){
            let OTP = generateOtp();
            while(OTP in previous){
                OTP = generateOtp();
            }
            previous.push(OTP);
            if(flag){
                mailData = spawn('python', ['mailer.py', mail, OTP, CompanyName, orgMail, orgPass])
            } else {
                mailData = spawn('python', ['mailer.py', mail, OTP, CompanyName])
            }
            mailData.stdout.on('data', async (data)=>{
                const readerData = await data.toString();
                console.log(data.toString());
                if(readerData.includes('error')){
                    res.json({
                        status: 404,
                        mail: mail,
                        success: false,
                        message: "Unable to send mail"
                    })
                } else {
                    res.json({
                        status : 200,
                        mail: mail,
                        OTP: OTP,
                        success: true
                    });
                }
            })
        } else {
            res.json({
                status : 404,
                mail: mail,
                error: "The mail id is not valid",
                success: false
            });
        }
    } catch (error) {
        console.log(error.message);
        res.json({
            status : 404,
            error: "Server error",
            success : false
        });
    }
})

Hope this clarifies your needs, And also we never sell or use the mail ID's we get for any kind of business purposes, and we clean them regularly to make sure the data is not breached and to save space, I am closing this issue for now, but feel free to comment back for any other needs, and I will re open it again 👍🏻

rupamking1 commented 3 years ago

Thanks bro