简体   繁体   English

节点 JS 和 Angular Email 验证:无论如何要发送 html 作为响应?

[英]Node JS and Angular Email Verification: Anyway to send html in a response?

To start off, I do want to clarify that I know how to use APi's created in NodeJS in Angular.首先,我想澄清一下,我知道如何在 Angular 中使用在 NodeJS 中创建的 APi。 The problem I have is a little tricky.我遇到的问题有点棘手。

I have a function that verifies the email used in registering:我有一个 function 验证 email 用于注册:

exports.confirmEmail = function (req, res) {
    ConfirmToken.findOne({
        token: req.params.token
    }, function (err, token) {

        if (err) {
            return res.status(500).send({
                message: "Internal Server Error " + err
            })
        }

        // token is not found into database i.e. token may have expired 
        if (!token) {
            return res.status(400).send({
                message: 'Your verification link may have expired. Please click on resend for verify your Email.'
            });
        }
        // if token is found then check valid user 
        else {
            Account.findOne({
                _id: token._accountId,
                email: req.params.email
            }, function (err, user) {

                if (err) {
                    return res.status(500).send({
                        message: "Internal Server Error " + err
                    })
                }
                // User does not exist
                if (!user) {
                    return res.status(401).send({
                        message: 'The account does not exist'
                    });
                }
                // user is already verified
                else if (user.isVerified) {
                    return res.status(200).send('User has been already verified. Please Login');
                }
                // verify user
                else {
                    // change isVerified to true
                    user.isVerified = true;
                    user.save(function (err) {
                        // error occur
                        if (err) {
                            return res.status(500).send({
                                message: err.message
                            });
                        }
                        // account successfully verified
                        else {
                            return res.status(200).send('Your account has been successfully verified');
                        }
                    });
                }
            });
        }

    })
}

This is the response I get when I register an account这是我注册账号时得到的回复注册后

Now my question is: is there a way to pass in html code or have it show in a custom Angular component instead of displaying as simple plain text on the web browser as such现在我的问题是:有没有办法传入 html 代码或让它显示在自定义 Angular 组件中,而不是像这样在 web 浏览器上显示为简单的纯文本

单击验证电子邮件后的响应

Your service should send a isVerified status back to the client.您的服务应将 isVerified 状态发送回客户端。 You are sending only a string at the moment您目前只发送一个字符串

return res.status(200).send('Your account has been successfully verified');

based on this status, let's call it, isVerified your angular app would render a isVerfiedComponent.ts or notVerifiedComponent.ts基于此状态,我们称之为isVerified您的 angular 应用程序将呈现 isVerfiedComponent.ts 或 notVerifiedComponent.ts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM