示例#1
0
 def to_api(self, admin):
     o = super(Player, self).to_api(admin)
     db = DB_Session()
     nation = (
         db.query(Nation)
         .join(Nationality, Nation.id == Nationality.country_id)
         .join(Player, Player.id == Nationality.player_id)
         .filter(Player.id == self.id)
         .all()
     )
     try:
         o["nationality"] = _to_api(nation)
     except Exception, e:
         o["nation"] = None
示例#2
0
 def validates(self, source=None, _validate=True, **kw):
     source = source or kw or web.input()
     out = super(LoginForm, self).validates(source=source, _validate=_validate, **kw)
     db = DB_Session()
     query = db.query(User)
     try:
         user = query.filter(User.email == source.email).one()
         if user and user.validate_password(source.password):
             session = web.config.session
             session.login = 1
             session.privilege = user.privilege
             out = True
         else:
             out = False
     except Exception, e:
         out = False
示例#3
0
    def activate_user(cls, activation_key):
        """
        Validate an activation key and activate the corresponding
        ``User`` if valid.
        
        If the key is valid and has not expired, return the ``User``
        after activating.
        
        If the key is not valid or has expired, return ``False``.
        
        If the key is valid but the ``User`` is already active,
        return ``False``.
        
        To prevent reactivation of an account which has been
        deactivated by site administrators, the activation key is
        reset to the string constant ``RegistrationProfile.ACTIVATED``
        after successful activation.

        To execute customized logic when a ``User`` is activated,
        connect a function to the signal
        ``registration.signals.user_activated``; this signal will be
        sent (with the ``User`` as the value of the keyword argument
        ``user``) after a successful activation.
        
        """
        # from registration.signals import user_activated

        # Make sure the key we're trying conforms to the pattern of a
        # SHA1 hash; if it doesn't, no point trying to look it up in
        # the database.
        db = DB_Session()
        if SHA1_RE.search(activation_key):
            query = db.query(RegistrationProfile)
            profile = query.filter(RegistrationProfile.activation_key == activation_key).one()
            if not profile:
                return False
            if not profile.activation_key_expired():
                user = profile.user
                user.is_active = 1
                profile.activation_key = RegistrationProfile.ACTIVATED
                db.flush()
                db.commit()
                db.close()
                # user_activated.send(sender=self.model, user=user)
                return user
        return False
示例#4
0
 def to_api(self):
     o = super(MatchPlayerStatistics, self).to_api()
     db = DB_Session()
     o["player"] = db.query(Player).get(self.playerId).to_api(None)
     db.close()
     return o