public async Task <int> ResetPassword(IOwinContext owinContext, HttpRequestBase Request, ResetPasswordItem model) { try { InstanceUserManager instanceUserManager = owinContext.GetUserManager <InstanceUserManager>(); IdentityUserItem user = await instanceUserManager.FindByEmailAsync(model.Email); if (user != null) { IdentityResult result = await instanceUserManager.ResetPasswordAsync(user.Id, model.Code, model.Password); if (result.Succeeded) { return(1); } else { foreach (var error in result.Errors) { strErrorMessage = strErrorMessage + " " + error; } return(2); } } else { return(0); } } catch (Exception ex) { serviceException = ex; return(-1); } }
public async Task <int> ForgotPassword(IOwinContext owinContext, HttpRequestBase Request, ForgotPasswordItem model) { try { InstanceUserManager instanceUserManager = owinContext.GetUserManager <InstanceUserManager>(); var user = await instanceUserManager.FindByEmailAsync(model.Email); if (user == null || !(await instanceUserManager.IsEmailConfirmedAsync(user.Id))) { //return View("ForgotPasswordConfirmation"); return(0); } string code = await instanceUserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = new UrlHelper(Request.RequestContext).Action("ResetPassword", "Login", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); //var callbackUrl = Url.Action("ResetPassword", "Login", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await instanceUserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking this link " + callbackUrl); //return RedirectToAction("ForgotPasswordConfirmation", "Login"); return(1); } catch (Exception ex) { serviceException = ex; //return LoginStatus.SystemFailure; return(-1); } }