public ActionResult ForgotPassword(CustomerForgotPasswordViewModel model) { if (ModelState.IsValid) { var customer = db.Customers.Where(q => q.Email == model.Email).FirstOrDefault(); if (customer == null) { ModelState.AddModelError("Email", "Email is not correct"); return(View(model)); } else if (customer.DeletedAt != null) { ModelState.AddModelError("Email", "Account locked"); return(View(model)); } customer.ResetPasswordToken = CommonHelper.GenerateToken(6); while (db.Customers.Where(q => q.ResetPasswordToken == customer.ResetPasswordToken && q.DeletedAt == null).FirstOrDefault() != null) { customer.ResetPasswordToken = CommonHelper.GenerateToken(6); } customer.TokenExipredAt = DateTime.Now.AddMinutes(30); db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); model.Url = CommonHelper.GetBaseUrl() + Url.Action("ResetPassword") + "?token=" + customer.ResetPasswordToken; EmailHandler.Handle(model, model.Email, "Reset Password", "Views/Customer/Template/ForgotPasswordTemplate.cshtml"); return(Redirect(Request.UrlReferrer.ToString())); } return(View(model)); }
public IActionResult SendOTPWhenForgotPassword(CustomerForgotPasswordViewModel model) { var sendOTPResult = _customerService.SendOTPForgotPassword(model); if (sendOTPResult == CustomerService.ERROR_NOT_FOUND_CUSTOMER) { return(StatusCode((int)HttpStatusCode.NotAcceptable, sendOTPResult)); } return(Ok()); }
public string SendOTPForgotPassword(CustomerForgotPasswordViewModel model) { var existedCustomer = _customerRepository.Get(x => x.Deleted == false && x.PhoneNumber == model.PhoneNumber ); if (existedCustomer == null) { return(ERROR_NOT_FOUND_CUSTOMER); } _oTPService.CreatOTPWithEachPhone(model.PhoneNumber); return(string.Empty); }