예제 #1
0
    def get(self, auction_id):
        auction = Auction.objects(auction_id=auction_id).first()
        server = auction.get_crypto_server()
        next_bidder_key = None
        if auction.current_state is None:
            auction.current_bid = 1
            first_bidder_key = \
                    auction.bidder_public_keys[0]
            blob = server.initialize(pickle.loads(first_bidder_key))
            auction.current_state = pickle.dumps(
                server.initialize(pickle.loads(first_bidder_key)))

        if auction.current_bid < len(auction.bidder_public_keys):
            next_bidder_key = auction.bidder_public_keys[auction.current_bid]

        payload = {
            'blob': auction.current_state,
            'bid_values': auction.bid_range,
            'seller_address': auction.account
        }

        auction.save()
        if next_bidder_key is not None:
            payload['next_bidder_key'] = next_bidder_key
        return json.dumps(payload)
예제 #2
0
 def post(self, auction_id):
     key = request.form['public_key']
     auction = Auction.objects(auction_id=auction_id).first()
     auction.bidder_public_keys.append(key)
     auction.save()
     bidder_id = len(auction.bidder_public_keys)
     server = auction.get_crypto_server()
     server_key = pickle.dumps(server.export_key())
     payload = {'server_key': server_key, 'bidder_id': bidder_id}
     return json.dumps(payload)
예제 #3
0
 def post(self, auction_id):
     auction = Auction.objects(auction_id=auction_id).first()
     blob = request.form['blob']
     auction.current_state = blob
     auction.current_bid += 1
     auction.save()
     if auction.current_bid > len(auction.bidder_public_keys):
         server = auction.get_crypto_server()
         blob = server.finalize(pickle.loads(blob))
         auction.current_state = pickle.dumps(blob)
         return str(blob)
     return ''
예제 #4
0
 def post(self, auction_id):
     auction = Auction.objects(auction_id=auction_id).first()
     blob = request.form['blob']
     auction.current_state = blob
     auction.current_bid += 1
     auction.save()
     if auction.current_bid > len(auction.bidder_public_keys):
         server = auction.get_crypto_server()
         blob = server.finalize(pickle.loads(blob))
         auction.current_state = pickle.dumps(blob)
         return str(blob)
     return ''
예제 #5
0
 def post(self, auction_id):
     key = request.form['public_key']
     auction = Auction.objects(auction_id=auction_id).first()
     auction.bidder_public_keys.append(key)
     auction.save()
     bidder_id = len(auction.bidder_public_keys)
     server = auction.get_crypto_server()
     server_key = pickle.dumps(server.export_key())
     payload = {
             'server_key': server_key,
             'bidder_id': bidder_id
         }
     return json.dumps(payload)
예제 #6
0
 def post(self):
     bid_range = list(range(int(request.form['startingBid']), int(request.form['maxBid']) + 1))
     file = request.files['image']
     filename = None
     if file:
         filename = secure_filename(file.filename)
         full_path = os.path.join(get_upload_folder(), filename)
         file.save(full_path)
     while True:
         auction_id = random.randint(1,10**5)
         if not Auction.objects(auction_id=auction_id):
             break
     auction = Auction(name=request.form['name'],
             account=request.form['account'],
             description=request.form['description'], auction_id=auction_id,
             bid_range=bid_range, picture_filename=filename)
     auction.save()
     return render_template('create.html', message = 'Auction #{} successfully created'.format(auction_id))
예제 #7
0
    def get(self, auction_id):
        auction = Auction.objects(auction_id=auction_id).first()
        server = auction.get_crypto_server()
        next_bidder_key = None
        if auction.current_state is None:
            auction.current_bid = 1
            first_bidder_key = \
                    auction.bidder_public_keys[0]
            blob = server.initialize(pickle.loads(first_bidder_key))
            auction.current_state = pickle.dumps(server.initialize(pickle.loads(first_bidder_key)))

        if auction.current_bid < len(auction.bidder_public_keys):
            next_bidder_key = auction.bidder_public_keys[auction.current_bid]

        payload = {
                'blob': auction.current_state,
                'bid_values': auction.bid_range,
                'seller_address': auction.account
            }

        auction.save()
        if next_bidder_key is not None:
            payload['next_bidder_key'] = next_bidder_key
        return json.dumps(payload)
예제 #8
0
 def post(self):
     bid_range = list(
         range(int(request.form['startingBid']),
               int(request.form['maxBid']) + 1))
     file = request.files['image']
     filename = None
     if file:
         filename = secure_filename(file.filename)
         full_path = os.path.join(get_upload_folder(), filename)
         file.save(full_path)
     while True:
         auction_id = random.randint(1, 10**5)
         if not Auction.objects(auction_id=auction_id):
             break
     auction = Auction(name=request.form['name'],
                       account=request.form['account'],
                       description=request.form['description'],
                       auction_id=auction_id,
                       bid_range=bid_range,
                       picture_filename=filename)
     auction.save()
     return render_template(
         'create.html',
         message='Auction #{} successfully created'.format(auction_id))