public RecoveryPasswordData ExecuteProcess(RecoveryPassword recoveryPassword) { RecoveryPasswordData recoveryPasswordData = new RecoveryPasswordData(); var userMail = this._UserRetrieveService.Where(p => p.Mail.ToLower() == recoveryPassword.Mail.ToLower() && p.Deleted_At == null).FirstOrDefault(); if (userMail == null) { throw new SystemValidationException("The mail is not registered"); } string password = Utilities.GetPasswordRandom(); recoveryPasswordData.Password = password; string passwordEncrypt = InsiscoCore.Utilities.Crypto.MD5.Encrypt(password); if (userMail != null) { recoveryPasswordData.Mail = userMail.Mail; userMail.Password = passwordEncrypt; recoveryPasswordData.Data = userMail; recoveryPasswordData.UserType = TemplateNetCoreEnum.UserType.Administrador; } return(recoveryPasswordData); }
public async Task RedefinirSenha(RecoveryPassword recovery, string Token) { using (HttpClient client = new HttpClient()) { try { client.BaseAddress = uri; var json = JsonConvert.SerializeObject(recovery); var content = new StringContent(json, Encoding.UTF8, "application/json"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); HttpResponseMessage response = await client.PostAsync("Cliente/ForgotPassword/", content); string mensagem = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode == true && mensagem == "Email enviado com sucesso!") { return; } if (!string.IsNullOrWhiteSpace(mensagem)) { throw new Exception(mensagem); } throw new Exception(response.StatusCode.ToString()); } catch (Exception ex) { throw new Exception(ex.Message); } } }
public string ForgotPasswordEmail(RecoveryPassword recuperarSenha) { try { var email = new Email { ClienteEmail = recuperarSenha.Email, AssuntoEmail = "Lyfr - Esqueceu sua senha?", ConteudoEmail = String.Format("</strong>Você esqueceu sua senha jovem leitor?<br><br></strong>" + " Alguém requisitou a opção \"Esqueci senha\" e foi passado seu email," + " caso seja você não se preocupe. <br><br><strong>Aqui está seu código de recuperação: {0}</strong><br><br>" + "<br>" + " Você pode mudar sua senha acessando nosso aplicativo ou plataforma web.<br>" + " <br>Caso não tenha sido você desconsidere esse email!<br><br><br><br>" + "<strong>Atenciosamente, equipe Lyfr!</strong>", recuperarSenha.CodigoGerado) }; var sucesso = new EmailSend().SendEmail(email); if (sucesso) { return("Email enviado com sucesso!"); } else { return("Ocorreu algum erro na hora de enviarmos o e-mail, por favor tente novamente!"); } } catch (Exception) { return("Tivemos alguns problemas de conexão. Por favor tente novamente mais tarde."); } }
public async Task <ResponseModel> RetrievePassword(RecoveryPassword model) { ResponseModel response = new ResponseModel(); ValidationResult validateRecoveryEmail = new RecoveryEmailValidator().Validate(model); if (validateRecoveryEmail.IsValid) { try { User user = _userRepository.GetByEmail(model.Email); if (user == null) { response.Message = "Usuário não encontrado."; return(response); } EmailRetrievePassword emailRetrieve = new EmailRetrievePassword() { FromEmail = "*****@*****.**", FromName = "Me Agenda Aí", Subject = "Link para alteração da sua senha do Me Agenda Aí", Token = JWTService.GenerateTokenRecoverPassword(user, _signingConfiguration, _tokenConfiguration), Url = _configuration.GetValue <string>("URLPortal"), Expiration = ((Convert.ToInt32(_tokenConfiguration.Seconds) / (60 * 60)).ToString()) }; bool resp = await _email.SendRecoveryPassword(user, emailRetrieve); if (resp) { response.Success = resp; response.Message = "E-mail enviado com sucesso."; } else { response.Message = "Não foi possível enviar o e-mail."; } } catch (Exception) { response.Message = "Erro no sistema, e-mail não enviado."; } } else { response.Message = validateRecoveryEmail.Errors.FirstOrDefault().ErrorMessage; } return(response); }
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { RecoveryPassword rec_form = new RecoveryPassword(); if (rec_form.ShowDialog(this) == DialogResult.OK) { if (mode_form != null) { mode_form.Close(); } mode_form = new SuperAdminMode(); mode_form.Show(this); } }
public async Task <ActionResult> RecoverPassword([FromBody] RecoveryPassword model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { return(Ok(await _userService.RetrievePassword(model))); } catch (ArgumentException e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }
public async Task <string> RedefinirSenha(string Email) { RecoveryPassword recovery = new RecoveryPassword(); recovery.Email = Email; recovery.CodigoGerado = EmailApplication.GenerateCode(HttpContext); try { await _cliente.RedefinirSenha(recovery, Token.GetToken(HttpContext)); } catch (Exception ex) { return(ex.Message); } return("Um código de redefinição foi enviado para o seu e-mail!"); }
public IActionResult ForgotPassword([FromBody] RecoveryPassword recuperarSenha) { try { if (!new ValidationFields().ValidateEmail(recuperarSenha.Email)) { return(BadRequest("Email inválido! Tente novamente.")); } else { var resposta = new ClienteAplicacao(_context, _provedorDiretoriosArquivos).ForgotPassword(recuperarSenha); return(Ok(resposta)); } } catch (Exception) { return(BadRequest("Tivemos alguns problemas de conexão. Tente novamente mais tarde.")); } }
public string ForgotPassword(RecoveryPassword recuperarSenha) { try { var cliente = GetClienteByEmail(recuperarSenha.Email.ToLower()); if (cliente != null) { var resposta = new ClienteMessages(_provedorDiretoriosArquivos).ForgotPasswordEmail(recuperarSenha); return(resposta); } else { return("Usuário não encontrado!"); } } catch (Exception) { return("Não foi possível se comunicar com a base de dados!"); } }
public async Task <IActionResult> EsqueciSenha(RecoveryPassword recuperarSenha) { await Token.CheckCookies(HttpContext); try { var resposta = await new RepositoryAdministrador().ForgotPassword(recuperarSenha, Token.GetToken(HttpContext)); if (resposta.Equals("Email enviado com sucesso!")) { return(Ok()); } else { return(BadRequest("Admnistrador não encontrado...")); } } catch (Exception ex) { return(Ok(ex.ToString())); } }
public async Task <string> ForgotPassword(RecoveryPassword recuperarSenha, string Token) { using (HttpClient client = new HttpClient()) { try { var emailRecuperar = new RecoveryPassword { Email = recuperarSenha.Email, CodigoGerado = recuperarSenha.CodigoGerado, }; client.BaseAddress = uri; var json = JsonConvert.SerializeObject(emailRecuperar); var content = new StringContent(json, Encoding.UTF8, "application/json"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); HttpResponseMessage response = await client.PostAsync("Administrador/ForgotPassword/", content); string result = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { return(result); } if (result == null) { throw new Exception(response.StatusCode.ToString()); } throw new Exception(result); } catch (Exception ex) { throw new Exception(ex.Message); } } }
///este metodo se encarga de recuperar la contraseña de una cuenta via email public ActionResult RecoveryPassword([Bind(Include = "FromEmail")] EmailVM emailVM) { if (!string.IsNullOrEmpty(emailVM.FromEmail)) { UsuarioDomainModel usuarioDM = usuarioBusiness.ValidarEmailPasswordrecovery(emailVM.FromEmail.ToLower()); if (usuarioDM != null) { emailVM.FromNombre = usuarioDM.Nombres + " " + usuarioDM.Apellidos; emailVM.Asunto = Recursos.RecursosAdmin.RECUPERACION_PASSWORD_MAIL; emailVM.Mensaje = Recursos.RecursosAdmin.MENSAJE_PASSWORD_RECOVERY + " Tu Password es: " + Funciones.Decrypt(usuarioDM.Clave); emailVM.FromEmail = usuarioDM.Email.ToLower(); EmailDomainModel emailDM = new EmailDomainModel(); RecoveryPassword recovery = new RecoveryPassword(); AutoMapper.Mapper.Map(emailVM, emailDM); if (recovery.RecuperarPasswordAccount(emailDM)) { return(RedirectToAction("SuccessRecoveryPassword", "Account"));//vista a donde se envia el mensaje de exito } } } ///regresa a un page de error return(RedirectToAction("NoEmailRecovery", "Error")); }
public async Task <Result> Send(Model model) { var user = db.Users.SingleOrDefault(s => s.Email == model.Email); if (user == null) { throw new ForbiddenException(); } if (user.DeletedAt != null) { throw new NotFoundException(); } var fromAddress = new MailAddress(configuration["Email:Email"]); var fromPassword = configuration["Email:Password"]; var toAddress = new MailAddress(user.Email); var recordecovery = new RecoveryPassword { UserId = user.Id, CreatedAt = DateTime.Now.AddMinutes(30), }; db.RecoveryPasswords.Add(recordecovery); await db.SaveChangesAsync(); string subject = "Recuperação de senha"; var encripty = new RecoveryPassword().Encrypt(recordecovery.Id.ToString()); string body = $"O link que você precisa acessar para redefimir a sua senha é http://getProgramadora.com.br/ResetPassword/{ encripty }"; try { SmtpClient smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 465, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var email = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) await smtp.SendMailAsync(email); return(new Result { Message = "O Email para recuperação de senha foi enviado para " + user.Email }); } catch (Exception ex) { { throw ex; } } }