Asp.NetMVC身份验证重置密码
创始人
2024-09-19 07:00:20
0
  1. 添加重设密码功能 添加忘记密码的链接和重置密码的视图。在忘记密码的视图中,用户输入他们的电子邮件地址,当他们单击按钮时,控制器将通过电子邮件发送重置密码链接。当用户单击链接时,他们将重定向到重置密码视图。以下是示例代码:

[HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) { // Don't reveal that the user does not exist or is not confirmed return View("ForgotPasswordConfirmation"); }

    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
    // Send an email with this link
    string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
    var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
    await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking here: link");
    return View("ForgotPasswordConfirmation");
}

// If we got this far, something failed, redisplay form
return View(model);

}

[AllowAnonymous] public ActionResult ForgotPassword() { return View(); }

[AllowAnonymous] public ActionResult ForgotPasswordConfirmation() { return View(); }

[AllowAnonymous] public ActionResult ResetPassword(string code) { return code == null ? View("Error") : View(); }

[HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task ResetPassword(ResetPasswordViewModel model) { if (!ModelState.IsValid) { return View(model); } var user = await UserManager.FindByNameAsync(model.Email); if (user == null) { // Don't reveal that the user does not exist return RedirectToAction("ResetPasswordConfirmation", "Account"); } var result = await UserManager.ResetPasswordAsync

相关内容

热门资讯

最新技巧(情怀麻将助赢神器购买... 最新技巧(情怀麻将助赢神器购买)最初是有挂(辅助挂)普及教程(2026已更新)(哔哩哔哩);1、完成...
9分钟了解(堆金城麻将有挂)一... 9分钟了解(堆金城麻将有挂)一直真的是有挂(辅助挂)2025版教程(2024已更新)(哔哩哔哩);一...
必备攻略(微友麻将亲友圈有挂)... 必备攻略(微友麻将亲友圈有挂)从来存在有挂(辅助挂)实用技巧(2023已更新)(哔哩哔哩)是一款可以...
必备辅助推荐(都莱罗松辅助器)... 必备辅助推荐(都莱罗松辅助器)好像真的有挂(辅助挂)透明挂教程(2025已更新)(哔哩哔哩);1、许...
一分钟秒懂(科乐麻将挂件神器通... 一分钟秒懂(科乐麻将挂件神器通用)最初真的有挂(辅助挂)微扑克教程(2020已更新)(哔哩哔哩);一...
热点讨论(哈灵麻将可以让系统发... 热点讨论(哈灵麻将可以让系统发好牌)最初是真的有挂(辅助挂)玩家教程(2020已更新)(哔哩哔哩)是...
我来向大家传授(衢州都莱有胜率... 我来向大家传授(衢州都莱有胜率)往昔真的有挂(辅助挂)攻略教程(2022已更新)(哔哩哔哩);1、很...
一分钟秒懂(齐聚天下有挂)原先... 一分钟秒懂(齐聚天下有挂)原先真的有挂(辅助挂)攻略教程(2024已更新)(哔哩哔哩);1、点击下载...
重大来袭(卡丁互娱有挂)原来真... 重大来袭(卡丁互娱有挂)原来真的有挂(辅助挂)系统教程(2023已更新)(哔哩哔哩)相信很多朋友都在...
六分钟了解(微乐陕西麻将小程序... 六分钟了解(微乐陕西麻将小程序有猫腻)一贯有挂(辅助挂)解说技巧(2022已更新)(哔哩哔哩)是一款...