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

相关内容

热门资讯

五分钟了解!豆豆斗牌鄂东麻将有... 五分钟了解!豆豆斗牌鄂东麻将有挂吗,微信小程序赣牌圈有挂么,新2025版(有挂详情)1、下载好微信小...
八分钟了解!休闲九九斗牛真的有... 八分钟了解!休闲九九斗牛真的有挂吗,皇豪互娱辅助器,2025新版教程(有挂揭秘)1、进入到休闲九九斗...
九分钟了解!中至辅助器ios免... 九分钟了解!中至辅助器ios免费版,吉祥麻将辅牌器哪里搞,安装教程(有挂透视)1、进入到吉祥麻将辅牌...
十分钟了解!福建大玩家十三水胜... 您好,福建大玩家十三水胜率怎么调这款游戏可以开挂的,确实是有挂的,需要了解加微【757446909】...
五分钟了解!雀神广东麻将好友方... 五分钟了解!雀神广东麻将好友方法怎么赢牌,掌中乐游戏有挂吗,细节方法(有挂黑科技)1、完成雀神广东麻...
三分钟了解!微信喜扣打筒子有挂... 三分钟了解!微信喜扣打筒子有挂吗,钱塘十三水如何调整输赢,AI教程(有挂总结);1、下载好钱塘十三水...
9分钟了解!至友互娱是不是有外... 9分钟了解!至友互娱是不是有外 挂,jj跑得快,德州论坛(有挂攻略)1、超多福利:超高返利,海量正版...
4分钟了解!多乐跑得快第三方辅... 4分钟了解!多乐跑得快第三方辅助器,欢乐龙城3脚本,存在挂教程(有挂秘笈)1、完成多乐跑得快第三方辅...
5分钟了解!东游麻将中挂件,兴... 5分钟了解!东游麻将中挂件,兴动互娱最强辅助神器下载,大神讲解(有挂插件)1、兴动互娱最强辅助神器下...
五分钟了解!心悦填大坑辅助器,... 五分钟了解!心悦填大坑辅助器,网易棋牌怎么才能提升好牌,解说技巧(有挂机密)1、在网易棋牌怎么才能提...