public ActionResult QuenMatKhau(QuenMatKhau model) { if (db.TaiKhoans.Any(x => x.Email == model.Email)) { TaiKhoan t = db.TaiKhoans.Where(x => x.Email == model.Email).FirstOrDefault(); idrecover = t.Id; string code = TaoMaXacNhan.RandomString(); if (db.MaXacNhans.Any(x => x.UserId == idrecover)) { MaXacNhan macu = db.MaXacNhans.Where(x => x.UserId == idrecover).First(); db.MaXacNhans.Remove(macu); } MaXacNhan maxn = new MaXacNhan(); maxn.Code = code; maxn.UserId = idrecover; db.MaXacNhans.Add(maxn); db.SaveChanges(); QuenMatKhau mail = new QuenMatKhau(); string bodymail = mail.BodyMail_LayLaiMatKhau(model.Email, code); string ThongBao = mail.Send("Lấy lại mật khẩu", bodymail, model.Email, true, true); ViewBag.ThongBao = ThongBao; } return(RedirectToAction("LayMaXacNhan")); }
public ActionResult LayMaXacNhan(LayMaXacNhan model) { MaXacNhan maxn = db.MaXacNhans.Find(model.Code); if (maxn != null) { if (maxn.UserId == idrecover) { return(RedirectToAction("MatKhauMoi")); } } return(View()); }