예제 #1
0
파일: server.py 프로젝트: mnm364/thehopbook
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)
예제 #2
0
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)
예제 #3
0
파일: server.py 프로젝트: mnm364/thehopbook
def create_user(username):
    user = request.get_json()
    user['username'] = username
    content = readdb('users')
    content[user['username']] = user
    writedb('users', content)

    return SUCCESS
예제 #4
0
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)
예제 #5
0
파일: server.py 프로젝트: mnm364/thehopbook
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
예제 #6
0
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)
예제 #7
0
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)
예제 #8
0
def register_user(user):
    content = readdb('users')
    content[user['username']] = user
    writedb('users', content)