public override void ExecuteResult(ControllerContext context) { //context.HttpContext.Response.Write("something"); context.HttpContext.Session["CaptchaImageText"] = ClasesVarias.Generar_Clave(); // Create a CAPTCHA image using the text stored in the Session object. RandomImage ci = new RandomImage(context.HttpContext.Session ["CaptchaImageText"].ToString(), 300, 75); // Change the response headers to output a JPEG image. context.HttpContext.Response.Clear(); context.HttpContext.Response.ContentType = "image/jpeg"; // Write the image to the response stream in JPEG format. ci.Image.Save(context.HttpContext.Response.OutputStream, ImageFormat.Jpeg); // Dispose of the CAPTCHA image object. ci.Dispose(); }
//public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model) public ActionResult ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { if (!(model.Captcha.Equals(this.HttpContext.Session["CaptchaImageText"]))) { ModelState.AddModelError("", Resources.LoginResource.CaptchaErrorMessge); } using (SeguricelEntities db = new SeguricelEntities()) { Usuario dataUsuario = (from u in db.Usuario where (u.CodigoUsuario == model.Email | u.Email == model.Email) select u).FirstOrDefault(); if ((dataUsuario != null) && ((model.Captcha.Equals(this.HttpContext.Session["CaptchaImageText"])))) { //Generar nueva clave y enviarla por correo string nuevaclave = ClasesVarias.Generar_Clave(); Encrypt.InicioClaves("53gur1cel!n37", "4LC_C0MUN1C4C10N35@S3GUR1C3L!N37", "53gur1c3l!4lcC0mun1c4c10n35@s3gur1c3lgm41l!c0m", 5); string nuevaclaveenc = Encrypt.Encriptar(nuevaclave, Encriptador.HasAlgorimt.SHA1, Encriptador.Keysize.KS256); db.Database.ExecuteSqlCommand("update Usuario set ClaveUsuario=@p0 where CodigoUsuario=@p1 or Email=@p1", new SqlParameter("@p0", nuevaclaveenc), new SqlParameter("@p1", model.Email)); System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); /*SendEmail msg = new SendEmail(); * msg.PARA(model.Email); * msg.DE("*****@*****.**","Seguricel"); * msg.Puerto = "587"; * msg.SERVIDOR_SMTP("smtp.gmail.com"); * msg.HABILITO_Ssl(true); * msg.CREDENCIALES("*****@*****.**", "Seguricel1234"); * msg.CUERPO_EMAIL(EmailOlvidoClaveText("","", model.Email, nuevaclave)); * msg.PRIORIDAD_ENTREGA(PrioridadEntrega.ALTA); * msg.Enviar();*/ //msg.To.Add("*****@*****.**"); msg.To.Add(model.Email); msg.From = new MailAddress("*****@*****.**", "Seguricel", System.Text.Encoding.UTF8); msg.Subject = "Cambio de usuario y contraseña para su acceso a SEGURICEL®. "; msg.SubjectEncoding = System.Text.Encoding.UTF8; msg.Body = EmailOlvidoClaveText("", "", model.Email, nuevaclave); msg.BodyEncoding = System.Text.Encoding.UTF8; msg.IsBodyHtml = false; //Aquí es donde se hace lo especial SmtpClient client = new SmtpClient(); client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Seguricel1234"); client.Port = 587; client.Host = "smtp.gmail.com"; client.EnableSsl = true; //Esto es para que vaya a través de SSL que es obligatorio con GMail try { client.Send(msg); } catch (System.Net.Mail.SmtpException ex) { Console.WriteLine(ex.Message); Console.ReadLine(); ModelState.AddModelError("", Resources.LoginResource.SendEmailMessage); return(View(model)); } return(View("ForgotPasswordConfirmation")); } else { //ModelState.AddModelError("", Resources.LoginResource.EmailAddressNotExistMessge); return(View("ForgotPasswordConfirmation")); } } // var user = await UserManager.FindByNameAsync(model.Email); // if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) // { // // No revelar que el usuario no existe o que no está confirmado // return View("ForgotPasswordConfirmation"); // } // // Para obtener más información sobre cómo habilitar la confirmación de cuenta y el restablecimiento de contraseña, visite http://go.microsoft.com/fwlink/?LinkID=320771 // // Enviar correo electrónico con este vínculo // // string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); // // var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // // await UserManager.SendEmailAsync(user.Id, "Restablecer contraseña", "Para restablecer la contraseña, haga clic <a href=\"" + callbackUrl + "\">aquí</a>"); // // return RedirectToAction("ForgotPasswordConfirmation", "Account"); } //// Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario return(View(model)); }