def login(request): if request.method != 'POST': return redirect('/') try: username = request.POST['username'] passwd = request.POST['passwd'] u = User.getUserByRawUsername(username) if u!=None and u!=False and u.checkPasswd(passwd): request.session['uid'] = u.uid return redirect(referer(request)) else: raise Exception('login err') except Exception as e: messages.error(request, u'用户名或密码错误') return redirect(referer(request))
def login(request): if request.method != 'POST': return redirect('/') try: username = request.POST['username'] passwd = request.POST['passwd'] u = User.getUserByRawUsername(username) if u != None and u != False and u.checkPasswd(passwd): request.session['uid'] = u.uid return redirect(referer(request)) else: raise Exception('login err') except Exception as e: messages.error(request, u'用户名或密码错误') return redirect(referer(request))
def showContest(request): logger.info(unicode(request).replace('\n', '\t')) try: pass except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.WARNING, unicode(e)) return redirect(referer(request))
def adminLogin(request): logger.info(unicode(request).replace('\n', '\t')) try: if request.method != 'POST': return render(request, 'newtpl/register/enter_admin.html', {}) key = request.POST['key'] if key != Const.ADMIN_KEY: raise Exception('Invalid Key') request.session['admin'] = True return redirect('Register:view_teams') except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.INFO, unicode(e)) return redirect(referer(request)) return redirect('Register:admin_login')
def adminLogin(request): logger.info(unicode(request).replace("\n", "\t")) try: if request.method != "POST": return render(request, "newtpl/register/enter_admin.html", {}) key = request.POST["key"] if key != Const.ADMIN_KEY: raise Exception("Invalid Key") request.session["admin"] = True return redirect("Register:view_teams") except Exception as e: logger.error(unicode(e).replace("\n", "\t")) messages.add_message(request, messages.INFO, unicode(e)) return redirect(referer(request)) return redirect("Register:admin_login")
def judgeTeamResult(request, tid, result): logger.info(unicode(request).replace('\n', '\t')) try: admin = request.session.get('admin', None) if not admin: messages.add_message(request, messages.INFO, u'Not admin!') return redirect('Register:admin_login') valid_result = False for status in Const.TEAM_STATUS: if status == result: valid_result = True break if not valid_result: raise Exception('Invalid Result') tid = int(tid) team = Team.getById(tid) team.updateStatus(result) return redirect('Register:judge_team', tid = tid+1) except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.WARNING, unicode(e)) return redirect(referer(request))
def judgeTeamResult(request, tid, result): logger.info(unicode(request).replace('\n', '\t')) try: admin = request.session.get('admin', None) if not admin: messages.add_message(request, messages.INFO, u'Not admin!') return redirect('Register:admin_login') valid_result = False for status in Const.TEAM_STATUS: if status == result: valid_result = True break if not valid_result: raise Exception('Invalid Result') tid = int(tid) team = Team.getById(tid) team.updateStatus(result) return redirect('Register:judge_team') except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.WARNING, unicode(e)) return redirect(referer(request))