def post(self, request):
        """
        登录页面post访问,接受登录表单提交
        表单验证成功则重定向到主页,否则重定向到登录页面的get
        登录成功会在session中存储student_id,存储后将通过student_login_require拦截器验证
        :param request:HttpRequest对象
        :return: 返回HttpResponse对象获取,render()
        """
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            user = UserModel.objects.filter(
                name=login_form.cleaned_data.get('name'))[0]
            if user.is_superuser:
                auth.login(request, user)
                my_print('用户:{:}登录'.format(user.name))
                request.session['success_info'] = '登录成功'
                return redirect(reverse('cms:index'))
            else:
                my_print('权限控制,禁止{:}访问'.format(user.name))
                request.session['error_info'] = '您没有访问的权限'
                return redirect(reverse('cms:login'))
        error = login_form.get_first_error()
        win32api.MessageBox(0, u'您没有访问的权限', u'提示', win32con.MB_OK)

        request.session['error_info'] = error
        return redirect(reverse('cms:login'))
Exemple #2
0
 def get(self, request):
     uuid, img = Captcha.gene_code()
     buf = BytesIO()  # 构建一个输入输出流
     img.save(buf, "png")  # 将图片保存到输入输出流,也就是内存中
     bur_str = buf.getvalue()  # 获得输入输出流里面的内容
     # session["Code"] = code   # 将验证码值存储到session中
     data = str(base64.b64encode(bur_str))[1:].strip("'")
     data = json.dumps({'uuid': str(uuid), 'image': data})
     my_print('验证码uuid:'+str(uuid))
     return HttpResponse(data)
 def my_wrapper(self, request, *args, **kwargs):
     user = request.user
     if user.id is None:
         request.session['error_info'] = '您还没有登录,请登录后再访问'
         my_print('未登录拦截')
         return redirect(reverse(url_name))
     if not user.is_superuser:
         request.session['error_info'] = '管理员页面,您没有权限访问'
         my_print('权限拦截')
         return redirect(reverse(url_name))
     return func(self, request, *args, **kwargs)
Exemple #4
0
 def post(self, request):
     uuid = request.POST.get('uuid')
     my_print('接受验证码uuid:'+uuid)
     code = request.POST.get('code')
     data = {}
     if Captcha.check_captcha(uuid, code):
         data['status'] = 0
         data['info'] = 'success'
     else:
         data['status'] = -1
         data['info'] = 'fail'
     return HttpResponse(json.dumps(data))
 def my_wrapper(self, request, *args, **kwargs):
     user = request.user
     if user.id is None:
         request.session['error_info'] = '您还没有登录,请登录后再访问'
         my_print('未登录拦截')
         #win32api.MessageBox(0, u'未登录拦截', u'提示', win32con.MB_OK)
         return redirect(reverse(url_name))
     if user.is_superuser:
         request.session['error_info'] = '学生页面,您没有权限访问'
         my_print('权限拦截')
         return redirect(reverse(url_name))
     return func(self, request, *args, **kwargs)
Exemple #6
0
 def post(self, request):
     """
     注册页面的post访问
     接收注册表单的请求,验证后会写入数据库
     注册成功后重定向到front:index,在session中传递info='注册成功'
     :param request:
     :return:
     """
     form = RegisterForm(request.POST)
     if form.is_valid():
         student = UserModel.objects.create(**form.cleaned_data)
         student.is_superuser = False
         student.save()
         request.session['info'] = '注册成功'
         my_print('用户:{:}注册成功'.format(student.name))
         return redirect(reverse('front:login'))
     else:
         error = form.get_first_error()
         request.session['error_info'] = error
         win32api.MessageBox(0, error, u'提示', win32con.MB_OK)
         return redirect(reverse('front:register'))
 def my_wrapper(self, request, *args, **kwargs):
     request.session.flush()
     my_print('注销登录')
     return func(self, request, *args, **kwargs)