Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

c# - .Net Core Forgot password not found

I am following the tutortial for .Net core Account and password recovery and I am not sure how things work. The tutorial says to add the email service in startup.cs then everything just started to work. I have no idea where the forgot password page is located, it not with the other pages, I checked hidden files and the actual directory it self (see image), yet I am being redirected there from the reset password link. I have no idea how the email service is being called yet I can set a break point and see that it is being hit with the correct data. I can see the sql query used to get the user information. Is this functionality managed by core identity?

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have no idea where the forgot password page is located, it not with the other pages

You need Scaffold Identity in your ASP.NET Core project.

  1. That means you need to add the pages you need through Scaffold Identity: ForgotPassword, ForgotPasswordConfirmation, ResetPassword, ResetPasswordConfirmation.
  2. Scaffold Identity in ASP.NET Core projects

I have no idea how the email service is being called yet I can set a break point and see that it is being hit with the correct data.

Is this functionality managed by core identity?

IEmailSender is in the package ASP.NET Core Identity.UI, with the default implementation injected in DI that doesn't do anything.

I will explain in detail below how to send an email to reset the password. You can read the process of resetting the password first to the last.

  1. In other words, you need to Implement IEmailSender.

  2. In the link you gave, it has been given in detail how to implement IEmailSender.

  3. In the example, SendGrid email provider is used. You can also choose other email providers.

    1. You need to register a SendGrid account first, then create an API Key, and store your SendGrid information in appsettings.json.
      • You can create an API Key as follows.
      • enter image description here
    2. appsettings.json:
      1. SendGridUser:
        • It’s the account you registered with SendGird. For example, I registered with the email xxx.test.com, and SendGridUser is xxx.test.com.
      2. SendGridKey:
        • This is the API Key mentioned above.
      {
        ... ...
        "AllowedHosts": "*",
        "SendGridUser": "xxxx",
        "SendGridKey": "xxxxx"
      }
      
  4. The process of resetting the password can be briefly summarized as follows:

    1. Request the ForgotPassword page after clicking the link to reset the password
    2. Enter your email address to reset the password
    3. If the email address you need to reset your password exists and has been confirmed, then the method OnPostAsync in ForgotPassword will send an email to your email address.
      • If you set a breakpoint in the Execute method in the implementation class EmailSender of IEmailSender, you can see the result of the email sent.
    4. You can open your mailbox to see the link to reset the password you received, then enter the reset password and submit the form.
    5. After the form is successfully submitted, it will request the OnPostAsync method of ResetPassword, and the processing will be redirected to the ResetPasswordConfirmation page.
  5. Result

    enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...