Ejemplo n.º 1
0
def settings():
    if info()["id"] == -1:
        flash("You haven't logged in, so you can't change your password")
        return redirect("/home")
    form = ChangePasswordForm()
    success, message = ChangePassword(form)
    flash(message[0], message[1])
    if success:
        return redirect("/home")
    return render_template("settings.html.j2",
                           title="Settings",
                           info=info(),
                           form=form)
Ejemplo n.º 2
0
def applyChange(request):
    Info = info()
    try:
        chSubId = int(request.args.get('chSubId'))
        ret = useCasesAPI.changeMainSubmission(Info['id'], chSubId)
        return ret
    except:
        return -1
Ejemplo n.º 3
0
def submissions():
    ret = mainChanger.applyChange(request)
    if ret > 0:
        flash("Submission type successfully changed", "message green")
        return redirect("/submissions")
    elif request.args.get("chSubId"):
        flash("Incorrect submission id", "message red")
        return redirect("/submissions")
    userId = info()['id']
    if userId == -1:
        flash("You haven't logged in, so you can't see your submissions",
              'message red')
        return redirect('/home')

    lst = useCasesAPI.getSubmissionsU(userId)
    return render_template('submissions.html.j2',
                           title="Submissions",
                           info=info(),
                           subList=lst[::-1])
Ejemplo n.º 4
0
def sign_up():
    form = SignUp()
    success, message = Sign_up(form)
    flash(message[0], message[1])
    if success:
        return redirect("home")
    return render_template('sign_up.html.j2',
                           title="Sign Up",
                           form=form,
                           info=info())
Ejemplo n.º 5
0
def changePassword():
    Info = info()
    if (not isAdmin()):
        flash("You don't have permission to do this!", 'message red')
        return redirect("/home")
    userId = request.args.get('userId')
    if storage.getUser(userId).username == "root":
        flash("You can't change root password", "message red")
        return redirect("/users_list")
    if (userId is None):
        flash("You have to specify user id", 'message red')
        return redirect("/users_list")
    form = ChangePasswordForm()
    success, message = UserChangePassword(form, userId)
    flash(message[0], message[1])
    if success:
        return redirect("/home")
    return render_template("changePassword.html.j2",
                           title="Change Password",
                           info=info(),
                           form=form)
Ejemplo n.º 6
0
def add_problem():
    if not isAdmin():
        flash("You don't have permission to do this!", 'message red')
        return redirect("/home")
    form = AddProblemForm()
    success, message = AddProblem(form)
    flash(message[0], message[1])
    if success:
        return redirect("/home")
    return render_template('add_problem.html.j2',
                           title="Add problem",
                           form=form,
                           info=info())
Ejemplo n.º 7
0
def changeType(request) -> list:
    strUserId = request.args.get("chUserId")
    if strUserId == None:
        return [0, ("", 'message blue')]
    try:
        userId = int(strUserId)
    except:
        return [1, ("Id must be an integer", 'message red')]
    Info = info()
    if Info["id"] == userId:
        return [
            1,
            ("You don't want to change your type to default!", 'message red')
        ]
    return [1, useCasesAPI.changeUserType(userId)]
Ejemplo n.º 8
0
def login():
    form = LoginForm()
    success, message, username, userId = Login(form)
    flash(message[0], message[1])
    if success:
        resp = make_response(redirect('/home'))
        resp.set_cookie(
            "all",
            encrypt("1 " + username + ' ' + str(userId) + ' ' +
                    str(randint(0, 100000))))
        return resp
    return render_template('login.html.j2',
                           title="Sign In",
                           form=form,
                           info=info())
Ejemplo n.º 9
0
def usersList():
    Info = info()
    if (not isAdmin()):
        flash("You don't have permission to do this!", 'message red')
        return redirect("/home")
    redir, message = changeType(request)
    if message != None:
        flash(message[0], message[1])
    if redir:
        return redirect("/users_list")
    lst = useCasesAPI.getAllUsers()
    return render_template("users_list.html.j2",
                           title="List of users",
                           info=Info,
                           lst=lst)
Ejemplo n.º 10
0
def add_tournament():
    Info = info()
    if (not Info['admin']):
        flash("You don't have permission to do this!", 'message red')
        return redirect("/home")

    default = request.args.get('probId')
    if (default == None):
        default = ''

    form = TournamentForm()
    success, message = Tournament(form)
    flash(message[0], message[1])
    if success:
        return redirect("/home")
    return render_template("add_tournament.html.j2",
                           title="Add tournament",
                           form=form,
                           default=default,
                           info=Info)
Ejemplo n.º 11
0
def problemsetId(strId: str) -> list:
    try:
        probId = int(strId)
    except ValueError:
        return [0, [], None, None, None]
    problem = storage.getProblem(probId)
    if (problem is None):
        return [0, [], None, None, None]

    userId = info()['id']
    if userId == -1:
        subList = []
    else:
        subList = useCasesAPI.getSubmissionsUP(userId, probId)

    tester.loadProblemDownloads(problem)

    paths = [convertPathForApp(path[0]) for path in problem.rules.downloads]
    #paths - список путей до файлов, которые пользователь может скачать
    #print(paths)

    return [1, paths, problem, subList, useCasesAPI.getProbTournaments(probId)]
Ejemplo n.º 12
0
def ChangePassword(form: ChangePasswordForm) -> list:
    return CommonChangePassword(form, info()["id"], 1)
Ejemplo n.º 13
0
def add_user():
    if not isAdmin():
        flash("You don't have permission to do this!", 'message red')
        return redirect("/home")
    return render_template('add_user.html.j2', title="Add user", info=info())