Example #1
0
        public void logout(int userId, ILibraryClient client)
        {
            ILibraryClient localClient = loggedClients[userId];

            loggedClients.Remove(userId);
            if (localClient == null)
            {
                throw new LibraryException("User " + userId + " is not logged in.");
            }
        }
        public void logout(int userId, ILibraryClient client)
        {
            sendRequest(new Request(RequestType.LOGOUT, userId));
            Response response = readResponse();

            closeConnection();
            if (response.Type == ResponseType.ERROR)
            {
                string err = (string)response.Data;
                throw new LibraryException(err);
            }
        }
Example #3
0
        public void logout(int userId, ILibraryClient client)
        {
            sendRequest(new LogoutRequest(userId));
            Response response = readResponse();

            closeConnection();
            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new LibraryException(err.Message);
            }
        }
Example #4
0
 private void closeConnection()
 {
     finished = true;
     try
     {
         stream.Close();
         //output.close();
         connection.Close();
         _waitHandle.Close();
         client = null;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.StackTrace);
     }
 }
Example #5
0
        public BookService(ILibraryClient libraryClient, IOptions <List <User> > authUsers, IOptions <ServiceUrls> serviceUrl)
        {
            _libraryClient = libraryClient;
            _serviceUrl    = serviceUrl;
            var user     = authUsers.Value.First();
            var coreUser = new LibraryCore.Models.User
            {
                ClaimName = user.ClaimName,
                Password  = user.Password
            };
            var accessToken = _libraryClient.GenerateAccessToken(coreUser);

            _headers = new Dictionary <string, string>
            {
                { "Authorization", accessToken }
            };
        }
Example #6
0
        public User login(String userName, String password, ILibraryClient client)
        {
            User user = userRepository.verifyUser(userName, password);

            if (user != null)
            {
                if (loggedClients.ContainsKey(user.Id))
                {
                    throw new LibraryException("User already logged in.");
                }
                loggedClients.Add(user.Id, client);
            }
            else
            {
                throw new LibraryException("Authentication failed.");
            }
            return(user);
        }
        public User login(string userName, string password, ILibraryClient client)
        {
            initializeConnection();
            User    user    = null;
            UserDTO userDto = new UserDTO(userName, password);

            sendRequest(new Request(RequestType.LOGIN, userDto));
            Response response = readResponse();

            if (response.Type == ResponseType.ERROR)
            {
                string err = (string)response.Data;
                closeConnection();
                throw new LibraryException(err);
            }
            if (response.Type == ResponseType.LOGIN_SUCCESSFULLY)
            {
                user        = (User)response.Data;
                this.client = client;
            }
            return(user);
        }
Example #8
0
        public User login(string userName, string password, ILibraryClient client)
        {
            initializeConnection();
            User    user    = null;
            UserDTO userDto = new UserDTO(userName, password);

            sendRequest(new LoginRequest(userDto));
            Response response = readResponse();

            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                closeConnection();
                throw new LibraryException(err.Message);
            }
            if (response is UserLoggedInResponse)
            {
                UserLoggedInResponse userLoggedInResponse = (UserLoggedInResponse)response;
                user        = userLoggedInResponse.User;
                this.client = client;
            }
            return(user);
        }