Esempio n. 1
0
        public IActionResult Login(UserModel user)
        {
            int?userId;

            if ((userId = _userRepository.GetUserIdFullMatch(user)) != null)
            {
                AuthHelper.AddUserToSession(HttpContext, (int)userId);
                return(Ok());
            }

            return(BadRequest("Invalid username or password"));
        }
Esempio n. 2
0
        public IActionResult Register(UserModel user)
        {
            if (_userRepository.GetUserIdByUsername(user.Username) != null)
            {
                return(BadRequest("This username is already used!"));
            }

            int?userId = _userRepository.Create(user);

            if (userId == null)
            {
                return(StatusCode(500));
            }

            AuthHelper.AddUserToSession(HttpContext, (int)userId);

            return(Ok());
        }