Beispiel #1
0
class Password_rec(QDialog):
    """диалоговое окно на случай если юзер забыл пароль"""
    forbidden_chars = "?&="

    def __init__(self, *args):
        super().__init__()

        self.client_path = os.getcwd().rsplit("\\", maxsplit=1)[0]
        self.uic_auth = os.path.join(self.client_path, "ui files",
                                     "pass_rec.ui")
        uic.loadUi(self.uic_auth, self)

        self.network = False

        self.btn_recovery.clicked.connect(self.recovery_pass)

    def my_errors(self, error):
        msg = QMessageBox(self)
        msg.setText(error)
        msg.show()
        return False

    def part_checker(self, login, secret):
        for word, type_ in zip([login, secret], ['Логин', "Секретное слово"]):
            if len(word.replace(' ', '')) == 0:
                return self.my_errors(f"{type_} не может быть пустой!")
            if len(word) == 0:
                return self.my_errors(f"{type_} не может быть пустой!")
            if any(ch in self.forbidden_chars for ch in word):
                return self.my_errors(
                    f"{type_} не может содержать символы '?&='")

        return True

    def recovery_pass(self):
        login, secret = [x.text() for x in [self.edit_login, self.edit_secret]]

        if not self.part_checker(login, secret):
            return False

        if self.network is False:
            self.network = Client()

        command = f"password_reset?login={login}&secret={secret}"
        result, data = self.network.command_send(command).split('?')
        if result != "False":
            self.close()
        return self.my_errors(data)
Beispiel #2
0
class SeeBattle_Auth(QMainWindow):
    """Окно для авторизации"""
    forbidden_chars = "?&="

    def __init__(self, *args):
        self.client_path = os.getcwd().rsplit("\\", maxsplit=1)[0]

        super().__init__()

        self.uic_auth = os.path.join(self.client_path, 'ui files',
                                     'auth_form.ui')
        uic.loadUi(self.uic_auth, self)

        self.network = False

        self.widget_functions()

        with open(os.path.join(self.client_path, 'settings', 'checker_ip.inf'),
                  'r') as f:
            data = [line.split()[1] for line in f.read().split('\n')]
            self.checkers_ip, self.checkers_port = data
        self.checkers_port = int(self.checkers_port)

    def widget_functions(self):
        self.btn_auth.clicked.connect(self.sign_in)
        self.btn_sign_up.clicked.connect(self.sign_up)

    def mousePressEvent(self, event):
        x, y = event.x(), event.y()
        if 40 <= x <= 121 and 210 <= y <= 226:
            self.recovery_pass()

    def my_errors(self, error):
        # Ошибки не свзянанные с ошибками исполнения программы
        msg = QMessageBox(self)
        msg.setText(error)
        msg.show()
        return False

    def login_and_password_checker(self, login, password):
        # Проверка пароля
        for word, type_ in zip([login, password], ['Логин', "Пароль"]):
            if len(word.replace(' ', '')) == 0:
                return self.my_errors(f"{type_} не может быть пустой!")
            if len(word) == 0:
                return self.my_errors(f"{type_} не может быть пустой!")
            if any(ch in self.forbidden_chars for ch in word):
                return self.my_errors(
                    f"{type_} не может содержать символы '?&='")
        return True

    def networking_switcher(self):
        # включение клиентской части
        if self.network is False:
            self.network = Client()

    @errors_handler
    def sign_in(self):
        # авторизация
        login = self.edit_login.text()
        password = self.edit_pass.text()
        if not self.login_and_password_checker(login, password):
            return False
        self.networking_switcher()

        result, data = self.network.command_send(
            f"auth?login={login}&password={password}&ip_port={self.checkers_ip}:{self.checkers_port}"
        ).split('?')
        if result == "False":
            self.my_errors(data)
            return False

        self.close()
        self.main_menu = Game_menu(data, self)
        self.main_menu.show()

        return True

    @errors_handler
    def recovery_pass(self):
        self.pass_rec = Password_rec(self)
        self.pass_rec.show()

    @errors_handler
    def sign_up(self):
        self.sign_up = Sign_up(self)
        self.sign_up.show()
        self.close()
Beispiel #3
0
class Sign_up(QMainWindow):
    """"Окно регистрации"""
    forbidden_chars = "?&="

    def __init__(self, *args):
        super().__init__()

        self.network = False

        self.client_path = os.getcwd().rsplit("\\", maxsplit=1)[0]

        self.uic_sign_up = os.path.join(self.client_path, 'ui files',
                                        'sign_up.ui')
        uic.loadUi(self.uic_sign_up, self)

        self.btn_su.clicked.connect(self.sign_up)

    def my_errors(self, error):
        msg = QMessageBox(self)
        msg.setText(error)
        msg.show()
        return False

    def part_checker(self, login, password, secret):
        for word, type_ in zip([login, password, secret],
                               ['Логин', "Пароль", "Секретное слово"]):
            if len(word.replace(' ', '')) == 0:
                return self.my_errors(f"{type_} не может быть пустой!")
            if len(word) == 0:
                return self.my_errors(f"{type_} не может быть пустой!")
            if any(ch in self.forbidden_chars for ch in word):
                return self.my_errors(
                    f"{type_} не может содержать символы '?&='")

        return True

    def sign_up(self):
        login, password, secret = [
            x.text()
            for x in [self.edit_login, self.edit_pass, self.edit_secret]
        ]
        if not self.part_checker(login, password, secret):
            return False

        if self.network is False:
            self.network = Client()
        result = self.network.command_send(
            f"sign_up?login={login}&password={password}&secret={secret}"
        ).split('?')

        if len(result) == 1:
            result = result[0]
            self.auth_form = SeeBattle_Auth(self)
            self.auth_form.show()
            self.close()
            self.network.close()
            msg = QMessageBox(self.auth_form)
            msg.setText("You was success registred")
            msg.show()
            return True
        return self.my_errors(result[1])

    def mousePressEvent(self, event):
        x, y = event.x(), event.y()
        if 20 <= x <= 67 and 10 <= y <= 30:
            self.auth_form = SeeBattle_Auth(self)
            self.auth_form.show()
            self.close()