示例#1
0
def cache_actions():
    ''' Loads all of the actions from the database into memory for the scoreboard pages'''
    action_list = dbsession.query(models.Action).all()
    ws_manager = WebSocketManager.Instance()
    for action in action_list:
        team = dbsession.query(models.User).filter_by(id=action.user_id).first()
        score_update = ScoreUpdate(action.created.strftime("%d%H%M%S"), action.value, team.team_name)
        ws_manager.currentUpdates.append(score_update)
示例#2
0
 def by_ip_address(cls, ip_addr):
     '''
     Returns a box object based on an ip address, supports both ipv4
     and ipv6
     '''
     db_ip = dbsession.query(IpAddress).filter(
         or_(IpAddress.v4 == ip_addr, IpAddress.v6 == ip_addr)
     ).first()
     if db_ip is not None:
         return dbsession.query(cls).filter_by(id=db_ip.box_id).first()
     else:
         return None
示例#3
0
文件: User.py 项目: xaelek/RootTheBox
 def team_name(self):
     """ Return a list with all groups names the user is a member of """
     if self.team_id == None:
         return None
     else:
         team = dbsession.query(Team).filter_by(id=self.team_id).first() #@UndefinedVariable
         return team.team_name
示例#4
0
 def list(cls):
     ''' Returns a list of all categories in the database '''
     categories = dbsession.query(cls).all()
     catlist = []
     for cat in categories:
         catlist.append(cat.category)
     return json.dumps(catlist)
示例#5
0
 def delivered(cls, user_id, uuid):
     notify = dbsession.query(cls).filter(
         and_(cls.event_uuid == uuid, cls.user_id == user_id)
     ).first()
     notify.viewed = True
     dbsession.add(notify)
     dbsession.flush()
示例#6
0
 def by_datetime(cls, input_datetime):
     ''' Returns all events for the day depicted by input_datetime '''
     day = input_datetime.date()
     next_day = day + datetime.timedelta(days=1)
     return dbsession.query(cls).filter(
         and_(cls.start_time >= day, cls.start_time < next_day)
     ).all()
示例#7
0
 def by_ip_address(cls, ip_addr):
     '''
     Returns a box object based on an ip address, supports both ipv4
     and ipv6
     '''
     ip = dbsession.query(IpAddress).by_address(ip_addr).first()
     return ip.box if ip is not None else None
示例#8
0
 def delivered(cls, user_id, uuid):
     notify = dbsession.query(cls).filter(
         and_(cls.event_uuid == uuid, cls.user_id == user_id)
     ).first()
     if notify is not None:
         notify.viewed = True
         dbsession.add(notify)
         dbsession.commit()
示例#9
0
文件: User.py 项目: xaelek/RootTheBox
 def score(self):
     ''' Returns user's current score from cache, or re-calculates if expired '''
     if self.dirty:
         actions = dbsession.query(Action).filter_by(user_id=self.id).all() #@UndefinedVariable
         self.score_cache = sum(actions)
         self.dirty = False
         dbsession.add(self)
         dbsession.flush()
     return self.score_cache
示例#10
0
文件: Monster.py 项目: hathcox/Arthur
 def get_monster(cls, user):
     ''' Based on the users quest and level this will choose an appropriate monster '''
     quest = Quest.by_id(user.quest_level)
     #If we are still on quests
     if quest != None:
         #Get all valid monsters
         all = dbsession.query(cls).filter(cls.level<=quest.max_monster_level).filter(cls.level>=quest.min_monster_level).all()
         return choice(all)
     return choice(cls.get_all())
示例#11
0
def get_current_user(self):
    """
    Return the request's user object.
    can be called using BaseHandler self.get_current_user() or
    by get_current_user(request_handler_instance)    
    """
    # loads the cookie and query the database to compare passwords.
    # if password was changed/deleted (in the server side) then treats as unauthed
    auth = loads(self.get_secure_cookie('auth') or '""')
    if auth:
        user = dbsession.query(User).get(auth['id'])
        if user and user.password[0:8] == auth['password']: return user
