def signin(request, user=None, p=""): ca=Captcha(request) c = RequestContext(request) code='' u='' ip = request.META.get('REMOTE_ADDR', None) if 'uname' in request.POST: u = request.POST.get('uname') else : return render_to_response('Sign/signin.html', c) if 'pw' in request.POST: p = request.POST.get('pw') if 'code' in request.POST: code=request.POST.get('code') if not ca.validate(code): return render_to_response('Sign/signin.html', {'error': 'verifyerror'}, c) else: return render_to_response('Sign/signin.html', c) try: user = Users.objects.get(user_id=str(u)) except Users.DoesNotExist: return render_to_response('Sign/signin.html', {'error': 'usererror'}, c) if p != "" and str(p) == str(user.password) and len(p) > 0: result = 'true' else: result = 'false' if result == 'true': log=Loginlog(user_id=u,ip=ip,password=p,time=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())) log.save() response = HttpResponseRedirect('index', c) response.set_cookie('uname', u, 3600) response.set_cookie('power', user.defunct, 3600) return response else: return render_to_response('Sign/signin.html', {'error': 'pwderror'}, c)
def signup(request): c = RequestContext(request) if 'uname' not in request.POST: return render_to_response("Sign/signup.html", c) ca = Captcha(request) if 'code' in request.POST: code= request.POST.get('code') if not ca.validate(code): return render_to_response("Sign/signup.html", {'error': 4}, c) else : return render_to_response("Sign/signup.html", c) uname = request.POST.get('uname') pwd = request.POST.get('pwd') rpwd = request.POST.get('rpwd') email = request.POST.get('email') validate = request.POST.get('validate') nick = request.POST.get('nick') ip = request.META.get('REMOTE_ADDR', None) if uname == '' or pwd == '' or nick == '': return render_to_response("Sign/signup.html", {'error': 2}, c) if pwd == rpwd: c_u = Users.objects.filter(user_id=uname) if c_u: return render_to_response("Sign/signup.html", {'error': 3}, c) u = Users(defunct='C', nick=nick, user_id=uname, password=pwd, email=email, volume=str(555), language=str(555), ip=str(ip), activated=str(555), submit=0, solved=0) u.save() return HttpResponseRedirect('index') elif pwd != '' and rpwd != '': return render_to_response("Sign/signup.html", {'error': 1}, c) else : return render_to_response("Sign/signup.html", c)
def admin_login(request): c = RequestContext(request) user_name = '' ca =Captcha(request) pwd = '' ip=request.META.get('REMOTE_ADDR',None) if 'user_name' in request.POST: user_name = request.POST.get('user_name') else : return render_to_response("admin/login.html", c) if 'code' in request.POST: code = request.POST.get('code') if not ca.validate(code): return render_to_response('admin/login.html', {'verify_error': True}, c) if 'password' in request.POST: pwd = request.POST.get('password') if user_name != '': try: user = Users.objects.get(user_id=user_name) if str(user.password) == pwd: if user.defunct != 'C': log=Loginlog(user_id=user_name,password=pwd,ip=ip,time=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())) log.save() response = HttpResponseRedirect('index?menuName=&submenuName=See%20SDUSTOJ', c) response.set_cookie('uname', user_name, 3600) response.set_cookie('power', user.defunct, 3600) return response else: return render_to_response('admin/login.html', {'user_error': True}, c) else: return render_to_response('admin/login.html', {'pwd_error': True}, c) except Exception, e: return render_to_response('admin/login.html', {'user_error': True}, c)
def index(request): ca_mode = request.GET.get('mode', 'word').lower() assert ca_mode in ['number', 'word', 'four_number'] _code = request.GET.get('code') or '' if not _code: return render('index.html', locals()) ca = Captcha(request) if ca.validate(_code): return HttpResponse("""<h1>^_^</h1><a href="/">back</a>""") return HttpResponse("""<h1>:-(</h1><a href="/">back</a>""")
def index(request): ca_type = request.GET.get('type', 'word').lower() assert ca_type in ['number', 'word'] _code = request.GET.get('code') or '' if not _code: return render('index.html',locals()) ca = Captcha(request) if ca.validate(_code): return HttpResponse("""<h1>^_^</h1><a href="/">back</a>""") return HttpResponse("""<h1>:-(</h1><a href="/">back</a>""")
def admin_login(request): c = RequestContext(request) user_name = '' ca = Captcha(request) pwd = '' ip = request.META.get('REMOTE_ADDR', None) if 'user_name' in request.POST: user_name = request.POST.get('user_name') else: return render_to_response("admin/login.html", c) if 'code' in request.POST: code = request.POST.get('code') if not ca.validate(code): return render_to_response('admin/login.html', {'verify_error': True}, c) if 'password' in request.POST: pwd = request.POST.get('password') if user_name != '': try: user = Users.objects.get(user_id=user_name) if str(user.password) == pwd: if user.defunct != 'C': log = Loginlog(user_id=user_name, password=pwd, ip=ip, time=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())) log.save() response = HttpResponseRedirect( 'index?menuName=&submenuName=See%20SDUSTOJ', c) response.set_cookie('uname', user_name, 3600) response.set_cookie('power', user.defunct, 3600) return response else: return render_to_response('admin/login.html', {'user_error': True}, c) else: return render_to_response('admin/login.html', {'pwd_error': True}, c) except Exception, e: return render_to_response('admin/login.html', {'user_error': True}, c)
def signin(request, user=None, p=""): ca = Captcha(request) c = RequestContext(request) code = '' u = '' ip = request.META.get('REMOTE_ADDR', None) if 'uname' in request.POST: u = request.POST.get('uname') else: return render_to_response('Sign/signin.html', c) if 'pw' in request.POST: p = request.POST.get('pw') if 'code' in request.POST: code = request.POST.get('code') if not ca.validate(code): return render_to_response('Sign/signin.html', {'error': 'verifyerror'}, c) else: return render_to_response('Sign/signin.html', c) try: user = Users.objects.get(user_id=str(u)) except Users.DoesNotExist: return render_to_response('Sign/signin.html', {'error': 'usererror'}, c) if p != "" and str(p) == str(user.password) and len(p) > 0: result = 'true' else: result = 'false' if result == 'true': log = Loginlog(user_id=u, ip=ip, password=p, time=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())) log.save() response = HttpResponseRedirect('index', c) response.set_cookie('uname', u, 3600) response.set_cookie('power', user.defunct, 3600) return response else: return render_to_response('Sign/signin.html', {'error': 'pwderror'}, c)
def signup(request): c = RequestContext(request) if 'uname' not in request.POST: return render_to_response("Sign/signup.html", c) ca = Captcha(request) if 'code' in request.POST: code = request.POST.get('code') if not ca.validate(code): return render_to_response("Sign/signup.html", {'error': 4}, c) else: return render_to_response("Sign/signup.html", c) uname = request.POST.get('uname') pwd = request.POST.get('pwd') rpwd = request.POST.get('rpwd') email = request.POST.get('email') validate = request.POST.get('validate') nick = request.POST.get('nick') ip = request.META.get('REMOTE_ADDR', None) if uname == '' or pwd == '' or nick == '': return render_to_response("Sign/signup.html", {'error': 2}, c) if pwd == rpwd: c_u = Users.objects.filter(user_id=uname) if c_u: return render_to_response("Sign/signup.html", {'error': 3}, c) u = Users(defunct='C', nick=nick, user_id=uname, password=pwd, email=email, volume=str(555), language=str(555), ip=str(ip), activated=str(555), submit=0, solved=0) u.save() return HttpResponseRedirect('index') elif pwd != '' and rpwd != '': return render_to_response("Sign/signup.html", {'error': 1}, c) else: return render_to_response("Sign/signup.html", c)