4

내 ASP.net 사이트에 대해 Identity Framework (2?)를 설정하고 있습니다. 확인 전자 메일이 작동하지만 사용자가 확인 전자 메일을 다시 보낼 것을 요청할 수있는 위치와 방법을 파악할 수 없습니다.ASP.net Identity Framework - 확인 재전송 전자 메일

이 섹션의 '이메일 확인 링크 재발송'은 this에 있지만 MVC 용으로 작성되었습니다 (별로 모르겠다).

누군가 올바른 방향으로 나를 가리키거나 샘플 코드를 던져 주시겠습니까?

감사합니다.

저는 Identity Identity Framework를 사용하고 있습니다.

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); 
+0

코드를 명확하게 표시 할 수 있습니까? 사이트에 등록 할 때 이메일로 확인합니까? 양식 인증을 사용하고 있습니까? – DaniDev

+0

@DaniDev. 주식 코드에서 발췌 문장을 추가했습니다. 그러나 그것이 처음 등록 할 때 전자 메일이 전송되는 곳입니다. 비슷한 전화를 사용하여 내 페이지를 만드는 것이 안전합니까? –

+1

필수 오브젝트 인 Identityhelper, signinManager를 호출 할 수 있어야합니다. 또한 'code'매개 변수 값을 찾아서 가져올 수 있어야합니다. – DaniDev

답변

1

글쎄 그다지 고통스럽지 않습니다. 나는 사용자의 전화 번호 필드 안에 마지막 요청의 dateTime을 저장하고있는 추악한 부분을 버렸다. :) 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); 
    }