Ejemplo n.º 1
0
    def dumplog_admin(self, filename):
        # TODO: implement security for admin dumplog

        self.session = get_session()
        transactions = self.session.query(Transaction).all()

        # Note: this is not secure against directory traversal
        full_path = path.join(config.DUMPLOG_DIR, filename)
        with open(full_path, 'w') as f:
            res = xml.DumplogResponse(transactions)
            f.write(str(res))


        xml.log_event('DUMPLOG', username='******', status_message='to file %s' % filename)
        return xml.ResultResponse('Wrote transactions to "%s"' % full_path)
Ejemplo n.º 2
0
    def run(self, username, amount):
        self.session = get_session()
        user = self.session.query(User).filter_by(username=username).first()
        if not user:
            log.info('User does not exist, creating one first...')
            user = User(username=username, password='',
                account_balance=Money(0, 0), reserve_balance=Money(0, 0))
            self.session.add(user)

        amount = Money.from_string(amount)
        user.account_balance += amount
        self.session.commit()

        #log event
        xml.log_event('ADD', username, amount=str(amount)) 

        return xml.ResultResponse('success')
Ejemplo n.º 3
0
    def dumplog_user(self, username, filename):
        self.session = get_session()
        user = self.session.query(User).filter_by(username=username).first()
        if not user:
            raise UserNotFoundError(username)

        # Get this users transactions
        transactions = self.session.query(Transaction).filter_by(user=user).all()

        # Note: this is not secure against directory traversal
        full_path = path.join(config.DUMPLOG_DIR, filename)
        with open(full_path, 'w') as f:
            res = xml.DumplogResponse(transactions)
            f.write(str(res))


        xml.log_event('DUMPLOG', username, status_message='to file %s' % filename)
        return xml.ResultResponse('Wrote transactions to "%s"' % full_path)
Ejemplo n.º 4
0
    def run(self, username='', stock_symbol=''):

        if not stock_symbol:
            xml.log_error('QUOTE', 'No stock symbol given')
            raise InvalidInputError('No stock symbol given')

        if len(stock_symbol) > 4:
            xml.log_error('QUOTE', 'stock symbol too long')
            raise InvalidInputError('stock symbol too long: %d' % \
                    len(stock_symbol))

        quote_client = get_quote_client()
        quote = quote_client.get_quote(stock_symbol, username)

        #create log
        xml.log_event('QUOTE', username, stock_symbol)

        return xml.QuoteResponse(quantity=1, price=quote)
Ejemplo n.º 5
0
    def run(self, username):
        self.session = get_session()
        user = self.session.query(User).filter_by(username=username).first()
        if not user:
            raise UserNotFoundError(username)

        # Get this users transactions
        transactions = self.session.query(Transaction).filter_by(user=user).all()

        # Get this users triggers
        triggers = self.session.query(Trigger).filter_by(user=user).all()

        # Get this users stocks
        stocks = self.session.query(StockPurchase).filter_by(user=user).all()

        xml.log_event('DISPLAY_SUMMARY', username)
        return xml.SummaryResponse(
            transactions=transactions, triggers=triggers, stocks=stocks,
            account_balance=user.account_balance,
            reserve_balance=user.reserve_balance)
Ejemplo n.º 6
0
 def run(self, username, filename):
     xml.log_event('DUMPLOG_USER', username, status_message='to file %s' % filename)
     return xml.ResultResponse('success')