コード例 #1
0
        public IActionResult Login(LoginCredentials creds)
        {
            var personDal = new PersonDAL(_configuration);
            var compact   = personDal.CheckUser(creds.UserName, creds.Password);

            if (compact == null)
            {
                ViewBag.LoginMessage  = "Invalid Credentials, please try again.";
                ViewBag.ShowLoginForm = true;
            }
            else
            {
                HttpContext.Session.SetString(personIdKey, compact.PersonId.ToString());
                HttpContext.Session.SetString(firstNameKey, compact.FirstName);
                ViewBag.UserFirstName = compact.FirstName;
                ViewBag.ShowLoginForm = false;
                ViewBag.LoginMessage  = string.Empty;
                return(RedirectToAction("Index"));
            }

            return(View("Index"));
        }