コード例 #1
0
        public IActionResult TryLogin(LoginViewModel model)
        {
            User user = new User
            {
                Username     = model.Username,
                PasswordHash = model.Password
            };

            if (accountLogic.CheckLoginCredentials(user) && ModelState.IsValid)
            {
                IUser tempUser = accountLogic.GetUserByName(model.Username);
                HttpContext.Session.SetInt32(SessionHolder.SessionUserId, tempUser.Id); //Todo Change this to auth token
                string username = model.Username;
                if (username.Length > 10)
                {
                    username = username.Substring(0, 10);
                }
                HttpContext.Session.SetString(SessionHolder.SessionUsername, username);
                HttpContext.Session.SetString(SessionHolder.SessionUserImg, tempUser.ImgLocation);
                return(RedirectToAction("Index", "Release"));
            }
            ModelState.AddModelError(string.Empty, "Invalid username and password combination");
            return(View("Login", model));
        }