Ejemplo n.º 1
0
 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()
Ejemplo n.º 2
0
 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()
Ejemplo n.º 3
0
 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()
Ejemplo n.º 4
0
 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()