Example #1
0
    def send_request(self):
        # Todo: Send request to server
        # try for server present
        try:

            email = self.lineEdit_email.text()
        except:
            pop_alert("Błąd sieci, sprawdź połączenie.")
Example #2
0
    def friend_req_repsponse(self, data):
        friend_name = data['sender']
        if data['response'] == 'True':
            pop_alert(f"{friend_name} Cię dodał do znajomych!")
        #  self.setup_contacts()

        else:
            pop_alert(f"{friend_name} Cię odrzucił")
Example #3
0
 def send_request_to_server(self):
     # try for server present
     try:
         login = self.lineEdit_login.text()
         password = self.lineEdit_pass.text()
         first_name = self.lineEdit_fname.text()
         last_name = self.lineEdit_sname.text()
         email = self.lineEdit_sname.text()
         url = self.LoginWindow.URLs[0] + '/chat/rest-auth/registration/'
         payload = {
             'username': login,
             'password1': password,
             'password2': password
         }
         r = requests.post(url, data=payload)
         if r.status_code == 400:
             pop_alert(
                 "Błąd rejstracji, spróbuj ponownie z innym hasłem lub loginem"
             )
             return False
         elif r.status_code != 201:
             pop_alert("Błąd rejstracji, spróbuj ponownie")
             return False
         return True
     except:
         pop_alert("Błąd sieci, sprawdź połączenie.")
Example #4
0
    def login_button_pressed(self):
        username = self.lineEdit_username.text()
        password = self.lineEdit_password.text()

        # Validate input data
        if not self.validate_data(username, password):
            self.lineEdit_username.setPlaceholderText("Podaj najpierw login i hasło!")
            return

        # remember user login data
        if self.checkBox_remember.isChecked():
            self.save_users_credentials(username, password)
        else:
            self.delete_users_credentials()

        # try for present server
        try:
            url = self.URLs[0] + '/chat/api-token-auth/'
            payload = {'username': username, 'password': password}
            r = requests.post(url, data=payload)
            if r.status_code == 200:
                self.close()
                data = r.json()
                token = data["token"]
                user_id = data["user_id"]
                if not self.opened_main_window:
                    self.open_main_window(token, user_id)
                self.opened_main_window = True

            else:
                pop_alert("Niepoprawne dane logowania!")
        except requests.ConnectionError:

            # Todo okienko z bledem sieci
            print("Błąd serwera")
            pop_alert("Błąd sieci, sprawdź połączenie.")
    def confirm_button_pressed(self):
        # Check old pass
        if not self.check_old_password():
            self.lineEdit_old_pass.setText("")
            self.lineEdit_new_pass1.setText("")
            self.lineEdit_new_pass2.setText("")
            pop_alert("Błędne hasło")
            return
        # Validate and check new password
        if not self.check_password():
            self.lineEdit_new_pass1.setText("")
            self.lineEdit_new_pass2.setText("")
            pop_alert("Podane hasła się różnią")
            return
        if not validate_password(self.lineEdit_new_pass1.text()):
            self.lineEdit_new_pass1.setText("")
            self.lineEdit_new_pass2.setText("")
            pop_alert(
                f"Hasło nie spełnia warunków.\nPowinno składać się \nz minimum {self.minimum_pass_len} znaków"
            )
            return

        self.send_request()
        self.close()
Example #6
0
 def send_button_pressed(self):
     if not validate_email(self.lineEdit_email.text()):
         pop_alert("Podaj poprawnego maila!")
         return
     self.send_request()
     self.close()
Example #7
0
 def handle_responses(self, data):
     admin_name = data['admin']
     title = data['title']
     pop_alert(f"{admin_name} Cię dodał do grupy {title}!")
Example #8
0
 def handle_friend_request(self, data):
     request_id = int(data['request_id'])
     sender_name = data['sender']
     timestamp = data['timestamp']
     pop_alert("Nowe Zaproszenie!")
