簡體   English   中英

ASP.net 身份框架 - 重新發送確認電子郵件

[英]ASP.net Identity Framework - Resend Confirmation Email

我正在為我的 ASP.net 站點設置 Identity Framework (2?)。 我有確認電子郵件,但我不知道在哪里或如何允許用戶請求重新發送確認電子郵件。

我在此找到了“重新發送電子郵件確認鏈接” 這一節,但這是為 MVC 編寫的(我對此知之甚少)。

有人能指出我正確的方向或給我一些示例代碼嗎?

謝謝

我正在使用股票身份框架。

string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);

manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");

signInManager.SignIn(user, isPersistent: false, rememberBrowser: false);

嗯,結果證明這並不很痛苦。 我省略了在用戶的電話號碼字段中存儲他們上次請求的日期時間的丑陋部分。 :) 我還沒有學會如何將自定義字段添加到 aspNetUsers 表中。 使用 dateTime 我可以限制他們要求重新發送的頻率......以防他們試圖向其他人發送垃圾郵件。

    private ApplicationUser _currentUser;
    private ApplicationUserManager _manager;

    protected ApplicationUserManager Manager
    {
        get { return _manager ?? (_manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>()); }
    }

    protected ApplicationUser CurrentUser
    {
        get { return _currentUser ?? (_currentUser = Manager.FindById(User.Identity.GetUserId())); }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (CurrentUser == null || !User.Identity.IsAuthenticated)
        {
            Response.Redirect("~/account/register.aspx");
        }
        else if (User.Identity.IsAuthenticated && CurrentUser.EmailConfirmed)
        {
            alreadyConfirmed.Visible = true;
        }
        else if (!minTimeElapsedSinceLastRequest())
        {
            NotEnoughTimeLiteral.Text = "A resend occurred on " + CurrentUser.PhoneNumber + ". Please wait longer before your next request";
            notEnoughTimeFlag.Visible = true;
        }
        else
        {
            idResendButton.Enabled = true;
        }
    }

    protected void ResendConfirmationEmailClick(object sender, EventArgs e)
    {
        string currentUserId = User.Identity.GetUserId();

        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
        string code = Manager.GenerateEmailConfirmationToken(currentUserId);
        string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, currentUserId, Request);

        Manager.SendEmail(currentUserId, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");
        setUsersLastResendDateTime(CurrentUser);
        IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
    }

再次發送確認電子郵件添加到身份框架ASP.NET核心2 *和3 *您應該通過凈CLI或Visual Studio腳手架任所示的代碼在這里

這是在visual studio中的做法。

  • 在 Visual Studio 中右鍵單擊項目名稱並選擇添加>新建腳手架項目>身份。
  • 按覆蓋所有文件,然后單擊添加。 這會添加最新的 nuget 包。 在撰寫此線程時,它們是 Identity.EntityFramworkCore v3.1.3、Identity.UI v3.1.3
  • 進入登錄頁面。
  • 您可以找到重新發送電子郵件確認鏈接
  • 從 ResendEmailConfirmationModel 類中刪除抽象

您可以在 Manage 控制器中使用SendVerificationEmail

有關更多信息,請查看此鏈接https://github.com/aspnet/AspNetCore/issues/5410

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM