use starts with when checking token prefix

allows prefix length to change
This commit is contained in:
Min RK
2014-10-30 10:21:32 -07:00
parent ae7b92c55e
commit e91b7f630c

View File

@@ -21,6 +21,7 @@ from sqlalchemy import (
from sqlalchemy.ext.declarative import declarative_base, declared_attr from sqlalchemy.ext.declarative import declarative_base, declared_attr
from sqlalchemy.orm import sessionmaker, relationship from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy.pool import StaticPool from sqlalchemy.pool import StaticPool
from sqlalchemy.sql.expression import bindparam
from sqlalchemy import create_engine from sqlalchemy import create_engine
from .utils import ( from .utils import (
@@ -383,7 +384,7 @@ class APIToken(Base):
prefix = token[:cls.prefix_length] prefix = token[:cls.prefix_length]
# since we can't filter on hashed values, filter on prefix # since we can't filter on hashed values, filter on prefix
# so we aren't comparing with all tokens # so we aren't comparing with all tokens
prefix_match = db.query(cls).filter(cls.prefix==prefix) prefix_match = db.query(cls).filter(bindparam('prefix', prefix).startswith(cls.prefix))
for orm_token in prefix_match: for orm_token in prefix_match:
if orm_token.match(token): if orm_token.match(token):
return orm_token return orm_token