public ActionResult Recovery(Models.ViewModels.RecoveryPasswordViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } using (Models.cursomvcEntities1 db = new Models.cursomvcEntities1()) { var oUser = db.user.Where(d => d.token_recovery == model.token).FirstOrDefault(); if (oUser != null) { oUser.password = model.Password; oUser.token_recovery = 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 éxito"; return(View("User/Index")); }
public ActionResult StartRecovery(Models.ViewModels.RecoveryViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } string token = GetSha256(Guid.NewGuid().ToString()); using (Models.cursomvcEntities1 db = new Models.cursomvcEntities1()) { var oUser = db.user.Where(d => d.email == model.Email).FirstOrDefault(); if (oUser != null) { oUser.token_recovery = token; db.Entry(oUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); //enviar mail SendEmail(oUser.email, token); } } return(View()); } catch (Exception ex) { throw new Exception(ex.Message); } }