def getpie(): currentId = session.get('user_id') db = get_db() if request.method == 'POST': name = db.execute('SELECT * FROM user WHERE id = ?', (currentId,)).fetchone() # galileo sweetness newPerson = gali.Galigali(name[10], name[11], name[12], name[13]) newPerson.setAccessToken() newPerson.transactionId = newPerson.randomString(30) if db.execute('SELECT COUNT(*) FROM SpendingAccount').fetchone()[0] < 1: db.execute('INSERT INTO SpendingAccount (rpn) VALUES (?)', (newPerson.setSpendingAccount(),)) print("successful insertion") db.commit() else: newPerson.spending_account = db.execute('SELECT rpn FROM SpendingAccount WHERE id = 1').fetchone()[0] newPerson.transfer(newPerson.transactionId) message = client.messages \ .create( body=("Medium cheese pizza ordered for " + name[3] + "! Please deliver to " + name[7] + ", " + name[9] + " " + name[6] + ", " + name[8] + "."), from_='+12562516142', to='+18054539083' ) print("Message: ", message.sid) return redirect(url_for('getpied.gotpie')) return render_template('getpie/lessago.html')
def load_logged_in_user(): user_id = session.get('user_id') if user_id is None: g.user = None else: g.user = get_db().execute('SELECT * FROM user WHERE id = ?', (user_id, )).fetchone()
def login(): if request.method == 'POST': email = request.form['email'] password = request.form['password'] db = get_db() error = None user = db.execute('SELECT * FROM user WHERE email = ?', (email, )).fetchone() if user is None: error = 'Incorrect email.' elif not check_password_hash(user['password'], password): error = 'Incorrect password.' if error is None: session.clear() session['user_id'] = user['id'] return redirect(url_for('getpied.getpie')) flash(error) return render_template('auth/login.html')
def register(): if request.method == 'POST': email = request.form['email'] password = request.form['password'] firstName = request.form['firstName'] lastName = request.form['lastName'] phoneNumber = request.form['phoneNumber'] stateID = request.form['stateID'] deliveryLocation = request.form['deliveryLocation'] zipCode = request.form['zipCode'] cardID = request.form['cardID'] gUsername = request.form['gUsername'] gPassword = request.form['gPassword'] accountNumber = request.form['accountNumber'] city = request.form['city'] db = get_db() error = [] if not firstName: error.append('First name is required.') elif len(firstName) < 2: error.append( 'First name is too short, must be at least two characters') elif len(firstName) >= 15: error.append( 'First name is too long, must be less than 16 characters') elif re.match(re.compile("^[a-zA-Z]+[-]{0,1}[a-zA-Z]*$"), firstName) is None: error.append( 'First name must use alphabetical characters, a hyphen is permitted' ) if not firstName: error.append('Last name is required.') elif len(lastName) < 2: error.append( 'Last name is too short, must be at least two characters') elif len(lastName) >= 15: error.append( 'Last name is too long, must be less than 16 characters') elif re.match(re.compile("^[a-zA-Z]+[-]{0,1}[a-zA-Z]*$"), lastName) is None: error.append( 'Last name must use alphabetical characters, a hyphen is permitted' ) if not phoneNumber: error.append('Phone number is required.') elif re.match(re.compile("^[0-9]{10}$"), phoneNumber) is None: error.append( 'Phone number is invalid, please input a sequence of 10 integers' ) if not stateID: error.append('State ID is required.') elif re.match(re.compile("^[A-Z]{2}$"), stateID) is None: error.append('State ID should be two capital letters.') if not deliveryLocation: error.append('Delivery location is required.') if not zipCode: error.append('Zip code is required.') elif re.match(re.compile("^[0-9]{5}$"), zipCode) is None: error.append( 'Zip code is invalid, please submit a 5 digit integer code.') if not city: error.append('City is required.') if not email: error.append('Email is required.') if not password: error.append('Password is required.') if not gUsername: error.append('Galileo username is required.') if not gPassword: error.append('Galileo password is required.') if not cardID: error.append('Galileo card id is required.') if not accountNumber: error.append('Galileo account number is required.') if not error: if db.execute('SELECT id FROM user WHERE email = ?', (email, )).fetchone() is not None: error = 'User {} is already registered.'.format(email) else: db.execute( 'INSERT INTO user (email, password, firstName, lastName, phoneNumber, stateID, deliveryLocation, ' 'zipCode, city, gUsername, gPassword, cardID, accountNumber) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', (email, generate_password_hash(password), firstName, lastName, phoneNumber, stateID, deliveryLocation, zipCode, city, gUsername, gPassword, cardID, accountNumber)) db.commit() return redirect(url_for('auth.login')) if error is not []: flash(error) return render_template('auth/register.html')
def gotpie(): db = get_db() return render_template('getpie/weagot.html')
def index(): db = get_db() return render_template('getpie/index.html')