def login(request): print "this is test" if request.method == 'POST': username = request.REQUEST.get('log_un', None) pwd = request.REQUEST.get('log_pwd', None) code = request.REQUEST.get('log_code', None) if username is None: form = LoginForm(request.POST) if form.is_valid(): cd = form.clean() username = cd['username'] pwd = cd['password'] code = cd['vcode'] i = user_auth(request, username, pwd, code) if i == 1: a = request.REQUEST.get('next', None) if a: return HttpResponseRedirect(a) else: return HttpResponseRedirect(reverse('search_result_m')) else: form.valiatetype(i) return render_to_response('login_m.html', {'form': form, }, context_instance=RequestContext(request)) else: return render_to_response('login_m.html', {'form': form, }, context_instance=RequestContext(request)) return refresh_header(request, user_auth(request, username, pwd, code)) else: form = LoginForm() next = request.GET.get('next', None) return render_to_response('login_m.html', {'form': form, 'next': next}, context_instance=RequestContext(request))
def login(request): if request.method == 'POST': username = request.REQUEST.get('log_un', None) pwd = request.REQUEST.get('log_pwd', None) code = request.REQUEST.get('log_code', None) if username is None: form = LoginForm(request.POST) print(form) if form.is_valid(): cd = form.clean() print(cd) username = cd['username'] pwd = cd['password'] code = cd['vcode'] i = user_auth(request, username, pwd, code) if i == 1: a = request.REQUEST.get('next', None) if a: return HttpResponseRedirect(a) else: return HttpResponseRedirect(reverse('searchindex')) else: form.valiatetype(i) return render_to_response('login.html', {'form': form, }, context_instance=RequestContext(request)) else: return render_to_response('login.html', {'form': form, }, context_instance=RequestContext(request)) return refresh_header(request, user_auth(request, username, pwd, code)) else: form = LoginForm() next = request.GET.get('next', None) return render_to_response('login.html', {'form': form, 'next': next}, context_instance=RequestContext(request))
def wx_binding(request): # print "get a request in wx_binding" # print "method is :"+request.method if request.method == 'POST': username = request.REQUEST.get('log_un', None) pwd = request.REQUEST.get('log_pwd', None) code = request.REQUEST.get('log_code', None) openid = request.REQUEST.get('openid', None) if username is None: form = WXLoginForm(request.POST) if form.is_valid(): cd = form.clean() # username = cd['username'] # pwd = cd['password'] username = request.REQUEST.get('username', None) pwd = request.REQUEST.get('password', None) user = auth.authenticate(username=username, password=pwd) if user is None: a = 2 elif not user.is_active: a = 3 else: auth.login(request, user) a = 1 if a == 1: a = request.REQUEST.get('next', None) if a: return HttpResponseRedirect(a) else: u = UserInformation.objects.filter(user_id=User.objects.filter(username=username)[0].id) tl = ThirdLogin.objects.filter(userInfo_id=u[0].id) if tl.exists(): tl = ThirdLogin.objects.get(userInfo_id=u[0].id) tl.wxopenId2 = openid tl.save() else: tl = ThirdLogin(wxopenId2=openid, wxFlag2=0) tl.userInfo = u[0] tl.wxFlag2 = 1 tl.wxBlock = 0 tl.save() return HttpResponseRedirect(reverse('searchindex')) else: form.valiatetype(a) return render_to_response('wx_login.html', {'form': form, 'openid': openid}, context_instance=RequestContext(request)) else: return render_to_response('wx_login.html', {'form': form, 'openid': openid}, context_instance=RequestContext(request)) return refresh_header(request, user_auth(request, username, pwd, code)) else: form = WXLoginForm() next = request.GET.get('next', None) openid = request.GET.get('openid', None) return render_to_response('wx_login.html', {'form': form, 'next': next, 'openid': openid}, context_instance=RequestContext(request))
def login(request): if request.method == 'POST': username = request.REQUEST.get('log_un', None) pwd = request.REQUEST.get('log_pwd', None) code = request.REQUEST.get('log_code', None) if username is None: form = LoginForm(request.POST) if form.is_valid(): cd = form.clean() username = cd['username'] pwd = cd['password'] code = cd['vcode'] i = user_auth(request, username, pwd, code) if i == 1: a = request.REQUEST.get('next', None) if a: return HttpResponseRedirect(a) else: user = User.objects.get(username=username) login_times = user.userinformation.login_times if login_times: user.userinformation.login_times = int( login_times) + 1 else: user.userinformation.login_times = 1 user.userinformation.save() return HttpResponseRedirect(reverse('searchindex')) else: form.valiatetype(i) return render_to_response( 'login.html', { 'form': form, }, context_instance=RequestContext(request)) else: return render_to_response( 'login.html', { 'form': form, }, context_instance=RequestContext(request)) return refresh_header(request, user_auth(request, username, pwd, code)) else: form = LoginForm() next = request.GET.get('next', None) return render_to_response('login.html', { 'form': form, 'next': next }, context_instance=RequestContext(request))
def wx_binding(request): # print "get a request in wx_binding" # print "method is :"+request.method if request.method == 'POST': username = request.REQUEST.get('log_un', None) pwd = request.REQUEST.get('log_pwd', None) code = request.REQUEST.get('log_code', None) openid = request.REQUEST.get('openid', None) if username is None: form = WXLoginForm(request.POST) if form.is_valid(): cd = form.clean() # username = cd['username'] # pwd = cd['password'] username = request.REQUEST.get('username', None) pwd = request.REQUEST.get('password', None) user = auth.authenticate(username=username, password=pwd) if user is None: a = 2 elif not user.is_active: a = 3 else: auth.login(request, user) a = 1 if a == 1: a = request.REQUEST.get('next', None) if a: return HttpResponseRedirect(a) else: u = UserInformation.objects.filter( user_id=User.objects.filter( username=username)[0].id) tl = ThirdLogin.objects.filter(userInfo_id=u[0].id) if tl.exists(): tl = ThirdLogin.objects.get(userInfo_id=u[0].id) tl.wxopenId2 = openid tl.save() else: tl = ThirdLogin(wxopenId2=openid, wxFlag2=0) tl.userInfo = u[0] tl.wxFlag2 = 1 tl.wxBlock = 0 tl.save() return HttpResponseRedirect(reverse('searchindex')) else: form.valiatetype(a) return render_to_response( 'wx_login.html', { 'form': form, 'openid': openid }, context_instance=RequestContext(request)) else: return render_to_response( 'wx_login.html', { 'form': form, 'openid': openid }, context_instance=RequestContext(request)) return refresh_header(request, user_auth(request, username, pwd, code)) else: form = WXLoginForm() next = request.GET.get('next', None) openid = request.GET.get('openid', None) return render_to_response('wx_login.html', { 'form': form, 'next': next, 'openid': openid }, context_instance=RequestContext(request))