def handle_contact_request(template, subject_base, recipient): if request.method == 'GET': return render_template(template, c=Common(), result=('success' if 'success' in request.args else '')) if get_secret('RECAPTCHA_SECRET_KEY'): score = create_assessment(request.form['g-recaptcha-response']) if score < 0.5: return render_template(template, c=Common(), result='failure') if get_secret('MAILJET_API_KEY') and get_secret('MAILJET_API_SECRET'): mailjet = Client(auth=(get_secret('MAILJET_API_KEY'), get_secret('MAILJET_API_SECRET')), version='v3.1') subject = '[' + subject_base + '] Contact form submission by ' + request.form['name'] if request.form['wcaid']: subject += ' (' + request.form['wcaid'] + ')' data = { 'Messages': [ { 'From': { 'Email': '*****@*****.**', 'Name': 'CubingUSA Contact Form', }, 'To': [ { 'Email': recipient, }, { 'Email': request.form['from-address'], 'Name': request.form['name'], }, ], 'Subject': subject, 'TextPart': request.form['contact-message'], } ] } result = mailjet.send.create(data=data) return redirect(request.root_path + request.path + '?success=1')
def edit_users_table(filter_text=''): with client.context(): me = auth.user() if not me or not me.HasAnyRole(Roles.AdminRoles()): abort(403) if filter_text: users_to_show = User.query(ndb.OR( User.name == filter_text, User.city == filter_text, User.wca_person == ndb.Key(Person, filter_text)), order_by=[User.name]).fetch(30) else: users_to_show = User.query(order_by=[User.name]).fetch(30) return render_template('admin/edit_users_table.html', c=Common(), users=users_to_show)
def edit_user(user_id=-1): with client.context(): me = auth.user() if not me: return redirect('/') if user_id == -1: user = me else: user = User.get_by_id(user_id) if not user: return error('Unrecognized user ID %d' % user_id) if not permissions.CanViewUser(user, me): return error('You\'re not authorized to view this user.') if request.method == 'GET': return render_template( 'edit_user.html', c=Common(), user=user, all_roles=Roles.AllRoles(), editing_location_enabled=permissions.CanEditLocation(user, me), can_view_roles=permissions.CanViewRoles(user, me), editable_roles=permissions.EditableRoles(user, me), successful=request.args.get('successful', 0)) city = request.form['city'] state_id = request.form['state'] if state_id == 'empty': state_id = '' if request.form['lat'] and request.form['lng']: lat = int(request.form['lat']) lng = int(request.form['lng']) else: lat = 0 lng = 0 template_dict = {} old_state_id = user.state.id() if user.state else '' changed_location = user.city != city or old_state_id != state_id user_modified = False if permissions.CanEditLocation(user, me) and changed_location: if city: user.city = city else: del user.city if state_id: user.state = ndb.Key(State, state_id) else: del user.state if user.wca_person and old_state_id != state_id: wca_person = user.wca_person.get() if wca_person: wca_person.state = user.state wca_person.put() RewriteRanks(wca_person) user.latitude = lat user.longitude = lng user_modified = True if changed_location: # Also save the Update. update = UserLocationUpdate() update.updater = me.key if city: update.city = city update.update_time = datetime.datetime.now() if state_id: update.state = ndb.Key(State, state_id) user.updates.append(update) elif changed_location: return error('You\'re not authorized to edit user locations.') for role in permissions.EditableRoles(user, me): if role in request.form and role not in user.roles: user.roles.append(role) user_modified = True elif role not in request.form and role in user.roles: user.roles.remove(role) user_modified = True if user_modified: user.put() return redirect(request.path + '?successful=1')
def error(msg): return render_template('error.html', c=Common(), error=msg)
def nats2019unofficial(): with client.context(): return render_template('nationals/2019/unofficial.html', c=Common())
def nats2019travel(): with client.context(): return render_template('nationals/2019/travel.html', c=Common())
def nats2019schedule(): with client.context(): return render_template('nationals/2019/schedule.html', c=Common())
def nats2019(): with client.context(): return render_template('nationals/2019/index.html', c=Common(wca_disclaimer=True))
def newengland(): with client.context(): return render_template('newengland.html', c=Common())
def supported(): with client.context(): return render_template('supported.html', c=Common())
def logo(): with client.context(): return render_template('logo.html', c=Common())
def donations(): with client.context(): return render_template('donations.html', c=Common())
def who(): with client.context(): return render_template('about_who.html', c=Common())
def root(): with client.context(): return render_template('index.html', c=Common())
def edit_users(): with client.context(): me = auth.user() if not me or not me.HasAnyRole(Roles.AdminRoles()): abort(403) return render_template('admin/edit_users.html', c=Common())