예제 #1
0
def taskCreate(id):
    if "userId" in session:
        if request.method == "POST":
            profiledb.update_one({"_id": ObjectId(session["userId"])}, { "$set": {"task_update": True}})
            query = request.form
            user = profiledb.update({"_id": ObjectId(session["userId"])}, {'$push': {"tasks": {"title": query["title"],
                                                                                                "description": query["description"],
                                                                                                "type": query["type"],
                                                                                               "pfpURL": profiledb.find_one({"_id": ObjectId(id)})["pfpURL"]
                                                                                                }}})
            return redirect(url_for('profile', id=session["userId"]))
        else:
            return render_template('taskcreate.html')
예제 #2
0
def notification():
    if "userId" in session:
        while True:
            #checking for post update_self
            status_self = profiledb.find_one({"_id": ObjectId(session["userId"])})
            if status_self["post_update"] == True:
                profiledb.update_one({"_id": ObjectId(session["userId"])}, {"$set": {"post_update": False}})
                for i in postsdb.find({"userId": session["userId"]}).sort("_id", -1):
                    user = profiledb.find_one({"_id": ObjectId(i["userId"])})
                    return jsonify({"type": "posts_self", "payload": [{
                        "_id": str(i["_id"]),
                        "username": user["username"],
                        "role": user["role"],
                        "body": i["body"],
                        "date": i["date"],
                        "pfpURL": user["pfpURL"]
                    }]})


            #checking for post update_wall
            status_wall = updatedb.find_one()
            if status_wall["postId"] != session["wall_update"]:
                profiledb.update_one({"_id": ObjectId(session["userId"])}, {"$set": {"post_update": False}})
                session["wall_update"] = status_wall["postId"]
                for i in postsdb.find().sort("_id", -1):
                    user = profiledb.find_one({"_id": ObjectId(i["userId"])})
                    return jsonify({"type": "posts_wall", "payload": [{
                        "_id": str(i["_id"]),
                        "username": user["username"],
                        "role": user["role"],
                        "body": i["body"],
                        "date": i["date"],
                        "pfpURL": user["pfpURL"]
                    }]})


            #checking for task updates
            status_task = profiledb.find_one({"_id": ObjectId(session["userId"])})
            if status_task["task_update"] == True:
                profiledb.update_one({"_id": ObjectId(session["userId"])}, {"$set": {"task_update": False}})
                user = profiledb.find_one({"_id": ObjectId(session["userId"])})
                tasks = user["tasks"]
                task = tasks[-1]
                return jsonify({"type": "tasks", "payload": [{
                    "title": task["title"],
                    "pfpURL": user["pfpURL"],
                    "type": task["type"]
                }]})

            #checking for classe updates
            #---------------------------


            #checking for notification updates
            if profiledb.find_one({"_id": ObjectId(session["userId"])})["notification_update"] == True:
                profiledb.update_one({"_id": ObjectId(session["userId"])}, {"$set": {"notification_update": False}})
                user = profiledb.find_one({"_id": ObjectId(session["userId"])})
                notifications = user["notifications"]
                notification = notifications[-1]
                return jsonify({"type": "notifications", "payload": [notification]})
예제 #3
0
def post_post():
    if "userId" in session:
        data = request.get_json()
        postId = postsdb.insert_one({
            "userId": session["userId"],
            "body": data["body"],
            "date": data["date"]
        })
        profiledb.update_one({"_id": ObjectId(session["userId"])}, {"$set": {"post_update": True}})
        obj = updatedb.find_one()
        updatedb.update_one({"_id": ObjectId(obj["_id"])}, {"$set": {"postId": str(postId.inserted_id)}})
        session["wall_update"] = str(postId.inserted_id)

        return jsonify(200)
예제 #4
0
def wall_get():
    if "userId" in session:
        profiledb.update_one({"_id": ObjectId(session["userId"])}, {"$set": {"post_update": False}})
        posts = []
        for i in postsdb.find().sort("_id", 1):
            user = profiledb.find_one({"_id": ObjectId(i["userId"])})
            posts.append({
                "_id": str(i["_id"]),
                "username": user["username"],
                "role": user["role"],
                "body": i["body"],
                "date": i["date"],
                "pfpURL": user["pfpURL"]
            })
        return jsonify(posts)
예제 #5
0
def login():

    if request.method == "POST":
        session.clear()
        form = request.form
        data = profiledb.find_one({"username": form["username"]})
        if data and bcrypt.check_password_hash(data["password"], form["password"]):
            session.clear()
            update = updatedb.find_one()
            updatedb.update_one({"_id": update["_id"]}, {"$set": {"postId": None}})
            session["userId"] = str(data["_id"])
            session["wall_update"] = ""
            profiledb.update_one({"_id": ObjectId(session["userId"])}, {"$set": {"post_update": False}})
            return redirect(url_for('profile', id=session["userId"]))
        else:
            return render_template('login.html', msg="Username or Password incorrect")
    return render_template("login.html", msg="")
예제 #6
0
def login():

    if request.method == "POST":
        session.clear()
        form = request.form
        data = profiledb.find_one({"_id": ObjectId(form["_id"])})
        if data and flask_app.bcrypt.check_password_hash(
                data["password"], form["password"]):
            session.clear()
            session["userId"] = str(data["_id"])
            session["wall_update"] = ""
            profiledb.update_one({"_id": ObjectId(session["userId"])},
                                 {"$set": {
                                     "post_update": False
                                 }})
            return redirect(url_for('profile'))
        else:
            return jsonify(401)
    return render_template("login.html")
예제 #7
0
def admin_tasks():
    if profiledb.find_one({"_id": ObjectId(session["userId"])})["role"] == "admin":
        query = request.form
        user = profiledb.update({"_id": ObjectId(query["_id"])}, {'$push': {"tasks": {"title": query["title"],
                                                                                           "description": query[
                                                                                               "description"],
                                                                                           "type": query["type"],
                                                                                           "pfpURL": profiledb.find_one(
                                                                                               {"_id": ObjectId(query["_id"])})[
                                                                                               "pfpURL"]
                                                                                           }}})
        profiledb.update_one({"_id": ObjectId(query["_id"])}, {"$push": {"notifications": {
            "sender": "Administrator",
            "action": "created a task for",
            "object": "You"
        }}})
        profiledb.update_one({"_id": ObjectId(query["_id"])}, {"$set": {"task_update": True}})
        profiledb.update_one({"_id": ObjectId(query["_id"])}, {"$set": {"notification_update": True}})
        return redirect(url_for('profile', id=profiledb.find_one({"role": "admin"})["_id"]))