def update_user_request(): # print("in update_user_request function - request method: " + request.method) fromProfile = True name = request.form['inputName'] # print("name is: " + name) user_company = request.form['inputCompanyName'] # print("company: " + user_company) phone = request.form['inputPhone'] # print("phone: " + phone) email = request.form['inputEmail'] # print("email: " + email) password = request.form['inputPassword'] # print("password1: " + password) password2 = request.form['inputPassword2'] # print("password2: " + password2) streetAddress1 = request.form['inputStreetAddress1'] # print("street address 1: " + streetAddress1) streetAddress2 = request.form['inputStreetAddress2'] # print("street address 2: " + streetAddress2) city = request.form['inputCity'] # print("city: " + city) state = request.form['inputState'] # print("State: " + state) country = request.form['inputCountry'] # print("Country: " + country) postal = request.form['inputZip'] # print("zip: " + postal) uid = session['userid'] # print('session ID in UPDATE--', session['userid']) updated_at = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] if len(password) != 0: if password != password2: error = 'passwords do not match' return render_template('customer_profile.html', fromProfile=fromProfile, retUserName=name, \ retCompany=user_company, retEmail=email, retPhone=phone, retStreet1=streetAddress1, \ retStreet2=streetAddress2, retCity=city, retState=state, retZip=postal, retCountry=country, \ error=error) else: # update password hashedPassword = hashAPassword(getUser, password) result = User.query.filter(func.lower(User.id) == func.lower(uid)).first() if result: result.password = hashedPassword result.updated_at = updated_at db_session.update(result) db_session.commit() else: error = 'no user record found' return render_template('customer_profile.html', fromProfile=fromProfile, retUserName=name, \ retCompany=user_company, retEmail=email, retPhone=phone, retStreet1=streetAddress1, \ retStreet2=streetAddress2, retCity=city, retState=state, retZip=postal, retCountry=country, \ error=error) # update user record result = User.query.filter(func.lower(User.id) == func.lower(uid)).first() if result: result.name = name result.company = user_company result.email = email result.phone = phone result.address1 = streetAddress1 result.address2 = streetAddress2 result.city = city result.state = state result.postal = postal result.country = country result.updated_at = updated_at #db_session.update(result) db_session.commit() else: error = 'no user record found' return render_template('customer_profile.html', fromProfile=fromProfile, retUserName=name, \ retCompany=user_company, retEmail=email, retPhone=phone, retStreet1=streetAddress1, \ retStreet2=streetAddress2, retCity=city, retState=state, retZip=postal, retCountry=country, \ error=error) flash('User was successfully updated') # print 'return from call: ', user_profile.fetchone() # or use fetchall() return render_template('customer_profile.html', fromProfile=fromProfile, retUserName=name, \ retCompany=user_company, retEmail=email, retPhone=phone, retStreet1=streetAddress1, \ retStreet2=streetAddress2, retCity=city, retState=state, retZip=postal, retCountry=country)
def create_user_request(): error = None if not validUserRequest(request): error = 'Invalid data entered' print('invalid data entered') return render_template('signup.html', error=error) # print('start add process...') name = request.form['inputName'] # print("name is: " + name) password = request.form['inputPassword'] # print("password is: " + password) password2 = request.form['inputPassword2'] # print("password2 is: " + password2) user_company = request.form['inputCompanyName'] # print("company: " + user_company) phone = request.form['inputPhone'] # print("phone: " + phone) email = request.form['inputEmail'] # print("email: " + email) streetAddress1 = request.form['inputStreetAddress1'] # print("street address 1: " + streetAddress1) streetAddress2 = request.form['inputStreetAddress2'] # print("street address 2: " + streetAddress2) city = request.form['inputCity'] # print("city: " + city) state = request.form['inputState'] # print("State: " + state) country = request.form['inputCountry'] # print("Country: " + country) postal = request.form['inputZip'] # print("zip: " + postal) if not checkEmailAvailable(request): error = 'Sorry, that email is already taken' # print('email in use') return render_template('signup.html', retUserName=name, retCompany=user_company, \ retEmail=email, retPhone=phone, retStreet1=streetAddress1, retStreet2=streetAddress2, \ retCity=city, retState=state, retZip=postal, retCountry=country, error=error) i = str(uuid.uuid4()) session['userid'] = i # print('session ID in USER ADD--', session['userid']) if password == password2: updated_at = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] u = User(i, name, email, password, user_company, phone, streetAddress1, \ streetAddress2, city, state, postal, country, updated_at) db_session.add(u) db_session.commit() flash('New user was successfully added') return redirect(url_for('home')) else: #print('unsuccessful add') error="passwords do not match" return render_template('signup.html', retUserName=name, retCompany=user_company, \ retEmail=email, retPhone=phone, retStreet1=streetAddress1, retStreet2=streetAddress2, \ retCity=city, retState=state, retZip=postal, retCountry=country, error=error)