Пример #1
0
    def get_account_by_oauth_token(self, token):
        now = int(time.time())

        # First, remove old tokens every 4 requests or so
        if random.randint(1, 4) == 1:
            q = OauthAccessToken.delete().where(
                OauthAccessToken.expires_at < now
            )
            deleted = q.execute()
            # print "Old tokens deleted: " + str(deleted)

        try:
            access_token = OauthAccessToken.get(
                OauthAccessToken.access_token == token,
                OauthAccessToken.expires_at > now
            )
        except peewee.DoesNotExist:
            raise Unauthorized('invalid_token')

        try:
            return Account.get(
                Account.account_id == access_token.account_id,
                Account.status == 'active'
            )
        except peewee.DoesNotExist:
            raise Unauthorized('Account not found')
Пример #2
0
    def get_account_by_oauth_token(self, token):
        now = int(time.time())
        try:
            access_token = OauthAccessToken.get(
                OauthAccessToken.access_token == token,
                OauthAccessToken.expires_at > now)
        except peewee.DoesNotExist:
            raise AuthException('invalid_token')

        try:
            return Account.get(Account.account_id == access_token.account_id,
                               Account.status == 'active')
        except peewee.DoesNotExist:
            raise AuthException('Account not found')
Пример #3
0
    def get_account_by_oauth_token(self, token):
        now = int(time.time())
        try:
            access_token = OauthAccessToken.get(
                OauthAccessToken.access_token == token,
                OauthAccessToken.expires_at > now
            )
        except peewee.DoesNotExist:
            raise AuthException('invalid_token')

        try:
            return Account.get(
                Account.account_id == access_token.account_id,
                Account.status == 'active'
            )
        except peewee.DoesNotExist:
            raise AuthException('Account not found')