Check type and author in package details

This commit is contained in:
rubenwardy 2018-03-20 00:58:44 +00:00
parent bc88027fbe
commit 07a9b79396
2 changed files with 17 additions and 1 deletions

@ -71,6 +71,17 @@ class PackageType(enum.Enum):
else:
return "TXP"
@staticmethod
def fromName(name):
if name == "mod":
return PackageType.MOD
elif name == "game":
return PackageType.GAME
elif name == "texturepacks":
return PackageType.TXP
else:
return None
class Package(db.Model):
id = db.Column(db.Integer, primary_key=True)

@ -24,7 +24,12 @@ def txp_page():
@app.route("/<type>s/<author>/<name>/")
def package_page(type, author, name):
package = Package.query.filter_by(name=name).first()
user = User.query.filter_by(username=author).first()
if user is None:
abort(404)
package = Package.query.filter_by(name=name, author_id=user.id,
type=PackageType.fromName(type)).first()
if package is None:
abort(404)