Ejemplo n.º 1
0
        public UserModel GetUserByCredentials(CredentialsModel credentials)
        {
            UserModel user = DB.Users.Where(u => u.UserName == credentials.Username && u.Password == credentials.Password)
                             .Select(u => new UserModel(u)).SingleOrDefault();

            return(user);
        }
Ejemplo n.º 2
0
        public IActionResult Login(CredentialsModel credentials)
        {
            try
            {
                UserModel user = userLogic.GetUserByCredentials(credentials);

                if (user == null)
                {
                    return(Unauthorized("Incorrect username or password"));
                }


                user.JwtToken = jwtHelper.GetJwtToken(user.UserName, user.UserRole);

                user.Password = null;
                return(Ok(user));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ErrorHelper.GetExceptionMessage(ex)));
            }
        }