Example #9
0
    def show_messages(self, item=None):
        """make sending message possible"""
        self.list_messages.clear()
        self.button_send_message.setEnabled(True)
        button_load_messages = QtWidgets.QPushButton("więcej wiadomości")
        item_widget = QtWidgets.QListWidgetItem()
        widget = QtWidgets.QWidget()
        widget_layout = QtWidgets.QVBoxLayout()
        widget_layout.addWidget(button_load_messages)
        widget_layout.addStretch()
        widget_layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
        widget.setLayout(widget_layout)
        item_widget.setSizeHint(widget.sizeHint())
        self.list_messages.addItem(item_widget)
        self.list_messages.setItemWidget(item_widget, widget)
        """show messages between you and given contact named 'item'"""
        contact = item.text() if item is not None else self.current_contact
        if item is not None:
            messages.pop(self.current_contact, None)
            if self.current_contact in self.initialised_conversations:
                self.initialised_conversations.remove(self.current_contact)
        button_load_messages.clicked.connect(self.get_more_messages)

        self.current_contact = contact

        conversation_id = self.conversation_ids[contact]
        self.request_key(conversation_id)
        if not self.key_manager.contains_conversation(
                conversation_id):  # send a request for the RSA key
            self.request_key(conversation_id)
            pop_alert("Poczekaj na wygenerowanie")
            return
            # TODO we must wait for the key from conversation admin, leave this function/tell user about it

        if contact not in self.initialised_conversations:
            self.get_messages(contact)
            contact_messages = messages[contact]
            self.initialised_conversations.append(contact)
        contact_messages = messages.get(contact, [])
        for message_info in contact_messages:
            sender = message_info.split(':')[0]
            message = message_info[len(sender) + 2:]
            message = split_message(message, 26)
            item_widget = QtWidgets.QListWidgetItem()
            widget_message = QtWidgets.QLabel(message)
            widget_message.setWordWrap(True)
            widget = QtWidgets.QWidget()
            if sender != username:
                widget_message.setStyleSheet("max-width: 225px;\n"
                                             "border-radius: 10px;\n"
                                             "background: #ffcccc;\n"
                                             "border: 5px solid #ffcccc;\n"
                                             "font-size: 11px;")
                sender_label = QtWidgets.QLabel(sender)
                widget_layout = QtWidgets.QVBoxLayout()
                widget_layout.addWidget(sender_label)
                widget_layout.addWidget(widget_message)
                widget_layout.addStretch()
                widget_layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
                widget.setLayout(widget_layout)
                item_widget.setSizeHint(widget.sizeHint())
                self.list_messages.addItem(item_widget)
                self.list_messages.setItemWidget(item_widget, widget)
            else:
                widget_message.setStyleSheet("border-radius: 10px;\n"
                                             "background: lightgray;\n"
                                             "border: 5px solid lightgray;\n"
                                             "margin-left: 200px;"
                                             "font-size: 11px;")
                widget_layout = QtWidgets.QHBoxLayout()
                widget_layout.addWidget(widget_message)
                widget_layout.addStretch()
                widget_layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
                widget.setLayout(widget_layout)
                item_widget.setSizeHint(widget.sizeHint())
                self.list_messages.addItem(item_widget)
                self.list_messages.setItemWidget(item_widget, widget)
            self.list_messages.scrollToBottom()
Example #10
0
    def register_button_pressed(self):
        # Firstly check for empty labels
        if self.lineEdit_login.text() == "" or \
                self.lineEdit_pass.text() == "" or \
                self.lineEdit_pass2.text() == "" or \
                self.lineEdit_fname.text() == "" or \
                self.lineEdit_sname.text() == "" or \
                self.lineEdit_email.text() == "" or \
                self.lineEdit_email2.text() == "":
            pop_alert("Uzupełnij wszystkie pola")
            return

        # Check data
        if not self.check_password():
            self.lineEdit_pass.setText("")
            self.lineEdit_pass2.setText("")
            pop_alert("Podane hasła się różnią")
            return
        if not self.check_email():
            self.lineEdit_email.setText("")
            self.lineEdit_email2.setText("")
            pop_alert("Podane adresy email się różnią")
            return

        if not self.check_username_availability(self.lineEdit_login.text()):
            self.lineEdit_login.setText("")
            pop_alert("Ten login jest już zajęty!")
            return

        # Validate data
        if not validate_password(self.lineEdit_pass.text()):
            self.lineEdit_pass.setText("")
            self.lineEdit_pass2.setText("")
            pop_alert(
                f"Hasło nie spełnia warunków.\nPowinno składać się \nz minimum {self.minimum_pass_len} znaków"
            )
            return
        if not validate_email(self.lineEdit_email.text()):
            self.lineEdit_email.setText("")
            self.lineEdit_email2.setText("")
            pop_alert("Podaj poprawne adres email")
            return

        passed = self.send_request_to_server()
        if passed:
            self.close()
        else:
            self.lineEdit_pass.setText("")
            self.lineEdit_pass2.setText("")