def get_user(self, login, password): """ Get user by login and password :param login: user login :param password: user password :return: User object """ session = self._get_db_session() enc_password = validator.password_to_hash(password) try: user = session.query(User).filter(and_(User.login.like(login), User.password.like(enc_password))).one() return user except sqlalchemy.orm.exc.NoResultFound: raise error.IncorrectNameError finally: session.close()
def register_user(self, login, password): """ Register user :param login: login :param password: passsword :return: user identifier """ user = User(login, validator.password_to_hash(password)) session = self._get_db_session() session.add(user) try: session.commit() return user.id except (sqlalchemy.exc.IntegrityError, sqlalchemy.exc.OperationalError) as err: raise error.Exists(errorMsg="User {} is already exists.".format(login)) finally: session.close()
def get_user(self, login, password): """ Get user by login and password :param login: user login :param password: user password :return: User object """ session = self._get_db_session() enc_password = validator.password_to_hash(password) try: user = session.query(User).filter( and_(User.login.like(login), User.password.like(enc_password))).one() return user except sqlalchemy.orm.exc.NoResultFound: raise error.IncorrectNameError finally: session.close()
def register_user(self, login, password): """ Register user :param login: login :param password: passsword :return: user identifier """ user = User(login, validator.password_to_hash(password)) session = self._get_db_session() session.add(user) try: session.commit() return user.id except (sqlalchemy.exc.IntegrityError, sqlalchemy.exc.OperationalError) as err: raise error.Exists( errorMsg="User {} is already exists.".format(login)) finally: session.close()