def post(self, *args, **kwargs): ''' Called to purchase an item ''' uuid = self.get_argument('uuid', '') item = MarketItem.by_uuid(uuid) if not item is None: user = self.get_current_user() team = Team.by_id(user.team.id) # Refresh object if user.has_item(item.name): self.render('market/view.html', user=user, errors=["You have already purchased this item."]) elif team.money < item.price: message = "You only have $%d" % (team.money, ) self.render('market/view.html', user=user, errors=[message]) else: logging.info("%s (%s) purchased the market item '%s' for $%d" % (user.handle, team.name, item.name, item.price)) self.purchase_item(team, item) event = self.event_manager.create_purchased_item_event( user, item) self.new_events.append(event) self.redirect('/user/market') else: self.render('market/view.html', user=self.get_current_user(), errors=["Item does not exist."])
def post(self, *args, **kwargs): """ Called to purchase an item """ uuid = self.get_argument("uuid", "") item = MarketItem.by_uuid(uuid) if item is not None: user = self.get_current_user() team = Team.by_id(user.team.id) # Refresh object if user.has_item(item.name): self.render( "market/view.html", user=user, errors=["You have already purchased this item."], ) elif team.money < item.price: if options.banking: money = "$%d" % team.money else: money = "%d points" % team.money message = "You only have %s" % (money) self.render("market/view.html", user=user, errors=[message]) else: logging.info("%s (%s) purchased '%s' for $%d" % (user.handle, team.name, item.name, item.price)) self.purchase_item(team, item) self.event_manager.item_purchased(user, item) self.redirect("/user/market") else: self.render( "market/view.html", user=self.get_current_user(), errors=["Item does not exist."], )
def post(self, *args, **kwargs): ''' Called to purchase an item ''' uuid = self.get_argument('uuid', '') item = MarketItem.by_uuid(uuid) if not item is None: user = self.get_current_user() team = Team.by_id(user.team.id) # Refresh object if user.has_item(item.name): self.render('market/view.html', user=user, errors=["You have already purchased this item."] ) elif team.money < item.price: message = "You only have $%d" % (team.money,) self.render('market/view.html', user=user, errors=[message]) else: logging.info("%s (%s) purchased '%s' for $%d" % ( user.handle, team.name, item.name, item.price )) self.purchase_item(team, item) self.event_manager.item_purchased(user, item) self.redirect('/user/market') else: self.render('market/view.html', user=self.get_current_user(), errors=["Item does not exist."] )
def get(self, *args, **kwargs): ''' Get details on an item ''' uuid = self.get_argument('uuid', '') item = MarketItem.by_uuid(uuid) if item is None: self.write({'Error': 'Item does not exist.'}) else: self.write(item.to_dict()) self.finish()
def get(self, *args, **kwargs): """ Get details on an item """ uuid = self.get_argument("uuid", "") item = MarketItem.by_uuid(uuid) if item is None: self.write({"Error": "Item does not exist."}) else: self.write(item.to_dict()) self.finish()
def edit_market_item(self): """ Change a market item's price """ try: item = MarketItem.by_uuid(self.get_argument("item_uuid", "")) if item is None: raise ValidationError("Item does not exist") price = self.get_argument("price", item.price) if item.price != price: item.price = price self.dbsession.add(item) self.dbsession.commit() self.redirect("/admin/view/market_objects") except ValidationError as error: self.render("admin/view/market_objects.html", errors=[str(error)])
def edit_market_item(self): ''' Change a market item's price ''' try: item = MarketItem.by_uuid(self.get_argument('item_uuid', '')) if item is None: raise ValidationError("Item does not exist") price = self.get_argument('price', item.price) if item.price != price: item.price = price self.dbsession.add(item) self.dbsession.commit() self.redirect('/admin/view/market_objects') except ValidationError as error: self.render('admin/view/market_objects.html', errors=[str(error)])
def edit_market_item(self): ''' Change a market item's price ''' item = MarketItem.by_uuid(self.get_argument('item_uuid', '')) if item is not None: try: price = self.get_argument('price', item.price) if item.price != price: item.price = price self.dbsession.add(item) self.dbsession.commit() self.redirect('/admin/view/market_objects') except ValueError: self.render('admin/view/market_objects.html', errors=["Invalid price."] ) else: self.render('admin/view/market_objects.html', errors=["Item does not exist."] )
def has_item(self, item_name): ''' Check to see if a team has purchased an item ''' item = MarketItem.by_name(item_name) if item is None: raise ValueError("Item '%s' not in database." % str(item_name)) return True if item in self.team.items else False
(u"386", [u'386.css', u'386.js', u'386.responsive.css']), ] for css in css_files: theme = Theme(name=css[0]) dbsession.flush() for f in css[1]: theme_file = ThemeFile(theme_id=theme.id, file_name=f) theme.files.append(theme_file) dbsession.add(theme_file) dbsession.add(theme) # Market Items item = MarketItem( name=u"Source Code Market", price=500, image=u"source_code_market.png", description= u"Allows your team access to the Source Code Black Market where you can purchase leaked source code for certain target boxes.", ) dbsession.add(item) dbsession.flush() item = MarketItem( name=u"Password Security", price=1000, image=u"password_security.png", description= u"Allows your team to upgrade their password hashes to more secure algorithms such as SHA1, and SHA256.", ) dbsession.add(item) dbsession.flush()