public ActionResult Register(UserAcount acount) { if (ModelState.IsValid) { using (UserDataContext db = new UserDataContext()) { var CheckUser = db.userAcount.Where(u => u.UserName.ToLower() == acount.UserName.ToLower()).FirstOrDefault(); if (CheckUser == null) { db.userAcount.Add(acount); db.SaveChanges(); ViewBag.Message = "X1"; return RedirectToAction("login"); } else { ModelState.AddModelError("", "Username is alredy used"); ViewBag.Message = "X2"; return View(); } } //ModelState.Clear(); loadViewBag(); } return View("Login"); }
public ActionResult Login(UserAcount user) { using (UserDataContext db = new UserDataContext()) { var usr = db.userAcount.Where(u => u.UserName == user.UserName && u.Password == user.Password).FirstOrDefault(); if (usr != null) { Session["UserID"] = usr.UserID.ToString(); Session["UserName"] = usr.UserName.ToString(); return RedirectToAction("HostListing", "Host"); } else { ModelState.AddModelError("", "Username or Password is Wrong"); } } return View(); }
public ActionResult ResetPassword(UserAcount user) { using (UserDataContext db = new UserDataContext()) { string TempPassword = GeneratePassword().ToString(); var usr = db.userAcount.Where(u => u.Email.ToLower() == user.Email.ToLower()).FirstOrDefault(); if (usr != null) { usr.Password = TempPassword.ToString(); usr.ConfirmPassword = TempPassword.ToString(); db.SaveChanges(); // SendMail(user.Email, TempPassword); return RedirectToAction("Login"); } else { ModelState.AddModelError("", "Rat Matyueb Shena?"); } } return View(); }