Пример #1
0
 def login(user, user_directory):
     data = JsonConstructor.build_json(SignupLoginJsonStrategy(user))
     response = ServerBoundary.send_request(LoginCommand(data)).json()
     rsa_config = RSAConfig(user_directory)
     user_config = UserConfig(user_directory)
     session = Session(user, response["data"], rsa_config, user_config)
     return session
    def send_message(self, message_text, recipient_email):

        if isinstance(message_text, str):
            message_text = message_text.encode("utf-8")
        elif isinstance(message_text, bytes):
            raise TypeError(
                "The argument 'message_text' is not of type 'str' or type 'bytes'"
            )

        message_obj = PlaintextMessage(message_text)
        # "C:\\Users\\tlindblom\\RSAKeys\\public.pem"
        controller = EncryptionController(
            message_obj, self._session.rsa_config.friends_rsa[recipient_email])
        encrypted_message_obj = controller.encrypt_message()

        if encrypted_message_obj is None:
            print("\nUnable to send message")

        else:
            json_data = JsonConstructor.build_json(
                SendMessageJsonStrategy(self._session.user,
                                        encrypted_message_obj,
                                        recipient_email))
            r = ServerBoundary.send_request(
                SendMessageCommand(json_data, self._session.token))
Пример #3
0
 def get_messages(session):
     data = JsonConstructor.build_json(
         CheckMessagesJsonStrategy(
             session.user, session.user_config.config_data["message poll"]))
     session.user_config.update_message_poll()
     response = ServerBoundary.send_request(
         CheckMessagesCommand(data, session.token)).json()
     return JsonDeconstructor.deconstruct_json(
         ReceiveMessagesStrategy(response))
Пример #4
0
    def get_pending_friend_requests(session):
        data = JsonConstructor.build_json(
            GetPendingFriendRequestsJsonStrategy(
                session.user, session.user_config.config_data["request poll"]))
        session.user_config.update_request_poll()
        response = ServerBoundary.send_request(
            GetPendingFriendRequestsCommand(data, session.token)).json()
        requests = response["data"]

        if len(requests) > 0:
            for requester in requests:
                GetPendingFriendRequestController._accept_reject_requests(
                    session, requester,
                    session.rsa_config.my_rsa["public key"])
        else:
            print("\nYou have no pending friend requests!")
Пример #5
0
 def _add_friend(primary_user, email_of_requester, token):
     data = JsonConstructor.build_json(
         AddFriendJsonStrategy(primary_user, email_of_requester))
     response = ServerBoundary.send_request(AddFriendCommand(data, token))
Пример #6
0
 def send_friend_request(session, recipient_username):
     data = JsonConstructor.build_json(
         SendFriendRequestJsonStrategy(session.user, recipient_username))
     ServerBoundary.send_request(
         SendFriendRequestCommand(data, session.token))
Пример #7
0
 def _get_friends(session):
     data = JsonConstructor.build_json(GetFriendsJsonStrategy(session.user))
     response = ServerBoundary.send_request(GetFriendsCommand(data, session.token)).json()
     return response["data"]