Exemplo n.º 1
0
def userProfile(username):
    currentUser = getCurrentUser()
    user = UserModel.getUserByUsername(username, getCurrentUid())

    if user == None:
        return render_template("not-found.html",
                               title="User Not Found!",
                               msg="The user you trying to access not found!",
                               currentUser=getCurrentUser())

    userLinks = UserModel.getUserLinks(user["uid"])
    userProjects = ProjectModel.getUserProjects(user["uid"])
    lastUserPosts = UserPostModel.getLastUserPosts(user["uid"], 10,
                                                   getCurrentUid())
    popularProjects = ProjectModel.getPopularProjects(10)
    whoToFollowList = UserModel.getWhoToFollowList(5, getCurrentUid())

    #Remove password and email fields
    user.pop("password")
    user.pop("email")

    return render_template("user-profile.html",
                           currentUser=currentUser,
                           user=user,
                           userLinks=userLinks,
                           userProjects=userProjects,
                           lastUserPosts=lastUserPosts,
                           popularProjects=popularProjects,
                           whoToFollowList=whoToFollowList)
Exemplo n.º 2
0
def userLinks():
    if request.method == "GET":
        uid = request.args.get("uid")
        if uid == None:
            uid = getCurrentUid()
        #Getting all user's links
        links = UserModel.getUserLinks(uid)
        return json.dumps(links, cls=DateTimeEncoder)
    elif request.method == "POST":
        #Stripping
        data = json.loads(request.data)
        data["name"] = data["name"].strip()
        data["link"] = data["link"].strip()

        #Adding new user link
        if data["name"] != "" and data["link"] != "":
            ulid = UserModel.addUserLink(getCurrentUid(), data["name"],
                                         data["link"])
            return json.dumps({"result": "success", "ulid": ulid})

    elif request.method == "PUT":
        #Updating a user link
        data = json.loads(request.data)
        ulid = request.args.get("ulid")
        link = UserModel.getUserLink(ulid)

        if link["uid"] == getCurrentUid():
            UserModel.updateUserLink(ulid, data["name"], data["link"])
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")

    else:
        #Delete a user link
        #DELETE request

        ulid = request.args.get("ulid")
        link = UserModel.getUserLink(ulid)

        if link["uid"] == getCurrentUid():
            UserModel.removeUserLink(ulid)
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")
    return render_template("private-api/unknown-request.html")