def check_in(self): """Ввод логина и пароля, проверка, сигнал о смене окна на основное, иначе ошибка""" self.login = self.login_edit.text() self.password = self.pass_edit.text() try: funcs.check_absence(self.login, self.password) logins = [ log[0] for log in self.cur.execute( """SELECT UserLogin FROM Users""").fetchall() ] if self.login in logins: hashed_pass = \ self.cur.execute("""SELECT UserPassword FROM Users WHERE UserLogin = ?""", (self.login,)).fetchone()[0] salt = self.cur.execute( """SELECT UserSalt FROM Users WHERE UserLogin = ?""", (self.login, )).fetchone()[0] if funcs.hash_pass(self.password, salt=salt) != hashed_pass: raise excepts.BadDataError else: raise excepts.BadDataError self.switch_window.emit("general") except excepts.AbsenceError: funcs.show_message("Поля должны быть заполнены!") except excepts.BadDataError: funcs.show_message("Неверный логин или пароль!")
def set_gr(self): """установка состояния выбранного тела на график""" speed = self.fir_speed_edit.text() acceleration = self.acceleration_edit.text() time = self.time_edit.text() try: self.check_have_body() check_not_empty_values(speed, acceleration, time) speed = int(speed) acceleration = int(acceleration) time = int(time) check_good_time(time) speeds = [speed + acceleration * t for t in range(time + 1)] self.graphicsView.clear() self.graphicsView.plot([t for t in range(time + 1)], speeds, pen="r") self.cur.execute(f"""UPDATE Bodies SET BodyFirSpeed = {speed}, BodyAcceleration = {acceleration}, BodyTime = {time} where BodyId = {self.picked_body[0]}""" ) except ValueError: show_message("Значения должны быть целыми числами!") except NotPickError: show_message("Должно быть выбрано тело!") except AvailableValueError: show_message("Недоступное значение!") except EmptyValueError: show_message("Пустое значение!") except BadTimeError: show_message("Путешествие назад во времени?")
def clean(self): """Очищает данные выбранного тела""" if self.picked_body: self.cur.execute( f"""UPDATE Bodies SET BodyFirSpeed = 0, BodyAcceleration = 0, BodyTime = 0 where BodyId = {self.picked_body[0]}""") self.fir_speed_edit.clear() self.acceleration_edit.clear() self.time_edit.clear() self.graphicsView.clear() else: show_message("Выберите тело!")
def delete(self): """Удаляет движение/тело""" if self.table_status == MOVES: if self.picked_move: self.cur.execute( f"""DELETE from Moves where MoveId = {self.picked_move[0]}""" ) else: show_message("Выберите движение!") else: if self.picked_body: self.cur.execute( f"""DELETE from Bodies where BodyId = {self.picked_body[0]}""" ) else: show_message("Выберите тело!") self.my_update()
def new(self): """Создаёт новое движение/тело""" good_title = None ok_pressed = True moves = [ move[2] for move in self.cur.execute( """SELECT * FROM Moves WHERE UserId = ?""", ( self.user_id, )).fetchall() ] bodies = [ x[2] for x in self.cur.execute("""SELECT * FROM Bodies""").fetchall() ] if self.table_status == MOVES: error_msg = "Движение с таким названием уже есть!" win_title = "Введите название движения" prompt = "Как назвать новое движение?" else: error_msg = "Тело с таким названием уже есть!" win_title = "Введите название тела" prompt = "Как назвать новое тело?" title = "" while not good_title and ok_pressed: if good_title is None: good_title = False else: show_message(error_msg) title, ok_pressed = QInputDialog.getText(self, win_title, prompt) if title not in (moves if self.table_status == MOVES else bodies): good_title = True if ok_pressed and title: if self.table_status == MOVES: self.cur.execute( f"""INSERT INTO Moves(UserId,MoveTitle) VALUES({self.user_id},'{title}') """ ) else: self.cur.execute( f"""INSERT INTO Bodies(MoveId,BodyTitle) VALUES({self.picked_move[0]},'{title}') """ ) self.my_update()
def check_in(self): """Сменяет окно на авторизацию, если пароль и логин подходящие""" self.login = self.login_edit.text() self.password = self.pass_edit.text() try: funcs.check_absence(self.login, self.password) check_free_login(self.login, [ log[0] for log in self.cur.execute( """SELECT UserLogin FROM Users""").fetchall() ]) check_len(self.password) check_letter(self.password) check_digit(self.password) check_sequence(self.password) hashed_password, salt = funcs.hash_pass( self.password, available_salt=[ s[0] for s in self.cur.execute("""SELECT UserSalt FROM Users""") ]) self.cur.execute( """INSERT INTO Users(UserLogin, UserPassword, UserSalt) VALUES(?, ?, ?)""", (self.login, hashed_password, salt)) self.con.commit() self.switch_window.emit("authorization") except excepts.AbsenceError: funcs.show_message("Поля должны быть заполнены!") except excepts.FreeLoginError: funcs.show_message("Логин занят!") except excepts.LengthError: funcs.show_message("Пароль должен быть длиной больше 8!") except excepts.LetterError: funcs.show_message( "Пароль должен содержать символы разных регистров!") except excepts.DigitError: funcs.show_message("Пароль должен содержать цифры!") except excepts.SequenceError: funcs.show_message( "Пароль не должен содержать последовательность из 3 символов, подряд идущих на клавиатуре" )