简体   繁体   English

从电子电子邮件中打开密码重置链接

[英]Open password reset link from an email in electron

Hi i have a Electron App built with React.嗨,我有一个用 React 构建的电子应用程序。 My password reset token link is sent by E-mail and that link then opens the browser to reset the users password.我的密码重置令牌链接是通过电子邮件发送的,然后该链接会打开浏览器以重置用户密码。 If possible i would like that email link to open in the electron app.如果可能,我希望在电子应用程序中打开该电子邮件链接。 Unfortuantly I havn't found anything helpful as of yet and i dont know where to even start.不幸的是,我还没有发现任何有用的东西,我什至不知道从哪里开始。 Any infomation would be greatly appreciated.任何信息将不胜感激。

this is my function sending a token link to the users email if it helps这是我的功能,如果有帮助,会向用户电子邮件发送令牌链接

app.post('/forgotPassword', async function(req, res){
    const name = req.body.name;
    const mail = req.body.email;
    crypto.randomBytes(32, (err, buffer)=>{
      if(err){
        console.log(err)
      }
      console.log(buffer)
      const token = buffer.toString("hex")
      console.log(token) 

    User.findOne({userName: name, email: mail})
      .then(user =>{
        if(!user){
          return res.json({
            status: 404,
            message: "No user found with Entered User name and email"
          })
        }
        user.resetToken = token
        user.expireToken = Date.now() + 1800000
        user.save().then((result)=>{
          transporter.sendMail({
            from: process.env.EMAIL,
            to: mail,
            subject: "Password Reset",
            html: `
              <p>Your requested password reset</p>
              <h5>Click on this <a href="http://localhost:3000/${token}">link<a/> to reset password</h5>
            `
          })
          res.json({
            status: 200,
            message: "Password Reset email Sent please check your inbox"
          })
        })
      })
    })
  })

In summary: I want the users password reset link (sent by email) to open in electron not the browser总结:我希望用户密码重置链接(通过电子邮件发送)在电子而不是浏览器中打开

Thanks in advance :)提前致谢 :)

since you want a link from the users mail client (browser, outlook, ...) to open your electron app, you have register your app as a "opener for that type of link" on the operating system level.由于您想要来自用户邮件客户端(浏览器、Outlook 等)的链接来打开您的电子应用程序,因此您已将您的应用程序注册为操作系统级别的“该类型链接的开启者”。

you might need to define a custom protocol for that like myapp://password-reset-link or something similar (because you don't want all http links to be opened with your electron app).您可能需要为myapp://password-reset-link或类似的东西定义一个自定义协议(因为您不希望所有的 http 链接都用您的电子应用程序打开)。

I have not done this myself yet, but I think this link looks promising https://glebbahmutov.com/blog/electron-app-with-custom-protocol/我自己还没有这样做,但我认为这个链接看起来很有希望https://glebbahmutov.com/blog/electron-app-with-custom-protocol/

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

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