public ActionResult Logowanie(USERS USERS) { var isPasswordsNull = registerRepository.PasswordNotNull(USERS); var IsMailNotNull = registerRepository.IsMailNotNull(USERS); if (IsMailNotNull) { ModelState.AddModelError("MAIL", "Należy podać maila"); return(View()); } else if (isPasswordsNull) { ModelState.AddModelError("PASSWORD", "Należy podać hasło"); return(View()); } else { USERS.PASSWORD = registerRepository.Encryption(USERS.PASSWORD); var userLoggedIn = db.USERS.SingleOrDefault(x => x.MAIL == USERS.MAIL && x.PASSWORD == USERS.PASSWORD); if (userLoggedIn != null) { Session["ID"] = userLoggedIn.USER_ID; Session["MAIL"] = userLoggedIn.MAIL; Session["FNAME"] = userLoggedIn.FNAME; return(RedirectToAction("Index", "Home", new { ID = USERS.USER_ID })); } else { ViewBag.Message = "Podane dane logowania są błędne"; ModelState.Clear(); return(View()); } } }
public ActionResult EditPassword(UserEditPassword form) { ViewBag.Message = null; if (Session["ID"] != null) { int uID = Convert.ToInt32(Session["ID"]); USERS Currentuser = new UserRepository().GetUserData(uID); if (ModelState.IsValid) { var EncryptedOldPassword = registerRepository.Encryption(form.OldPassword); if (EncryptedOldPassword == Currentuser.PASSWORD) { Currentuser.PASSWORD = registerRepository.Encryption(form.NewPassword); db.Entry(Currentuser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); ViewBag.Message = "Hasło zmienione"; return(View()); } else { ViewBag.Message = "Podano złe aktualne hasło"; return(View()); } } else { return(View()); } } return(RedirectToAction("Logowanie", "Home")); }