public ActionResult Recovery(Models.ViewModel.RecoveryPasswordViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } using (Models.plataformaEntities db = new Models.plataformaEntities()) { var oUser = db.usuario.Where(d => d.TokenRecovery == model.token).FirstOrDefault(); if (oUser != null) { oUser.Contraseña = model.Password; oUser.TokenRecovery = null; db.Entry(oUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } } catch (Exception ex) { throw new Exception(ex.Message); } ViewBag.Message = "Contraseña modificada con exito"; return(View("Index", "Logueo")); }
public ActionResult StartRecovery(Models.ViewModel.RecoveryViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } string token = GetSha256(Guid.NewGuid().ToString()); using (Models.plataformaEntities db = new Models.plataformaEntities()) { var oUser = db.usuario.Where(d => d.Correo == model.Email).FirstOrDefault(); if (oUser != null) { oUser.TokenRecovery = token; db.Entry(oUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); //enviamos email SendEmail(oUser.Correo, token); } } return(View()); } catch (Exception es) { throw new Exception(es.Message); } }