def user(username): user = readdb('users').get(username) current_user_friends = readdb('friends').get(current_user.id, []) if user is None or (username != current_user.id and username not in current_user_friends): return unauthorized(None) friends = readdb('friends').get(username, []) user['friends'] = friends return render_template('profile.html', user=user)
def submit(): valid = False if request.method == 'POST': answer_json_data = json.load(request.body) lon = answer_json_data['longitude'] lat = answer_json_data['latitude'] guess = answer_json_data['answer'] riddle_id = answer_json_data['riddle_id'] answer_lat = readdb(riddle_id).get('latitude') answer_lon = readdb(riddle_id).get('longitude') answer_text = readdb(riddle_id).get('answer') if guess == answer_text or (lat == answer_lat and lon == answer_lon): valid = True return jsonify(correct=valid)
def create_user(username): user = request.get_json() user['username'] = username content = readdb('users') content[user['username']] = user writedb('users', content) return SUCCESS
def validate_user(username, password): users = readdb('users') user_dict = users.get(username) if user_dict is None or user_dict['password'] != password: return None return User(username)
def remove_friend(): content = readdb('friends') friends = request.form from_friends = set(content.setdefault(friends['from'], [])) from_friends.remove(friends['to']) to_friends = set(content.setdefault(friends['to'], [])) to_friends.remove(friends['from']) content[friends['from']] = list(from_friends) content[friends['to']] = list(to_friends) writedb('friends', content) return SUCCESS
def get_riddle(riddle_id): title = readdb(riddle_id).get('title') riddle_creator = readdb(riddle_id).get('creatorUsername') points = readdb(riddle_id).get('points') length = readdb(riddle_id).get('length') geofence = readdb(riddle_id).get('geofence') question = readdb(riddle_id).get('question') total_lon = 0 total_lat = 0 for i in range(len(geofence)): temp_point = geofence[i] total_lat += float(temp_point['lat']) total_lon += float(temp_point['lon']) center_lon = total_lon / len(geofence) center_lat = total_lat / len(geofence) if request.method == 'POST': return jsonify(title=title, creator=riddle_creator, length=length, points=points, geofence=geofence, riddle=question, center_lat=center_lat, center_lon=center_lon) return jsonify(title=title, creator=riddle_creator, length=length, points=points, geofence=geofence, center_lat=center_lat, center_lon=center_lon)
def search(): json_array = [] file_array = ['HopHacks', 'qGjUaBuw'] for i in range(len(file_array)): json_array.append(readdb(file_array[i])) return jsonify(results=json_array)
def register_user(user): content = readdb('users') content[user['username']] = user writedb('users', content)