Example #1
0
def send_invite(class_id):
    email = request.form.get("email")
    createdAt = request.form.get("createdAt")

    user = User().getUserByEmail(email)
    classe = Class().getClassById(class_id)

    if user:
        invite = Invite(user=user,
                        classe=classe,
                        createdAt=createdAt,
                        status="sent")
    else:
        invite = Invite(user={"email": email},
                        classe=classe,
                        createdAt=createdAt,
                        status="sent")

    invite_id = invite.createInvite(invite)
    title = "Convite Classroom"
    message = "Você foi convidado para participar da turma {0} no Classroom!<br><a href='http://200.137.131.118/classroom/invites/{1}/register/'>Aceitar</a>".format(
        classe["name"], invite_id)

    msg = Email().send(title="Convite Classroom", message=message, email=email)

    return "OK", 200
Example #2
0
def register_invite(invite_id):
    if "_id" in session:
        user = User().getUserById(session["_id"])
        invite = Invite().getInviteById(invite_id)

        if user["email"] == invite["user"]["email"]:
            Class().addParticipant(classe=invite["class"], user=user)

            invite().deleteInviteById(invite_id)

            return redirect("/classroom/")

    return "Error: Você não tem permissão!", 400
Example #3
0
def register():
    name = request.form.get("name")
    email = request.form.get("email")
    password = request.form.get("password")
    confirmar_password = request.form.get("confirmar_password")

    #Verificar se o usuario já existe
    user = User().getUserByEmail(email)

    if user:
        return render_template(
            "user/register.html",
            error="E-mail já está sendo usado por outro usuário!")
    else:
        password = generate_password_hash(password)
        user = User(name=name, email=email, password=password)

        if User().signUpUser(user):
            return redirect("/login/")

        else:
            return render_template(
                "user/register.html",
                msg="Cadastro não realizado. Por favor. tente novamente!"), 400
Example #4
0
def login():
    email = request.form.get("email")
    password = request.form.get("password")

    user = User().getUserByEmail(email)

    if user:
        if check_password_hash(user["password"], password):
            session["email"] = user["email"]
            session["name"] = user["name"]
            session["_id"] = str(user["_id"])
            return redirect("/classroom/")

    error = "E-mail ou senha estão incorretos!"
    return render_template("user/login.html", error=error)
Example #5
0
def create_class():
    try:
        name = request.form.get("name")
        description = request.form.get("description")
        createdAt = request.form.get("createdAt")
        creator = User().getUserById(session["_id"])

        classe = Class(name=name,
                       description=description,
                       creator=creator,
                       createdAt=createdAt)

        classe.createClass(classe)

        return "OK", 200
    except:
        return "Error", 400
Example #6
0
def get_class_student(class_id):
    if "_id" in session:
        classe = Class().getClassById(class_id)
        tasks = Task().getAllTasksByClassId(class_id)
        notices = Notice().getAllNoticesByClassId(class_id)

        participants = []

        result = classe["participants"]

        for item in result:
            participants.append(User().getUserById(str(item)))

        if ObjectId(session["_id"]) in classe["participants"]:
            return render_template("classes/student.html",
                                   participants=participants,
                                   classe=classe,
                                   tasks=tasks,
                                   notices=notices)

    return "error", 400
Example #7
0
def get_class(class_id):
    if "_id" in session:
        classe = Class().getClassById(class_id)
        tasks = Task().getAllTasksByClassId(class_id)
        notices = Notice().getAllNoticesByClassId(class_id)
        invites = Invite().getAllInvitesByClassId(class_id)

        participants = []

        result = classe["participants"]

        for item in result:
            participants.append(User().getUserById(str(item)))

        if str(classe["creator"]["_id"]) == session["_id"]:
            return render_template("classes/classes.html",
                                   participants=participants,
                                   classe=classe,
                                   tasks=tasks,
                                   notices=notices,
                                   invites=invites)

    return "error", 400