示例#12
0
 def by_uuid(cls, _uuid):
     ''' Return and object based on a _uuid '''
     return dbsession.query(cls).filter_by(uuid=_uuid).first()
 def by_ip_address(cls, weapon_ip_address):
     ''' Return the WeaponSystem object whose ip_address is 'weapon_ip_address' '''
     return dbsession.query(cls).filter_by(
         ip_address=unicode(weapon_ip_address)).first()
示例#14
0
 def by_event_uuid(cls, uuid):
     ''' Always returns anonymous notification '''
     return dbsession.query(cls).filter_by(event_uuid=uuid).filter_by(
         user_id=None).first()
示例#15
0
 def name(self):
     return dbsession.query(
         Team._name).filter_by(id=self.team_id).first()[0]
 def by_hexdigest(cls, hexvalue, jid):
     ''' Return the digest based on valud and job_id '''
     return dbsession.query(cls).filter(
         and_(cls.hexdigest == hexvalue, cls.job_id == jid)
     ).first()
示例#17
0
 def by_team_id(cls, team_id):
     ''' Return all paste objects for a given team '''
     return dbsession.query(cls).filter_by(team_id=team_id).order_by(desc(cls.created)).all()
示例#18
0
 def by_uuid(cls, _uuid):
     """ Return and object based on a uuid """
     return dbsession.query(cls).filter_by(uuid=str(_uuid)).first()
示例#19
0
 def by_name(cls, name):
     """ Return the box object whose name is "name" """
     return dbsession.query(cls).filter_by(_name=str(name)).first()
示例#20
0
 def ranks(cls):
     ''' Returns a list of all objects in the database '''
     return sorted(dbsession.query(cls).all())
示例#21
0
 def by_uuid(cls, uuid):
     ''' Return and object based on a uuid '''
     return dbsession.query(cls).filter_by(uuid=unicode(uuid)).first()
示例#22
0
 def by_name(cls, team_name):
     ''' Return the team object based on "team_name" '''
     return dbsession.query(cls).filter_by(name=unicode(team_name)).first()
示例#23
0
 def last_level(cls, number):
     ''' Returns the prior level '''
     return dbsession.query(cls).filter_by(
         next_level_id=int(number)).first()
示例#24
0
 def by_number(cls, number):
     ''' Returns a the object with number of number '''
     return dbsession.query(cls).filter_by(_number=abs(int(number))).first()
示例#25
0
 def by_id(cls, _id):
     ''' Returns a the object with id of _id '''
     return dbsession.query(cls).filter_by(id=_id).first()
示例#26
0
 def by_category(cls, _cat_id):
     """ Return the box object whose category is "_cat_id" """
     return dbsession.query(cls).filter_by(category_id=int(_cat_id)).all()
示例#27
0
 def by_name(cls, name):
     ''' Return the team object based on "team_name" '''
     return dbsession.query(cls).filter_by(_name=unicode(name)).first()
示例#28
0
 def all(cls):
     ''' Returns a list of all objects in the database '''
     return dbsession.query(cls).order_by(asc(cls._number)).all()
示例#29
0
 def all(cls):
     ''' Returns a list of all objects in the database '''
     return dbsession.query(cls).all()
示例#30
0
 def get_all(cls):
     """ Return all non-admin user objects """
     return dbsession.query(cls).filter(cls.user_name != 'admin').all() 
示例#31
0
 def new_messages(cls, user_id):
     ''' Return all notification which have not been viewed '''
     return dbsession.query(cls).filter(
         and_(cls.user_id == user_id, cls.viewed == False)).all()
示例#32
0
 def by_id(cls, user_id):
     """ Return the user object whose user id is user_id """
     return dbsession.query(cls).filter_by(id=user_id).first()
示例#33
0
 def delivered(cls, user_id, uuid):
     notify = dbsession.query(cls).filter(
         and_(cls.event_uuid == uuid, cls.user_id == user_id)).first()
     notify.viewed = True
     dbsession.add(notify)
     dbsession.commit()
示例#34
0
 def get_unapproved(cls):
     """ Return all unapproved user objects """
     return dbsession.query(cls).filter_by(approved=False).all()
