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
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
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
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
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
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
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
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
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
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
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
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
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