def join(token): form = PhoneForm(request.form) if request.method == 'POST' and form.validate_on_submit(): student = db.students.find_one( { 'token': token, 'status': { '$in': [ 1, 2, 3, 4 ] } }, { '_id': 1 }, ) if student: # Retrieve phone phone = request.form['phone'].strip() if phone.startswith('0'): phone = '+353' + phone[1:] if phone.startswith('+'): phone = phone[1:] + '@c.us' # Create code code = ''.join([ str(random.randint(0, 9)) for _ in range(6) ]) result = db.students.update_one( { 'token': token }, { '$set': { 'phone': phone, 'code': code, 'status': 2, # Status: "Code Shown" } } ) if result.matched_count == 1: # Show Code return redirect(url_for('success', code=code)) # Student not found or update could not be made return redirect(url_for('fail')) return render_template('join.html', token=token, form=form)
def schedule(): form = PhoneForm() context = { 'form': form, } if form.validate_on_submit(): brand = form.brand.data model = form.model.data problem = form.problem.data problem_explanation = form.problem_explanation.data email = form.email.data set_appointment(brand, model, problem, problem_explanation, email) return redirect('/success') return render_template('schedule.html', **context)
def phone(): """ Save the user's phone number if it has been posted and validated. Otherwise, render the form for the user to submit their phone number. """ form = PhoneForm() if form.validate_on_submit(): # save a record of the user's Foursquare user id and phone number conn = boto.dynamodb.connect_to_region(application.config['AWS_REGION'], aws_access_key_id=application.config['AWS_ACCESS'], aws_secret_access_key=application.config['AWS_SECRET']) phone_nums = conn.get_table('phonenums') item_data = {'phone': form.phone.data} item = phone_nums.new_item(hash_key=session['foursquare_id'], attrs=item_data) item.put() return redirect(url_for('done')) return render_template('phone.html', form=form, name=session["foursquare_uname"])
def send_sms(): form = PhoneForm() if form.validate_on_submit(): session['phone'] = form.phone.data msg_sent, msg_error, error_code, error_uri, error_msg_body = _sendsms( session['phone']) if msg_error == None: with open(dir_path + "/logs/send_sms_log.json", "a+") as f: f.write( json.dumps(msg_sent._properties, indent=4, sort_keys=True, default=str)) session['body'] = msg_sent.body session['date_sent'] = msg_sent.date_created session['to'] = msg_sent.to session['from'] = msg_sent.from_ session['error_message'] = msg_sent.error_message else: error_log = {"body": error_msg_body, "date_created": datetime.now().isoformat(' ', 'seconds'),\ "date_sent": None, "date_updated": datetime.now().isoformat(' ', 'seconds'),\ "direction": "outbound-api", "error_code": error_code, "error_message": msg_error, "from_": app.config['NUMBER'],\ "messaging_service_sid": None, "num_media": "0", "num_segments": "1", "price": None, "price_unit": "USD",\ "sid": None, "status": "failed", "subresource_uris": None, "to": "+61421123456", "uri": error_uri} with open(dir_path + "/logs/send_sms_log.json", "a+") as f: f.write( json.dumps(error_log, indent=4, sort_keys=True, default=str)) session['body'] = error_log["body"] session['date_sent'] = error_log["date_created"] session['to'] = error_log["to"] session['from'] = error_log["from_"] session['error_message'] = error_log["error_message"] return redirect(url_for('sms_receipt')) return render_template('phoneform.html', form=form)