Пример #1
0
def login():
    if request.method == "POST":
        userID = request.form['userID']
        passwd = request.form['passwd']
        userID, session['login'] = UserManage.authenticate_user(userID, passwd)
        if session['login']:
            session['userID'] = userID
        else:
            session['userID'] = None
        response_body = render_template('auth/login.html',
                                        title="Quizs | ログイン",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        is_post=True,
                                        userID=userID)
        response = prepare_response(response_body)
        return response
    else:
        response_body = render_template('auth/login.html',
                                        title="Quizs | ログイン",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        is_post=False)
        response = prepare_response(response_body)
        return response
Пример #2
0
def delete_user():
    if request.method == "POST":
        userID = session['userID']
        passwd = request.form['passwd']
        correct = UserManage.delete_user(userID, passwd)
        if correct:
            session['userID'] = None
            session['login'] = False

        response_body = render_template('auth/delete.html',
                                        title="Quizs | ユーザ削除",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        is_post=True,
                                        correct=correct)
        response = prepare_response(response_body)
        return response

    else:
        response_body = render_template('auth/delete.html',
                                        title="Quizs | ユーザ削除",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        is_post=False)
        response = prepare_response(response_body)
        return response
Пример #3
0
def quiz():
    if request.method == "POST":
        ans = request.form['ans']
        result, session['correct_total'], problem = QuizManage.judge(
            ans, session['quiz_num'], session['correct_total'],
            json.loads(session['order']))

        response_body = render_template('quiz/quiz.html',
                                        title="Quizs | クイズ",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        answered=True,
                                        quiz_num=session['quiz_num'],
                                        problem=problem,
                                        ans=ans,
                                        result=result)
        response = prepare_response(response_body)
        return response

    else:
        session['quiz_num'], problem = QuizManage.get_next_quiz(
            session['quiz_num'], json.loads(session['order']))

        response_body = render_template('quiz/quiz.html',
                                        title="Quizs | クイズ",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        answered=False,
                                        quiz_num=session['quiz_num'],
                                        problem=problem)
        response = prepare_response(response_body)
        return response
Пример #4
0
def register_user():
    if request.method == 'POST':
        userID = request.form['userID']
        passwd = request.form['passwd']
        userID, session['login'], message = UserManage.register_user(
            userID, passwd)
        if session['login']:
            session['userID'] = userID
        else:
            session['userID'] = None

        response_body = render_template('auth/registeruser.html',
                                        title="Quizs | ユーザ登録",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        is_post=True,
                                        message=message)
        response = prepare_response(response_body)
        return response

        return
    else:
        response_body = render_template('auth/registeruser.html',
                                        title="Quizs | ユーザ登録",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        is_post=False)
        response = prepare_response(response_body)
        return response
Пример #5
0
def updatequiz():
    if request.method == "POST":
        quizID = int(request.form['quizID'])
        problem = request.form['problem']
        correct = int(request.form['correct'])

        correct = QuizManage.update_quiz(quizID, problem, correct)

        response_body = render_template('quiz/update.html',
                                        title="Quizs | クイズ更新",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        is_post=True,
                                        correct=correct)
        response = prepare_response(response_body)
        return response

    else:
        response_body = render_template('quiz/update.html',
                                        title="Quizs | クイズ更新",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        is_post=False)
        response = prepare_response(response_body)
        return response
Пример #6
0
def result():
    response_body = render_template('quiz/result.html',
                                    title="Quizs | 結果発表",
                                    current_userID=session['userID'],
                                    login=session['login'],
                                    total=session['correct_total'])
    response = prepare_response(response_body)
    return response
Пример #7
0
 def index():
     if not 'userID' in session:
         session['userID'] = None
     if not 'login' in session:
         session['login'] = False
     response_body = render_template('index.html',
                                     title="Quizs | メインページ",
                                     current_userID=session['userID'],
                                     login=session['login'])
     response = prepare_response(response_body)
     return response
Пример #8
0
def deletequiz():
    if request.method == "POST":
        quizID = int(request.form['quizID'])

        QuizManage.delete_quiz(quizID)

        response_body = render_template('quiz/delete.html',
                                        title="Quizs | クイズ削除",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        is_post=True)
        response = prepare_response(response_body)
        return response

    else:
        response_body = render_template('quiz/delete.html',
                                        title="Quizs | クイズ削除",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        is_post=False)
        response = prepare_response(response_body)
        return response
Пример #9
0
def mypage(user_id):
    quiz_list = QuizManage.get_quiz_from_userID(user_id)
    quiz_count = 4 if len(quiz_list) > 4 else 0

    response_body = render_template('mypage/mypage.html',
                                    title=f"Quizs | {user_id}",
                                    current_userID=session['userID'],
                                    login=session['login'],
                                    quiz_list=quiz_list,
                                    quiz_count=quiz_count,
                                    param=user_id)

    response = prepare_response(response_body)
    return response
Пример #10
0
def registerquiz():
    if request.method == "POST":
        problem = request.form['problem']
        correct = int(request.form['correct'])
        userID = session['userID']

        correct = QuizManage.register_quiz(problem, correct, userID)
        response_body = render_template('quiz/registerquiz.html',
                                        title="Quizs | クイズ登録",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        is_post=True,
                                        correct=correct)
        response = prepare_response(response_body)
        return response
    else:
        response_body = render_template('quiz/registerquiz.html',
                                        title="Quizs | クイズ登録",
                                        current_userID=session['userID'],
                                        login=session['login'],
                                        is_post=False)
        response = prepare_response(response_body)
        return response
Пример #11
0
def newquiz():
    session['quiz_num'], session['correct_total'], session[
        'order'] = QuizManage.new_quiz()

    session['quiz_num'], problem = QuizManage.get_next_quiz(
        session['quiz_num'], json.loads(session['order']))

    response_body = render_template('quiz/quiz.html',
                                    title="Quizs | クイズ",
                                    current_userID=session['userID'],
                                    login=session['login'],
                                    answered=False,
                                    quiz_num=session['quiz_num'],
                                    problem=problem)
    response = prepare_response(response_body)
    return response
Пример #12
0
 def internal_server_error(error):
     response_body = render_template('internal_server_error.html',
                                     title="Quizs | 500 error")
     response = prepare_response(response_body)
     return response, 500
Пример #13
0
 def page_not_found(error):
     response_body = render_template('page_not_found.html',
                                     title="Quizs | 404 error")
     response = prepare_response(response_body)
     return response, 404