Esempio n. 1
0
def forum_posts(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['forum']
    opt_args = ['since', 'limit', 'sort', 'order']
    short_name = extract_req(request.args, req_args)
    since, limit, sort, order = extract_opt(request.args, opt_args)

    related = extract_list(request.args, 'related',
                           ['user', 'forum', 'thread'])

    forum = get_forum_by_slug(cursor, short_name)
    posts = get_forum_posts(cursor, short_name, since, limit, sort, order)

    for post in posts:
        if 'user' in related:
            post['user'] = get_user_by_email(cursor, post['user'])

        if 'forum' in related:
            post.update({'forum': forum})

        if 'thread' in related:
            post['thread'] = get_thread_by_id(cursor, post['thread'])

    cursor.close()
    return response_ok(posts)
Esempio n. 2
0
def manage_login():
    if request.method == "POST":
        data = request.get_json()
        email = data["email"]
        if not validate_email(email):
            abort(409)
        res = create_new_credentials(db.session, email)
        if res:
            return "200"
        else:
            abort(403)

    if request.method == "GET":
        token = request.args.get("token")
        email = request.args.get("email")
        if not validate_email(email):
            abort(409)
        res = verify_user(db.session, token, email)
        if res:
            session["loggedIn"] = True
            session["email"] = email
            user = get_user_by_email(db.session, email)
            session["doctor_id"] = user.doctor_id
            return redirect("" + domain + "/")
        else:
            abort(401)
Esempio n. 3
0
def manage_user():
    loggedIn = session["loggedIn"] if "loggedIn" in session else False

    if loggedIn is True:
        user_email = session["email"]
        user = get_user_by_email(db.session, email=user_email)
        return {
            "loggedIn": True,
            "displayName": user.display_name,
            "role": user.role
        }
    else:
        return {"loggedIn": False}
Esempio n. 4
0
def forum_details(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['forum']
    short_name = extract_req(request.args, req_args)
    related = extract_list(request.args, 'related', ['user'])

    forum = get_forum_by_slug(cursor, short_name)
    if 'user' in related:
        user = get_user_by_email(cursor, forum['user'])
        forum.update({'user': user})

    cursor.close()
    return response_ok(forum)
Esempio n. 5
0
def thread_details(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['thread']
    thread = extract_req(request.args, req_args)
    related = extract_list(request.args, 'related', ['user', 'forum'])

    thread = get_thread_by_id(cursor, thread)

    if 'user' in related:
        thread['user'] = get_user_by_email(cursor, thread['user'])

    if 'forum' in related:
        thread['forum'] = get_forum_by_slug(cursor, thread['forum'])

    cursor.close()
    return response_ok(thread)
Esempio n. 6
0
def thread_details(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['thread']
    thread = extract_req(request.args, req_args)
    related = extract_list(request.args, 'related', ['user', 'forum'])

    thread = get_thread_by_id(cursor, thread)

    if 'user' in related:
        thread['user'] = get_user_by_email(cursor, thread['user'])

    if 'forum' in related:
        thread['forum'] = get_forum_by_slug(cursor, thread['forum'])

    cursor.close()
    return response_ok(thread)
Esempio n. 7
0
def post_details(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['post']
    post = extract_req(request.args, req_args)
    related = extract_list(request.args, 'related', ['user', 'forum', 'thread'])

    post = get_post_by_id(cursor, post)

    if 'user' in related:
        post['user'] = get_user_by_email(cursor, post['user'])

    if 'forum' in related:
        post['forum'] = get_forum_by_slug(cursor, post['forum'])

    if 'thread' in related:
        post['thread'] = get_thread_by_id(cursor, post['thread'])

    cursor.close()
    return response_ok(post)
Esempio n. 8
0
def post_details(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['post']
    post = extract_req(request.args, req_args)
    related = extract_list(request.args, 'related',
                           ['user', 'forum', 'thread'])

    post = get_post_by_id(cursor, post)

    if 'user' in related:
        post['user'] = get_user_by_email(cursor, post['user'])

    if 'forum' in related:
        post['forum'] = get_forum_by_slug(cursor, post['forum'])

    if 'thread' in related:
        post['thread'] = get_thread_by_id(cursor, post['thread'])

    cursor.close()
    return response_ok(post)
Esempio n. 9
0
def forum_threads(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['forum']
    opt_args = ['since', 'limit', 'order']
    short_name = extract_req(request.args, req_args)
    since, limit, order = extract_opt(request.args, opt_args)

    related = extract_list(request.args, 'related', ['user', 'forum'])

    forum = get_forum_by_slug(cursor, short_name)
    threads = get_forum_threads(cursor, short_name, since, limit, order)

    for thread in threads:
        if 'user' in related:
            thread['user'] = get_user_by_email(cursor, thread['user'])

        if 'forum' in related:
            thread['forum'] = forum

    cursor.close()
    return response_ok(threads)