public async Task <IActionResult> Index(ForgotPasswordModel input) { if (ModelState.IsValid) { HttpResponseMessage httpResponseMessage = await HttpClientRequest.PostAsync(ApiEndpoints.ForgotPassword, ConstructForgotPasswordParams(input.Email)); if (httpResponseMessage.StatusCode == HttpStatusCode.OK) { ForgotPasswordResponseModel responseModel = JsonConvert.DeserializeObject <ForgotPasswordResponseModel>( await httpResponseMessage.Content.ReadAsStringAsync()); if (responseModel.code == FORGOT_PASSWORD_SUCCESS_CODE) { return(RedirectToAction("ForgotPasswordSuccess", "Form", new { email = ProtectForgotPasswordMessage(input.Email) })); } else { return(HandleForgotPasswordFailAction(responseModel.code, input)); } } else { return(RedirectToAction("Index", "Home", new { area = "" })); } } else { return(View(input)); } }
public ForgotPasswordResponseModel SendURL(string userName, string URL) { Guid id = Guid.NewGuid(); bool isSuccess = false; string message = ""; LogForgotPassword temp = new LogForgotPassword(); ForgotPasswordResponseModel responseModel = new ForgotPasswordResponseModel(); ForgotPasswordMobileOutputModel outputModel = new ForgotPasswordMobileOutputModel(); UserRepository userRepo = new UserRepository(DbContext); var userInfo = userRepo.FindByUserName(userName); if (userInfo != null && userInfo.ID != null && userInfo.ID != Guid.Empty) { LogForgotPasswordRepository repo = new LogForgotPasswordRepository(DbContext); temp.ID = id; temp.IsUsed = false; temp.UserName = userName; temp.DateRequest = DateTime.Now; temp.DateExpired = DateTime.Now.AddHours(3); temp.CreateByUserID = userInfo.ID; temp.CreateDate = DateTime.Now; var result = repo.Insert(temp); if (result.Result) { isSuccess = result.Result; message = result.Message; outputModel.ID = result.ID; outputModel.UserName = userName; outputModel.URL = URL + result.ID.ToString(); responseModel.data = outputModel; } responseModel.Message = message; responseModel.Response = isSuccess; } else { responseModel.Message = "Can't find Username"; responseModel.Response = false; } return(responseModel); }
public IActionResult ForgotPassword([FromBody][Required] PostForgotPasswordRequestDto data) { StatusResponseDto responseDto; try { /// <summary> /// Método para guardar request en logs /// </summary> _securityService.RequestLog("api/auth/ForgotPassword: " + JsonConvert.SerializeObject(data)); if (string.IsNullOrWhiteSpace(data.User)) { return(BadRequest()); } else { var request = _mapper.Map <PostForgotPasswordRequestModel>(data); ForgotPasswordResponseModel responseModel = _authService.ForgotPassword(request); switch (responseModel.Status) { case ResultStatus.SUCCESS: _notifier.Notify(new EmailData(EmailType.CommercialPasswordNew, responseModel)); responseDto = _mapper.Map <StatusResponseDto>(responseModel); return(StatusCode(StatusCodes.Status200OK, responseDto)); case ResultStatus.NOT_FOUND: case ResultStatus.ACCESS_DENIED: return(StatusCode(StatusCodes.Status401Unauthorized)); case ResultStatus.CANNOT_CONNECT_TO_PBX: return(StatusCode(StatusCodes.Status503ServiceUnavailable)); default: return(StatusCode(StatusCodes.Status500InternalServerError)); } } } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e)); } }
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 async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordRequestModel requestModel) { if (ModelState.IsValid) { ForgotPasswordResponseModel responseModel = await _accountService.ForgotPasswordAsync(requestModel); if (!responseModel.IsPossibleToUseCurrentEmail) { ModelState.AddModelError(string.Empty, "It's impossible to use email that you provided"); return(BadRequest(ModelState)); } string callbackUrl = CreateCallbackUrl("ResetPassword", new { userId = responseModel.Id, code = responseModel.Code, redirectUrl = requestModel.RedirectUrl, email = requestModel.Email }); await _emailHelper.SendEmailAsync(requestModel.Email, "Reset Password", $"Для сброса пароля пройдите по ссылке: <a href='{callbackUrl}'>link</a>"); return(Ok()); } return(BadRequest(ModelState)); }
public async Task <ForgotPasswordResponseModel> ForgotPasswordAsync(ForgotPasswordRequestModel requestModel) { ApplicationUser user = await _userManager.FindByEmailAsync(requestModel.Email); ForgotPasswordResponseModel responseModel = new ForgotPasswordResponseModel(); bool isEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user); if (user is null || !isEmailConfirmed) { responseModel.IsPossibleToUseCurrentEmail = false; return(responseModel); } responseModel.Id = user.Id; responseModel.IsPossibleToUseCurrentEmail = true; string code = await _userManager.GeneratePasswordResetTokenAsync(user); responseModel.Code = Base64UrlEncoder.Encode(code); return(responseModel); }
public async void ConfirmTap() { if (!this.IsEnabled) { return; } this.IsEnabled = false; this.IsRunning = true; if (string.IsNullOrEmpty(this.User)) { await _messageService.ShowErrorMessage(Application.Current.Resources["TitleValidForgotPasswordPage"].ToString(), Application.Current.Resources["AllTextValidation"].ToString()); this.IsEnabled = true; this.IsRunning = false; return; } var forgotPasswordRequestModel = new ForgotPasswordRequestModel() { usuario = this.User }; try { _forgotPasswordResponseModel = await _loginService.ForgotPassword(forgotPasswordRequestModel); await DestroyThisModalAsync(); await _messageService.ShowSuccessMessage(_forgotPasswordResponseModel.Descripcion); } catch (Exception ex) { await _messageService.HandleException(ex); }finally{ this.IsEnabled = true; this.IsRunning = false; } }
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"); } } }
/// <summary> /// Consrtructor de EmailData. /// </summary> /// <param name="inEmailType">Enumerado indicando tipo de mail a crear.</param> /// <param name="inData">Objeto (segun el tipo de email) con los datos a usar en el asunto/cuerpo del mail.</param> public EmailData(EmailType inEmailType, object inData) { #region ImageHeaderAttachment string pathImageHeader = Path.Combine(Path.GetTempPath(), "BestBankEmailHeader.png"); if (!File.Exists(pathImageHeader)) { File.WriteAllBytes(pathImageHeader, Resources.BestBank_EmailHeader); } Guid imageHeaderId = Guid.NewGuid(); EmailAttachment attachmentHeader = new EmailAttachment { ContentId = imageHeaderId.ToString(), Inline = true, MediaType = new System.Net.Mime.ContentType("image/png"), Path = pathImageHeader, }; #endregion switch (inEmailType) { case EmailType.CommercialNew: // Image AppLogin Attachment string pathImageAppLogin = Path.Combine(Path.GetTempPath(), "BestBankAppLogin.jpg"); if (!File.Exists(pathImageAppLogin)) { File.WriteAllBytes(pathImageAppLogin, Resources.BestBank_AppLogin); } Guid imageAppLoginId = Guid.NewGuid(); EmailAttachment attachmentAppLogin = new EmailAttachment { ContentId = imageAppLoginId.ToString(), Inline = true, MediaType = new System.Net.Mime.ContentType("image/jpg"), Path = pathImageAppLogin, }; PostBOCommercialsResponseModel objCommercial = ((PostBOCommercialsResponseModel)inData); this.To = objCommercial.Email; this.Subject = "Registo na Contact APP do Best Bank"; this.Attachments = new List <EmailAttachment> { attachmentHeader, attachmentAppLogin }; this.Body = Resources.BestBank_EmailTemplate_CommercialNew .Replace("{USER_EMAIL}", objCommercial.Email) .Replace("{USER_NAME}", objCommercial.Name) .Replace("{USER_PASSWORD}", objCommercial.Password) .Replace("{USER_PEER}", objCommercial.Peer.ToString()) .Replace("{LINK_DOWNLOAD_APP}", objCommercial.LinkAppAndroid) .Replace("{IMAGE_APPLOGIN_SRC}", $"cid:{imageAppLoginId.ToString()}") .Replace("{IMAGE_SRC}", $"cid:{imageHeaderId.ToString()}"); break; case EmailType.CommercialPasswordNew: ForgotPasswordResponseModel objForgotPass = ((ForgotPasswordResponseModel)inData); this.To = objForgotPass.CommercialEmail; this.Subject = "Alteração de Password da Contact App do Banco Best."; this.Attachments = new List <EmailAttachment> { attachmentHeader }; this.Body = Resources.BestBank_EmailTemplate_CommercialNewPassword .Replace("{USER_NAME}", objForgotPass.CommercialName) .Replace("{USER_PASSWORD}", objForgotPass.CommercialPassword) .Replace("{IMAGE_SRC}", $"cid:{imageHeaderId.ToString()}"); break; case EmailType.SupervisorState: PatchBOSupervisorsRequestModel objSupervisor = ((PatchBOSupervisorsRequestModel)inData); this.To = objSupervisor.Email; this.Subject = "Supervisor de Aplicação"; this.Attachments = new List <EmailAttachment> { attachmentHeader }; this.Body = Resources.BestBank_EmailTemplate_SupervisorState .Replace("{SUPERVISOR_STATE}", objSupervisor.Approve ? "aprovado" : "rejeitado") .Replace("{IMAGE_SRC}", $"cid:{imageHeaderId.ToString()}"); break; } }