Example #1
0
def create_transaction():
    sqlHandler = SqlHandler(mysql)
    jsonData = request.get_json()
    jwt_service = JWTService()

    buyer_id = jwt_service.get_account(jsonData['token'])
    event_id = jsonData['eventID']
    tickets = jsonData['tickets']
    commission = jsonData['commission']
    tax = jsonData['tax']
    subtotal = jsonData['subtotal']
    total = jsonData['total']
    group_id = jsonData['group_id']
    tax_per_ticket = jsonData['taxPerTicket']
    comm_per_ticket = jsonData['commPerTicket']
    subtotal_per_ticket = jsonData['subtotalPerTicket']

    success = sqlHandler.create_transaction(buyer_id, tickets, commission, tax,
                                            subtotal, total, group_id,
                                            tax_per_ticket, comm_per_ticket,
                                            subtotal_per_ticket)
    if success:
        event_info = sqlHandler.get_event_info(event_id)
        phone_num, email = sqlHandler.get_seller_email_and_phone(group_id)
        thr = threading.Thread(target=TTTEmailClient.send_sale_confirmation,
                               args=(email, event_info, tickets, commission,
                                     tax, subtotal, total))
        thr.start()

    return jsonify({'success': success})
    def createListing(self):
        sqlHandler = SqlHandler(self.mysql)
        jwt_service = JWTService()
        jsonData = self.json

        sectionNum = jsonData['section']
        rowNum = jsonData['row']
        seatsInfo = jsonData['seatsInfo']
        ticketPrice = jsonData['ticketPrice']
        numberOfTickets = jsonData['numberOfTickets']
        minPurchaseSize = jsonData['minPurchaseSize']
        gameDate = jsonData['dbGameDate']
        accountID = jwt_service.get_account(jsonData['token'])

        ticketIds = sqlHandler.insert_ticket_listing(sectionNum, rowNum,
                                                     seatsInfo, ticketPrice,
                                                     numberOfTickets,
                                                     minPurchaseSize, gameDate,
                                                     accountID)

        print(ticketIds)

        mysqlInsertSuccess = False

        if (ticketIds):
            mysqlInsertSuccess = True

        fileUploadSuccess = self.pdfworker.splitPDF(self.file, ticketIds)
        #fileUploadSuccess = True

        return mysqlInsertSuccess and fileUploadSuccess
Example #3
0
 def decorated_function(*args, **kwargs):
     jwt_service = JWTService()
     jsonData = request.get_json()
     id_token = jsonData['token']
     if id_token and jwt_service.validate_auth_token(id_token):
         return f(*args, **kwargs)
     else:
         return requestNotSupported()
Example #4
0
def get_account_info():
    if 'application/json' in request.headers.environ['CONTENT_TYPE']:
        jsonData = request.get_json()
        try:
            jwt_service = JWTService()
            account_id = jwt_service.get_account(jsonData['token'])
            sqlHandler = SqlHandler(mysql)
            return jsonify(sqlHandler.get_account_info(account_id))
        except Exception as e:
            return jsonify({'authenticated': False})
Example #5
0
def hold_tickets():
    jsonData = request.get_json()
    try:
        jwt_service = JWTService()
        account_id = jwt_service.get_account(jsonData['token'])
        sqlHandler = SqlHandler(mysql)
        result = sqlHandler.hold_tickets(account_id, jsonData['ticketIds'])
        return jsonify({'authenticated': result, 'timer': 30000})  # 5 minutes
    except Exception as e:
        print(e)
        return jsonify({'authenticated': False})
Example #6
0
def get_buyer_purchases():
    jsonData = request.get_json()
    try:
        jwt_service = JWTService()
        account_id = jwt_service.get_account(jsonData['token'])
        sqlHandler = SqlHandler(mysql)
        transactions = sqlHandler.get_buyer_transactions(account_id)
        return jsonify({'purchases': transactions, 'authenticated': True})
    except Exception as e:
        print(e)
        return jsonify({'authenticated': False})
Example #7
0
def refresh_token():
    if 'application/json' in request.headers.environ['CONTENT_TYPE']:
        jsonData = request.get_json()
        jwt_service = JWTService()
        token = jwt_service.refresh_token(jsonData['token'])
        if token:
            return jsonify({'token': token, 'authenticated': True})
        else:
            return jsonify({'authenticated': False})
    else:
        return requestNotSupported()
Example #8
0
def get_seller_listings():
    jsonData = request.get_json()
    try:
        jwt_service = JWTService()
        account_id = jwt_service.get_account(jsonData['token'])
        sqlHandler = SqlHandler(mysql)
        transactions = sqlHandler.get_seller_transactions(account_id)
        listings = sqlHandler.get_seller_tickets(account_id)
        # Concatenate the two arrays into one listings array to be consumed by frontend page
        return jsonify({
            'listings': listings + transactions,
            'authenticated': True
        })
    except Exception as e:
        print(e)
        return jsonify({'authenticated': False})
Example #9
0
def unlock_tickets():
    jsonData = request.get_json()
    try:
        jwt_service = JWTService()
        #account_id = jwt_service.get_account(jsonData['token'])
        sqlHandler = SqlHandler(mysql)
        result = sqlHandler.unlock_tickets(jsonData['ticketIds'])
        return jsonify({'authenticated': result})  #
    except Exception as e:
        print(e)
        return jsonify({'authenticated': False})
Example #10
0
def sendTicketsPDF():
    if 'application/json' in request.headers.environ['CONTENT_TYPE']:
        jsonData = request.get_json()
        jwt_service = JWTService()
        sqlHandler = SqlHandler(mysql)
        try:
            accountID = jwt_service.get_account(jsonData['token'])
            email = sqlHandler.get_user_email(accountID)

            ticketIds = jsonData['ticketIds']
            outputPDF = pdfworker.getCombinedPDF(ticketIds)
            outputPDFName = "Tickets.pdf"

            thr = threading.Thread(
                target=TTTEmailClient.send_combined_ticket_file,
                args=(email, outputPDF, outputPDFName))
            thr.start()
        except Exception as e:
            print(e)
            return jsonify({'success': False})
    else:
        return requestNotSupported()
    return jsonify({'success': True})
Example #11
0
from account import Account
from sql_handler import SqlHandler
from account_jwt import JWTService

jwt_service = JWTService()

# This class is responsible with authenticating accounts.
class AccountAuthenticator(object):

    # The initialization method.
    def __init__(self, mysql):
        self.mysql = mysql

    # Authenticates that email and password entered by a user are valid.
    # param IN self - this class object.
    # param IN data - the email and password entered.
    # param OUT True if valid False if not.
    def authenticate_user(self, data):
        account = Account(data['email'], data['password'],'','','','','','','','')
        return self.verify_credentials(account)

    # Verifies the user credentials.
    # param IN self - this class object.
    # param IN account - the account to verify credentials for.
    # param OUT True if verfied False if not.
    def verify_credentials(self, account):
        sqlHandler = SqlHandler(self.mysql)
        loginResultDict = {'authenticated': False}
        try :
            loginResultDict = sqlHandler.verify_credentials(account.email, account.password)
            if (loginResultDict['authenticated']):