public ActionResult VerifyRegister(Registration regs, string id) { ViewBag.code = TempData.Peek("code").ToString(); string session = (string)System.Web.HttpContext.Current.Session["IDUser"]; if (id == null) { return(RedirectToAction("Login", "Main")); } else if (session == null) { return(RedirectToAction("Login", "Main")); } else { if (ModelState.IsValid) { using (ASPMVCDB db = new ASPMVCDB()) { var obj = db.Registration.Where(model => model.Id.Equals(session)).FirstOrDefault(); if (obj != null) { if (obj.VerifyActivationCode == regs.UserActivationCode) { var ObjUpdate = db.Registration.Find(obj.Id); ObjUpdate.UserActivationCode = obj.VerifyActivationCode; db.Entry(ObjUpdate).State = EntityState.Detached; db.Entry(ObjUpdate).State = EntityState.Modified; db.SaveChanges(); TempData.Remove("code"); long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; Session["TOURING"] = "SIMPLE_TOUR_STARTED_IN" + milliseconds.ToString().Substring(1, 5) + "ERA"; } else { ViewBag.Color = "red"; ViewBag.Message = "Wrong Verification Code"; return(View()); } } else { ViewBag.Color = "red"; ViewBag.Message = "Your ID Is Not Found"; return(View()); } } } return(RedirectToRoute("SimpleTour")); } }
public ActionResult ChangePassword(Registration regs, string id) { string session = (string)System.Web.HttpContext.Current.Session["ID"]; if (id == null) { return(RedirectToAction("Login", "Main")); } else if (session == null) { return(RedirectToAction("Login", "Main")); } else if (regs.ConfirmPassword != regs.Password) { long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; return(RedirectToRoute("ChangePassword", new { id = milliseconds })); } else { if (ModelState.IsValid) { using (ASPMVCDB db = new ASPMVCDB()) { var obj = db.Registration.Where(model => model.Id.Equals(session)).FirstOrDefault(); if (obj != null) { string encoded = Encryption(regs.Password); var ObjUpdate = db.Registration.Find(obj.Id); ObjUpdate.Password = encoded; ObjUpdate.ConfirmPassword = encoded; db.Entry(ObjUpdate).State = EntityState.Detached; db.Entry(ObjUpdate).State = EntityState.Modified; db.SaveChanges(); Session.Clear(); Session.Abandon(); } else { ViewBag.Color = "red"; ViewBag.Message = "Your ID Is Not Found"; return(View()); } } } return(RedirectToAction("Login", "Main")); } }
public ActionResult Login(Registration regs) { string encoded = Encryption(regs.Password); if (ModelState.IsValid) { using (ASPMVCDB db = new ASPMVCDB()) { //get username dan password dari DB var obj = db.Registration.Where(model => model.Username.Equals(regs.Username) && model.Password.Equals(encoded)).FirstOrDefault(); if (obj != null) { if (obj.VerifyActivationCode == obj.UserActivationCode) { /*UPDATE SESSION ISACTIVE JADI 1*/ var ObjUpdate = db.Registration.Find(obj.Id); String isActive = ObjUpdate.IsActive; ObjUpdate.IsActive = "1"; db.Entry(ObjUpdate).State = EntityState.Detached; db.Entry(ObjUpdate).State = EntityState.Modified; db.SaveChanges(); /************************************/ Session["UserID"] = obj.Id; Session["isActive"] = obj.IsActive; Session["UserName"] = obj.Username; return(RedirectToRoute("Main")); } else { ViewBag.Color = "red"; ViewBag.Message = "You're not verified your account"; return(View()); } } else { ViewBag.Color = "red"; ViewBag.Message = "Wrong Username or Password"; return(View()); } } } return(View(regs)); }