示例#35
0
 def by_uuid(cls, paste_uuid):
     ''' Get a paste object by uuid '''
     return dbsession.query(cls).filter_by(uuid=paste_uuid).first()
示例#36
0
 def all(cls):
     """ Return all non-admin user objects """
     return dbsession.query(cls).all()
 def by_name(cls, weapon_name):
     ''' Return the WeaponSystem object whose name is 'weapon_name' '''
     return dbsession.query(cls).filter_by(
         name=unicode(weapon_name)).first()
示例#38
0
 def ranks(cls):
     ''' Returns a list of all objects in the database '''
     return sorted(dbsession.query(cls).all())
示例#39
0
 def by_garbage(cls, _garbage):
     return dbsession.query(cls).filter_by(garbage=_garbage).first()
示例#40
0
 def count(cls):
     return dbsession.query(cls).count()
示例#41
0
 def name(self):
     return dbsession.query(Team._name).filter_by(
         id=self.team_id
     ).first()[0]
示例#42
0
 def all(cls):
     """ Returns a list of all objects in the database """
     return dbsession.query(cls).all()
示例#43
0
 def permissions(self):
     """ Return a list with all permissions granted to the user """
     return dbsession.query(Permission).filter_by(user_id=self.id)
示例#44
0
 def by_uuid(cls, _uuid):
     """ Get a paste object by uuid """
     return dbsession.query(cls).filter_by(uuid=_uuid).first()
示例#45
0
 def by_uuid(cls, user_uuid):
     """ Return the user object whose user uuid is user_uuid """
     return dbsession.query(cls).filter_by(uuid=unicode(user_uuid)).first()
示例#46
0
 def team(self):
     ''' Pull box object from persistant db '''
     return dbsession.query(Box).by_uuid(self.box_uuid)
示例#47
0
 def get_approved(cls):
     """ Return all approved user objects """
     return dbsession.query(cls).filter_by(approved=True).all()
示例#48
0
 def by_uuid(cls, uuid):
     ''' Returns a the object with a given uuid '''
     return dbsession.query(cls).filter_by(uuid=unicode(uuid)).first()
示例#49
0
 def by_username(cls, user_name):
     """ Return the user object whose user name is 'user_name' """
     return dbsession.query(cls).filter_by(username=unicode(user_name)).first()
示例#50
0
 def by_box_id(cls, bid):
     return dbsession.query(cls).filter_by(box_id=bid).first()
示例#51
0
 def count(cls):
     return dbsession.query(cls).count()
示例#52
0
 def all(cls):
     ''' Returns a list of all objects in the database '''
     return dbsession.query(cls).all()
示例#53
0
 def by_uuid(cls, _uuid):
     ''' Return and object based on a uuid '''
     return dbsession.query(cls).filter_by(uuid=_uuid).first()
示例#54
0
 def by_id(cls, ident):
     ''' Returns a the object with id of ident '''
     return dbsession.query(cls).filter_by(id=ident).first()
 def by_id(cls, hash_id):
     ''' Return the PasswordHash object whose user id is 'hash_id' '''
     return dbsession.query(cls).filter_by(id=hash_id).first()
示例#56
0
 def all(cls):
     ''' Returns a list of all objects in the database '''
     return dbsession.query(cls).filter_by(user_id=None).all()
 def by_algorithm(cls, algo):
     ''' Return all passwords objects of a given algorithm id '''
     if isinstance(algo, int):
         return dbsession.query(cls).filter_by(algorithm_id=algo).all()
     else:
         return dbsession.query(cls).filter_by(algorithm_id=algo.id).all()
示例#58
0
 def by_id(cls, _id):
     ''' Returns a the object with id of _id '''
     return dbsession.query(cls).filter_by(id=_id).first()
示例#59
0
 def by_id(cls, identifier):
     ''' Returns a the object with id of identifier '''
     return dbsession.query(cls).filter_by(id=identifier).first()
示例#60
0
 def by_user_id(cls, _id):
     ''' Return notifications for a single user '''
     return dbsession.query(cls).filter_by(user_id=_id).order_by(
         desc(cls.created)).all()