public ActionResult <ForgotPasswordResponseModel> ForgotPassword([FromBody] ForgotPasswordMobileInputModel data) { try { ForgotPasswordBL forPasswordBL = new ForgotPasswordBL(DbContext); var url = AppSettings.URLForgotPassword; var result = forPasswordBL.SendURL(data.UserName, url); if (result.Response) { var locationHtml = AppSettings.TemplatePath + "EmailResetPassword.html"; string content = System.IO.File.ReadAllText(locationHtml); content = content.Replace("$BASE_URL", AppSettings.BaseURL); content = content.Replace("$ForgetPassword_URL", AppSettings.BaseURL + AppSettings.URLForgotPassword + result.data.ID); MailMessage message = new MailMessage(); message.To.Add(result.data.UserName); message.Body = content; message.Subject = "Forgot Password"; message.From = new MailAddress(AppSettings.EmailConfig.FromAddress); message.IsBodyHtml = true; EmailSenderEngine emailEngine = new EmailSenderEngine(); string configOnJSON = JsonConvert.SerializeObject(AppSettings.EmailConfig); emailEngine.SendEmail(message, configOnJSON); } return(result); } catch (Exception ex) { ForgotPasswordResponseModel logres = new ForgotPasswordResponseModel(); logres.Message = ex.Message; logres.Response = false; return(logres); } }
public IActionResult ForgotPass(string email) { ForgotPasswordMobileInputModel data = new ForgotPasswordMobileInputModel(); data.UserName = email; JsonConvert.SerializeObject(data); using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseAPI + "Profile/"); //HTTP POST var postTask = client.PostAsJsonAsync <ForgotPasswordMobileInputModel>("ForgotPassword", data); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { var content = result.Content.ReadAsStringAsync(); ForgotPasswordResponseModel forgot = Newtonsoft.Json.JsonConvert.DeserializeObject <ForgotPasswordResponseModel>(content.Result); if (forgot.data != null && forgot.data.ID.ToString() != "") { TempData["CustomInfo"] = "Email notification sended. Please check your email."; return(RedirectToAction("Index", "Home")); } else { TempData["CustomError"] = "Fail to update data. Please contact administrator."; return(RedirectToAction("Index", "Home")); } } else { TempData["CustomError"] = "Terjadi kesalahan server. Hubungi admin."; return(RedirectToAction("Index", "Home")); } } }
public IActionResult ForgotPass(string email) { ForgotPasswordMobileInputModel data = new ForgotPasswordMobileInputModel(); data.UserName = email; JsonConvert.SerializeObject(data); using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseAPI + "Profile/"); //HTTP POST var postTask = client.PostAsJsonAsync <ForgotPasswordMobileInputModel>("ForgotPassword", data); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { var content = result.Content.ReadAsStringAsync(); ForgotPasswordResponseModel forgot = Newtonsoft.Json.JsonConvert.DeserializeObject <ForgotPasswordResponseModel>(content.Result); if (forgot.data != null && forgot.data.ID.ToString() != "") { TempData["CustomInfo"] = "Email notification sended. Please check your email."; if (HttpContext.Session.GetString(Loginfrom) == "ADM/SPV") { return(RedirectToAction("AdminLogon", "Login")); } else if (HttpContext.Session.GetString(Loginfrom) == "MDO") { return(RedirectToAction("OwnerLogon", "Login")); } else { return(RedirectToAction("BuyerLogon", "Login")); } //return RedirectToAction("Logon", "Login"); } else { TempData["CustomError"] = "Fail to update data. Please contact administrator."; if (HttpContext.Session.GetString(Loginfrom) == "ADM/SPV") { return(RedirectToAction("AdminLogon", "Login")); } else if (HttpContext.Session.GetString(Loginfrom) == "MDO") { return(RedirectToAction("OwnerLogon", "Login")); } else { return(RedirectToAction("BuyerLogon", "Login")); } //return RedirectToAction("Logon", "Login"); } } else { TempData["CustomError"] = "Server Error. Please contact administrator."; if (HttpContext.Session.GetString(Loginfrom) == "ADM/SPV") { return(RedirectToAction("AdminLogon", "Login")); } else if (HttpContext.Session.GetString(Loginfrom) == "MDO") { return(RedirectToAction("OwnerLogon", "Login")); } else { return(RedirectToAction("BuyerLogon", "Login")); } //return RedirectToAction("Logon", "Login"); } } }