// GET: ConfirmAction public ActionResult Index() { using (OrderSystemEntities2 db = new OrderSystemEntities2()) { int uID = (Int32)(Session["id"]); Random rnd = new Random(); int otp = rnd.Next(1000, 10000); otp_table exist_otp = db.otp_table.Where(x => x.uId == uID).FirstOrDefault(); if (exist_otp != null) { exist_otp.otp = otp; exist_otp.create_time = DateTime.Now; db.SaveChanges(); } else { otp_table otp_ = new otp_table() { uId = uID, create_time = DateTime.Now, otp = otp }; db.otp_table.Add(otp_); db.SaveChanges(); } ViewBag.code = otp; return(View()); } }
public ActionResult Cancel(int oID, int otp, string reason) { using (OrderSystemEntities2 db = new OrderSystemEntities2()) { otp_table _otp = db.otp_table.Where(x => x.otp == otp).FirstOrDefault(); if (_otp == null) { ViewBag.error = "Mã xác thực sai, vui lòng kiểm tra lại!"; return(View()); } else { var otp_time = _otp.create_time; var now = DateTime.Now; if ((now - otp_time).TotalMinutes > 2) { ViewBag.error = "Mã xác thực đã hết hạn, vui lòng kiểm tra lại"; return(View()); } else { UpdateCancel(oID, reason); return(RedirectToAction("Index", "QRScanner")); } } } }
private void SendActivationEmail(user user) { Random rand = new Random(); int otpcode = rand.Next(minValue: 1000, maxValue: 10000); otp_table otp = db.otp_table.Add(new otp_table { uId = user.id, otp = otpcode, create_time = DateTime.Now }); db.SaveChanges(); using (MailMessage mm = new MailMessage("*****@*****.**", user.email)) { mm.Subject = "Kích hoạt tài khoản"; string body = "<div style='font - family: Segoe UI; margin: 0; color: #707070;font-size:16px;'>"; body += "<div style='max - width:800px; width: 100 %; margin: 0 auto; '>"; body += "<img style='width: 100 % ' src='https://i.pinimg.com/564x/f9/98/86/f99886a97ba4e7b0aa4d8b33e00b060c.jpg' />"; body += "<div style='padding: 1.5rem; color: #707070;'>"; body += " <h3 style='color:#069B4F; font-size:24px;'>Đăng ký thành công</h3>"; body += "Xin chào " + user.name + ","; body += "<br /><br />Chúc mừng bạn đã đăng ký thành công !"; body += "<br /><br />Hãy ấn vào đường link dưới đây để kích hoạt tài khoản của bạn"; body += "<br /><a href = '" + string.Format("{0}://{1}/Register/Activation/{2}", Request.Url.Scheme, Request.Url.Authority, otpcode) + "'>Ấn vào đây !</a>"; body += "<br /><br />Cảm ơn và chúc bạn một ngày tốt lành !"; mm.Body = body; mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential("*****@*****.**", "anhdaica1"); smtp.UseDefaultCredentials = false; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); } }