예제 #1
0
파일: Main.py 프로젝트: lmejia3/fuelup
def registerUser(user):
    response = {}
    if (('username' not in user) or ('password' not in user)):
        print('user or pass is missing for registration')
        response['error'] = 'user/pass missing'
        return response
    elif (not UR.emailIsValid(user['username'])):
        print('email format is wrong.')
        response['error'] = 'wrong email format'
        return response
    elif (not UR.passwordIsValid(user['password'])):
        print('password is too weak.')
        response['error'] = 'password is weak'
        return response
    elif (not UR.emailAvailable(user['username'])):
        print('email is taken.')
        response['error'] = 'email is taken'
        return response

    user['type'] = 'client'
    user['date'] = str(date.today())
    q = 'INSERT INTO Login_Info (Username, Passwd, Type_of_user, Register_Date) VALUES ("%s", "%s", "%s", "%s");' \
        % (user['username'], user['password'], user['type'], user['date'])
    db.runInsertQuery(q)
    id = db.runQuery('SELECT Username_ID FROM Login_Info WHERE Username = "******"' \
                     % (user['username']))[0]['Username_ID']
    db.runInsertQuery('INSERT INTO Profile_for_Users (Username_ID) VALUES (%s)' \
                      % (id))
    response['status'] = 'added'
    return response
예제 #2
0
파일: Main.py 프로젝트: lmejia3/fuelup
def getQuote(form):
    response = {}
    if ('gallons' not in form or 'date' not in form or 'username' not in form):
        print('field missing')
        response['error'] = 'field missing'
        return response

    price = PR.getQuote(form)
    today = str(date.today())

    response['price'] = price
    response['today'] = today
    response['price'] = form['price']
    response['history'] = form['history']
    response['season'] = form['season']
    response['location'] = form['location']
    response['amount'] = form['amount']
    response['profit'] = form['profit']
    response['rate'] = form['rate']

    db.runInsertQuery('INSERT INTO Quote (Username_ID, Number_of_Gallons, Price, Request_Date, Request_Delivery_Date) VALUES (%s, %s, %s, "%s", "%s")' \
                     % (form['id'], form['gallons'], price, today, form['date']))
    response['quote_id'] = db.runQuery(
        'SELECT LAST_INSERT_ID()')[0]['LAST_INSERT_ID()']
    return response
예제 #3
0
파일: Main.py 프로젝트: lmejia3/fuelup
def processOrder(form):
    response = {}
    if ('invoice_id' not in form or 'username' not in form):
        print('field missing')
        response['error'] = 'field missing'
        return response

    db.runInsertQuery('UPDATE Invoice SET Invoice.Delivery_Date = CURDATE() WHERE Invoice.Invoice_ID = %s'\
                     % (form['invoice_id']))
    return response
예제 #4
0
파일: Main.py 프로젝트: lmejia3/fuelup
def Pay(form):
    response = {}
    if ('username' not in form or 'invoice_id' not in form):
        print('field missing')
        response['error'] = 'field missing'
        return response

    q = 'UPDATE Invoice Set Paid = 1 WHERE Invoice.Invoice_ID = %s' \
        % (form['invoice_id'])
    result = db.runInsertQuery(q)
    return response
예제 #5
0
파일: Main.py 프로젝트: lmejia3/fuelup
def createInvoice(form):
    response = {}
    if ('quote_id' not in form or 'username' not in form):
        print('field missing')
        response['error'] = 'field missing'
        return response

    q = 'INSERT INTO Invoice (Paid, Username_ID, Quote_ID) SELECT 0, Quote.Username_ID, %s FROM Quote WHERE Quote.Quote_ID = %s' \
        % (form['quote_id'], form['quote_id'])

    result = db.runInsertQuery(q)
    return response
예제 #6
0
파일: Main.py 프로젝트: lmejia3/fuelup
def modifyProfile(form):
    print(form)
    response = {}
    if('username' not in form or 'lastname' not in form or 'company' not in form or 'address1' not in form or\
       'city' not in form or 'state' not in form or 'zipcode' not in form or 'firstname' not in form):
        print('field missing.')
        response['error'] = "field missing."
        return response
    q = 'SELECT * FROM Profile_for_Users INNER JOIN Login_Info ON Profile_for_Users.Username_ID = Login_Info.Username_ID WHERE Username = "******"' \
        % (form['username'])
    curProfile = db.runQuery(q)
    print(len(curProfile))
    if (len(curProfile) == 0):
        id = db.runQuery('SELECT Username_ID FROM Login_Info WHERE Username = "******"' \
            % (form['username']))[0]['Username_ID']
        db.runInsertQuery('INSERT INTO Profile_for_Users (Username_ID) VALUES (%s)' \
                          % (id))
    q = 'UPDATE Profile_for_Users NATURAL JOIN Login_Info SET First_Name = "%s", Last_Name = "%s", Company_Name = "%s", Address = "%s", Address2 = "%s", City = "%s", State = "%s", Zipcode = %s WHERE Username = "******";' \
        % (form['firstname'], form['lastname'], form['company'], form['address1'], form['address2'], form['city'], form['state'], form['zipcode'], form['username'])
    db.runInsertQuery(q)
    response['status'] = 'updated'
    return response