本文整理汇总了C#中IMembershipService.ResetUserPassword方法的典型用法代码示例。如果您正苦于以下问题:C# IMembershipService.ResetUserPassword方法的具体用法?C# IMembershipService.ResetUserPassword怎么用?C# IMembershipService.ResetUserPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMembershipService
的用法示例。
在下文中一共展示了IMembershipService.ResetUserPassword方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AccountModule
//.........这里部分代码省略.........
}
else
{
membershipService.RequestResetPassword(user, applicationSettings.RequestResetPasswordValidThroughInHours);
repository.CommitChanges();
emailService.SendRequestResetPassword(user, this.Request.Url.SiteBase + "/account/resetpassword/");
return View["requestresetpasswordsuccess", username];
}
}
}
catch (Exception ex)
{
this.AddValidationError("_FORM", ex.Message);
}
return View["requestresetpassword"];
};
Get["/resetpassword/{id}"] = parameters =>
{
if (!applicationSettings.AllowUserResetPassword ||
string.IsNullOrWhiteSpace(applicationSettings.EmailSender))
{
return HttpStatusCode.NotFound;
}
string resetPasswordToken = parameters.id;
string userName = membershipService.GetUserNameFromToken(resetPasswordToken);
// Is the token not valid, maybe some character change?
if (userName == null)
{
return View["resetpassworderror", LanguageResources.Account_ResetInvalidToken];
}
else
{
ChatUser user = repository.GetUserByRequestResetPasswordId(userName, resetPasswordToken);
// Is the token expired?
if (user == null)
{
return View["resetpassworderror", LanguageResources.Account_ResetExpiredToken];
}
else
{
return View["resetpassword", user.RequestPasswordResetId];
}
}
};
Post["/resetpassword/{id}"] = parameters =>
{
if (!HasValidCsrfTokenOrSecHeader)
{
return HttpStatusCode.Forbidden;
}
if (!applicationSettings.AllowUserResetPassword ||
string.IsNullOrWhiteSpace(applicationSettings.EmailSender))
{
return HttpStatusCode.NotFound;
}
string resetPasswordToken = parameters.id;
string newPassword = Request.Form.password;
string confirmNewPassword = Request.Form.confirmPassword;
ValidatePassword(newPassword, confirmNewPassword);
try
{
if (ModelValidationResult.IsValid)
{
string userName = membershipService.GetUserNameFromToken(resetPasswordToken);
ChatUser user = repository.GetUserByRequestResetPasswordId(userName, resetPasswordToken);
// Is the token expired?
if (user == null)
{
return View["resetpassworderror", LanguageResources.Account_ResetExpiredToken];
}
else
{
membershipService.ResetUserPassword(user, newPassword);
repository.CommitChanges();
return View["resetpasswordsuccess"];
}
}
}
catch (Exception ex)
{
this.AddValidationError("_FORM", ex.Message);
}
return View["resetpassword", resetPasswordToken];
};
}