【发布时间】:2015-07-16 07:24:56
【问题描述】:
您好,我正在尝试通过短信向用户发送重置密码链接,就像您使用 mvc 中的电子邮件密码重置发送它一样
我现在拥有 ryt 的代码只是向我发送了一条带有完整 url 和用户 ID 的短信,而不是我可以点击的部分
这是我的电子邮件代码重置,首先显示我如何重置
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
{
//SendSmsBusiness objap = new SendSmsBusiness();
RegisterBusiness reg = new RegisterBusiness();
EmailBusiness _emailBusiness = new EmailBusiness();
if (ModelState.IsValid)
{
ApplicationUser user = new ApplicationUser();
user = reg.UserManager.FindByEmail(model.Email);
// 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
if (user != null)
{
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 <a href=\"" + callbackUrl + "\">here</a>");
_emailBusiness.SendEmailForgot(model.Email, callbackUrl);
return RedirectToAction("ForgotPasswordConfirmation", "Account");
}
{
ModelState.AddModelError("", "The user does not exist");
return View();
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
这很有效
这是我的短信重置代码
// GET: /Account/ForgotPassword
[AllowAnonymous]
public ActionResult PhoneReset()
{
return View();
}
// POST: /Account/ForgotPassword
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> PhoneReset(ForgotPasswordView model,string sms)
{
RegisterBusiness reg = new RegisterBusiness();
if (ModelState.IsValid)
{
ApplicationUser user = new ApplicationUser();
user = reg.UserManager.FindByEmail(model.Email);
// 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
if (user != null)
{
//string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
SendSmsBusiness objap = new SendSmsBusiness();
string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
sms = "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>";
objap.Send_SMS(model.Phone, sms);
await SignInAsync(user, isPersistent: false);
return RedirectToAction("ResetViaPhone", "Account");
}
else if (user == null)
{
ModelState.AddModelError("", "The user does not exist");
return View();
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
在短信中我收到了这个 - 请点击重置您的密码
但是没有链接。 minenhle@gmail.com 是我用来重置密码的。
我不知道我在哪里弄错了,或者我尝试什么是不可能的
【问题讨论】:
标签: c# asp.net-mvc asp.net-identity-2