2016-04-22 29 views
1

Ich verwende das vorhandene PasswordReset-Formular in WebMatrix. Ich habe an dem Modul nichts geändert, aber es funktioniert nicht. Wenn ich auf "Hast du dein Passwort vergessen?" Link und es bringt mich zum ForgotPassword Formular. Nachdem ich meine E-Mail-Adresse eingegeben und auf "Anweisungen senden" geklickt habe, geht es zu meiner E-Mail. Aber wenn ich auf den Link klicke, bekomme ich sofort den Bildschirm zum Zurücksetzen des Passworts, aber oben auf dem Bildschirm steht: "Das Passwort konnte nicht zurückgesetzt werden. Bitte korrigieren Sie die Fehler und versuchen Sie es erneut." Auch wenn ich versuche mein Passwort zurückzusetzen passiert nichts.PasswordReset funktioniert nicht in WebMatrix

Unten ist der Passwort-Reset-Code:

@* Remove this section if you are using bundling *@ 
@section Scripts { 
    <script src="~/Scripts/jquery.validate.min.js"></script> 
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script> 
} 

@{ 
    Layout = "~/_SiteLayout.cshtml"; 
    Page.Title = "Password Reset"; 

    var passwordResetToken = Request.Form["resetToken"] ?? Request.QueryString["resetToken"]; 

    bool tokenExpired = false; 
    bool isSuccess = false; 

    // Setup validation 
    Validation.RequireField("newPassword", "The new password field is required."); 
    Validation.Add("confirmPassword", 
     Validator.EqualsTo("newPassword", "The new password and confirmation password do not match.")); 
    Validation.RequireField("passwordResetToken", "The password reset token field is required."); 
    Validation.Add("newPassword", 
     Validator.StringLength(
      maxLength: Int32.MaxValue, 
      minLength: 6, 
      errorMessage: "New password must be at least 6 characters")); 

    if (IsPost && Validation.IsValid()) { 
     AntiForgery.Validate(); 
     var newPassword = Request["newPassword"]; 
     var confirmPassword = Request["confirmPassword"]; 

     if (WebSecurity.ResetPassword(passwordResetToken, newPassword)) { 
      isSuccess = true; 
     } else { 
      ModelState.AddError("passwordResetToken", "The password reset token is invalid."); 
      tokenExpired = true; 
     } 
    } 
} 

<hgroup class="title"> 
    <h1>@Page.Title.</h1> 
    <h2>Use the form below to reset your password.</h2> 
</hgroup> 

@if (!WebMail.SmtpServer.IsEmpty()) { 
    if (!Validation.IsValid()) { 
     <p class="validation-summary-errors"> 
      @if (tokenExpired) { 
       <text>The password reset token is incorrect or may be expired. Visit the <a href="~/Account/ForgotPassword">forgot password page</a> 
       to generate a new one.</text> 
      } else { 
       <text>Could not reset password. Please correct the errors and try again.</text> 
      } 
     </p> 
    } 

    if (isSuccess) { 
     <p class="message-success"> 
      Password changed! Click <a href="~/Account/Login" title="Log in">here</a> to log in. 
     </p> 
    } 

    <form method="post"> 
     @AntiForgery.GetHtml() 
     <fieldset> 
      <legend>Password Change Form</legend> 
      <ol> 
       <li class="new-password"> 
        <label for="newPassword" @if (!ModelState.IsValidField("newPassword")) {<text>class="error-label"</text>}>New password</label> 
        <input type="password" id="newPassword" name="newPassword" disabled="@isSuccess" @Validation.For("newPassword") /> 
        @Html.ValidationMessage("newPassword") 
       </li> 
       <li class="confirm-password"> 
        <label for="confirmPassword" @if (!ModelState.IsValidField("confirmPassword")) {<text>class="error-label"</text>}>Confirm password</label> 
        <input type="password" id="confirmPassword" name="confirmPassword" disabled="@isSuccess" @Validation.For("confirmPassword") /> 
        @Html.ValidationMessage("confirmPassword") 
       </li> 
       <li class="reset-token"> 
        <label for="resetToken" @if (!ModelState.IsValidField("resetToken")) {<text>class="error-label"</text>}>Password reset token</label> 
        <input type="text" id="resetToken" name="resetToken" value="@passwordResetToken" disabled="@isSuccess" @Validation.For("resetToken") /> 
        @Html.ValidationMessage("resetToken") 
       </li> 
      </ol> 
      <input type="submit" value="Reset password" disabled="@isSuccess"/> 
     </fieldset> 
    </form> 
} else { 
    <p class="message-info"> 
     Password recovery is disabled for this website because the SMTP server is 
     not configured correctly. Please contact the owner of this site to reset 
     your password. 
    </p> 
} 

Hier ist der Code in meinem _AppStart ist:

WebSecurity.InitializeDatabaseConnection ("StarterSite", "Userprofile", "Benutzer-ID", "E-Mail", autoCreateTables: true);

OAuthWebSecurity.RegisterGoogleClient(); 

WebMail.SmtpServer = "smtp.gmail.com"; 
WebMail.EnableSsl = true; 

WebMail.SmtpPort = 587; 
WebMail.UserName = "[email protected]"; 
WebMail.Password = "September"; 
WebMail.From = "[email protected]"; 

Antwort

0

Ändern Sie die Konstanten in Ihrem Benutzerobjekt. Löschen Sie die erforderlichen Attribute von dort. Ebenfalls. Ich schlage vor, Ihre eigene Basisauthentifizierung zu schreiben.

+0

Was bedeutet das? Ich folge dir nicht. – tnbumbray

+0

Hallo, sory ich habe nicht viel Zeit. WebMatrix ist ein leichtgewichtiges Authentifizierungs-Framework und es hat eine gewisse Konstanz während der Verwendung. Einer von ihnen ist in Sicht chtml Attribut. Dort können Sie sehen, dass Validierungsregeln sie löschen und Ihr Fehler wird verschwinden. Und ich habe auch lange mit WebMatrix gearbeitet und es gibt viele andere Consistencies wie diese und ich habe mein eigenes Framework geschrieben und ich schlage dir dazu vor. freundliche Grüße – dewelloper