Example #1
0
File: views.py Project: levvli/oms
    def post(self, request):
        if request.user.role < 3:
            # edit_dept_form = EditDeptForm(request.POST)
            # if edit_dept_form.is_valid():

            # 获取设备
            dept = UserDepartment.objects.get(id=request.POST.get('id'))
            dept.name = request.POST.get('name')
            dept.connect = request.POST.get('connect')
            dept.connect_phone = request.POST.get('connect_phone')
            dept.comment = request.POST.get('comment')
            dept.update_user = request.user.id
            dept.update_time = datetime.datetime.now()

            dept.save()

            # 添加操作记录
            op_record = UserOperationRecord()
            op_record.op_user = request.user
            op_record.belong = 2
            op_record.status = 1
            op_record.op_num = dept.id
            op_record.operation = 2
            op_record.action = "修改部门:%s" % (dept.name)
            op_record.save()

            return HttpResponse('{"status":"success", "msg":"部门信息修改成功!"}',
                                content_type='application/json')
        # else:
        #     return HttpResponse('{"status":"failed", "msg":"部门信息填写错误,请检查!"}', content_type='application/json')
        else:
            return HttpResponse(status=403)
Example #2
0
    def post(self, request):
        if request.user.role > 1:
            obj = Machine()  #定义数据库类
            # obj=request_form.cleaned_data#数据库类赋值
            obj.add_user = request.user  #添加人为当前用户
            obj.add_time = time.strftime("%Y-%m-%d %H:%M:%S",
                                         time.localtime())  #添加时间为当前时间
            obj.name = request.POST.get('name')
            obj.area_id = request.POST.get('area')
            obj.status = request.POST.get('status')
            obj.supplier = request.POST.get('supplier')
            obj.type = request.POST.get('type')
            obj.manufacturing_date = request.POST.get('manufacturing_date')
            obj.ID_fixed_assets = request.POST.get('ID_fixed_assets')
            obj.operator_id = request.POST.get('operator')
            obj.desc = request.POST.get('desc')

            obj.save()

            #import task_pool.taskscheduler 启动条件测试

            #models.Machine.objects.create(**obj)#增加数据库记录
            # 添加操作记录
            op_record = UserOperationRecord()
            op_record.op_user = request.user
            op_record.belong = 1
            op_record.status = 1
            op_record.op_num = obj.id
            op_record.operation = 1
            op_record.action = "添加设备[ %s ]" % (request.POST.get('name'))
            op_record.save()
            return redirect('/asset/management/machine/list')
Example #3
0
    def get(self, request, active_code):
        code_record = UserEmailVirificationCode.objects.filter(
            code=active_code).filter(purpose='active').latest('add_time')
        if code_record:
            user = UserProfile.objects.get(email=code_record.email)
            user.is_active = True
            user.save()

            msg = '用户激活成功!'
            context = {
                'msg': msg,
            }

            # 添加操作记录
            op_record = UserOperationRecord()
            op_record.op_user = user
            op_record.belong = 2
            op_record.status = 1
            op_record.op_num = user.id
            op_record.operation = 3
            op_record.action = "用户 [ %s ] 激活成功" % user.chinese_name
            op_record.save()

            return render(request, 'users/login/login.html', context=context)
        else:
            msg = '地址有误,请重新发送重置邮件!'
            context = {
                'msg': msg,
            }
            return render(request,
                          'users/login/active_user.html',
                          context=context)
Example #4
0
File: views.py Project: levvli/oms
    def post(self, request):
        if request.user.role < 3:
            edit_unit_form = EditUnitForm(request.POST)
            if edit_unit_form.is_valid():

                # 获取设备
                unit = UserCompany.objects.get(id=request.POST.get('id'))
                unit.name = request.POST.get('name')
                unit.connect = request.POST.get('connect')
                unit.connect_phone = request.POST.get('connect_phone')
                unit.address = request.POST.get('address')
                unit.comment = request.POST.get('comment')
                unit.update_user = request.user.id
                unit.update_time = datetime.datetime.now()

                unit.save()

                # 添加操作记录
                op_record = UserOperationRecord()
                op_record.op_user = request.user
                op_record.belong = 2
                op_record.status = 1
                op_record.op_num = unit.id
                op_record.operation = 2
                op_record.action = "修改单位:%s" % (unit.name)
                op_record.save()

                return HttpResponse('{"status":"success", "msg":"单位信息修改成功!"}',
                                    content_type='application/json')
            else:
                return HttpResponse(
                    '{"status":"failed", "msg":"单位信息填写错误,请检查!"}',
                    content_type='application/json')
        else:
            return HttpResponse(status=403)
Example #5
0
    def post(self, request):
        if request.user.role > 1:
            tags = request.POST.get("tags", "")
            if tags == "":
                return HttpResponse('{"status":"failed", "msg":"标签为必填项!"}', content_type='application/json')

            add_doc_form = AddDocumentForm(request.POST)
            if add_doc_form.is_valid():
                try:
                    doc_id = int(request.POST.get('doc_id'))
                    doc_obj = Document.objects.get(id=doc_id)
                    doc_obj.subject = request.POST.get("subject")
                    doc_obj.content = request.POST.get("content")
                    doc_obj.belong = int(request.POST.get("belong"))
                    doc_obj.update_user = request.user
                    doc_obj.save()

                    if int(request.POST.get("belong")) == 1:
                        title = '文档'
                    else:
                        title = '脚本'

                    # 获取新标签
                    tags = request.POST.get('tags')
                    tag_list = tags.split(',')

                    # 去除旧的标签
                    doc_obj.tags.clear()

                    for each in tag_list:
                        if DocumentTags.objects.filter(name=each):
                            # 存在直接加关联
                            tag = DocumentTags.objects.get(name=each)
                            doc_obj.tags.add(tag)
                            doc_obj.save()
                        else:
                            # 不存在添加标签
                            tag_obj = DocumentTags()
                            tag_obj.name = each
                            tag_obj.save()
                            # 加入关联
                            doc_obj.tags.add(tag_obj)
                            doc_obj.save()

                    # 添加操作记录
                    op_record = UserOperationRecord()
                    op_record.op_user = request.user
                    op_record.belong = 4
                    op_record.status = 1
                    op_record.op_num = doc_obj.id
                    op_record.operation = 2
                    op_record.action = "修改%s:%s" % (title, request.POST.get("subject"))
                    op_record.save()
                    return HttpResponse('{"status":"success", "msg":"修改成功!"}', content_type='application/json')
                except Exception as e:
                    return HttpResponse('{"status":"failed", "msg":"未知错误!"}', content_type='application/json')
            else:
                HttpResponse('{"status":"failed", "msg":"填写不合法!"}', content_type='application/json')
        else:
            return HttpResponse(status=403)
Example #6
0
    def post(self, request):
        if request.user.role > 1:
            doc_obj = Document.objects.get(id=int(request.POST.get('doc_id')))
            try:
                doc_obj.status = 0
                doc_obj.update_user = request.user
                doc_obj.save()

                if doc_obj.belong == 1:
                    title = '文档'
                else:
                    title = '脚本'

                # 添加操作记录
                op_record = UserOperationRecord()
                op_record.op_user = request.user
                op_record.belong = 4
                op_record.status = 1
                op_record.op_num = doc_obj.id
                op_record.operation = 4
                op_record.action = "删除%s:%s" % (title, doc_obj.subject)
                op_record.save()
                return HttpResponse('{"status":"success", "msg":"删除成功!"}', content_type='application/json')
            except Exception as e:
                return HttpResponse('{"status":"failed", "msg":"删除失败!"}', content_type='application/json')
        else:
            return HttpResponse(status=403)
Example #7
0
File: views.py Project: levvli/oms
    def post(self, request):
        if request.user.role < 3:
            add_user_form = AddUserForm(request.POST)
            if add_user_form.is_valid():
                username = request.POST.get('username')
                password = request.POST.get('password')

                if UserProfile.objects.filter(username=username):
                    return HttpResponse(
                        '{"status":"failed", "msg":"该账号已经被另外的用户使用!"}',
                        content_type='application/json')

                # 添加用户
                user = UserProfile()
                user.role = 3
                user.username = request.POST.get('username')
                user.user_name = request.POST.get('user_name')
                user.password = make_password(password)
                user.unit_id = int(request.POST.get('unit_id'))
                user.unit_name = UserCompany.objects.get(
                    id=request.POST.get('unit_id')).name
                user.dept_id = int(request.POST.get('dept_id'))
                user.dept_name = UserDepartment.objects.get(
                    id=request.POST.get('dept_id')).name
                user.email = request.POST.get('email')
                user.mobile = request.POST.get('mobile')
                user.gender = request.POST.get('gender')
                user.status = int(request.POST.get('status'))
                user.create_user = request.user.username
                user.user_id_create = request.user.id
                user.comment = request.POST.get('comment')
                user.save()

                # 添加操作记录
                op_record = UserOperationRecord()
                op_record.op_user = request.user
                op_record.belong = 2
                op_record.status = 1
                op_record.op_num = user.id
                op_record.operation = 1
                op_record.action = "新增用户 [ %s ]" % request.POST.get(
                    'user_name')
                op_record.save()

                return HttpResponse('{"status":"success", "msg":"用户添加成功!"}',
                                    content_type='application/json')
            else:
                return HttpResponse(
                    '{"status":"failed", "msg":"填写的内容不正确,请检查!"}',
                    content_type='application/json')
        else:
            return HttpResponse(status=403)
Example #8
0
File: views.py Project: levvli/oms
    def post(self, request):
        try:
            plat_id = request.POST.get('plat_id')
            plat = PlatformInfo.objects.get(id=int(plat_id))

            # 添加操作记录
            op_record = UserOperationRecord()
            op_record.op_user = request.user
            op_record.belong = 1
            op_record.status = 1
            op_record.op_num = plat.id
            op_record.operation = 4
            op_record.action = "删除平台:%s" % (plat.name)
            op_record.save()
            plat.delete()
            return HttpResponse('{"status":"success", "msg":"平台删除成功!"}', content_type='application/json')
        except Exception as e:
            return HttpResponse('{"status":"falied", "msg":"平台删除失败!"}', content_type='application/json')
Example #9
0
File: views.py Project: levvli/oms
    def post(self, request):

        if request.user.role < 3:
            add_dev_form = AddDevForm(request.POST)
            if add_dev_form.is_valid():
                dev_id = request.POST.get('dev_id')

                if InspectDevInfo.objects.filter(dev_id=dev_id).filter():
                    return HttpResponse(
                        '{"status":"failed", "msg":"该设备id已经存在,请检查!"}',
                        content_type='application/json')

                device = InspectDevInfo()
                device.unit_id = request.POST.get('unit_id')
                device.unit_name = UserCompany.objects.get(
                    id=request.POST.get('unit_id'))
                device.dev_id = dev_id
                device.dev_name = request.POST.get('dev_name')
                device.dev_type = request.POST.get('dev_type')
                device.install_position = request.POST.get('install_position')
                device.comment = request.POST.get('comment')
                device.create_mobile = request.user.mobile
                device.create_user = request.user.id
                device.create_time = datetime.datetime.now()
                device.save()

                # 添加操作记录
                op_record = UserOperationRecord()
                op_record.op_user = request.user
                op_record.belong = 5
                op_record.status = 1
                op_record.op_num = device.id
                op_record.operation = 1
                op_record.action = "添加巡检设备:%s:%s" % (device.dev_id,
                                                     device.dev_name)
                op_record.save()
                return HttpResponse('{"status":"success", "msg":"巡检设备添加成功!"}',
                                    content_type='application/json')
            else:
                return HttpResponse(
                    '{"status":"failed", "msg":"巡检设备填写错误,请检查!"}',
                    content_type='application/json')
        else:
            return HttpResponse(status=403)
Example #10
0
File: views.py Project: levvli/oms
    def post(self, request):
        try:
            user = UserProfile.objects.get(id=request.POST.get('id'))

            # 添加操作记录
            op_record = UserOperationRecord()
            op_record.op_user = request.user
            op_record.belong = 5
            op_record.status = 1
            op_record.op_num = user.id
            op_record.operation = 4
            op_record.action = "删除用户:%s" % (user.user_name)
            op_record.save()
            user.delete()
            return HttpResponse('{"status":"success", "msg":"用户删除成功!"}',
                                content_type='application/json')
        except Exception as e:
            return HttpResponse('{"status":"falied", "msg":"用户删除失败!"}',
                                content_type='application/json')
Example #11
0
File: views.py Project: levvli/oms
    def post(self, request):
        try:
            dept = UserDepartment.objects.get(id=request.POST.get('id'))

            # 添加操作记录
            op_record = UserOperationRecord()
            op_record.op_user = request.user
            op_record.belong = 5
            op_record.status = 1
            op_record.op_num = dept.id
            op_record.operation = 4
            op_record.action = "删除部门:%s" % (dept.id)
            op_record.save()
            dept.delete()
            return HttpResponse('{"status":"success", "msg":"部门删除成功!"}',
                                content_type='application/json')
        except Exception as e:
            return HttpResponse('{"status":"falied", "msg":"部门删除失败!"}',
                                content_type='application/json')
Example #12
0
File: views.py Project: levvli/oms
    def post(self, request):
        try:
            device = InspectDevInfo.objects.get(id=request.POST.get('id'))

            # 添加操作记录
            op_record = UserOperationRecord()
            op_record.op_user = request.user
            op_record.belong = 5
            op_record.status = 1
            op_record.op_num = device.id
            op_record.operation = 4
            op_record.action = "删除巡检设备设备:%s:%s" % (device.dev_id,
                                                   device.dev_name)
            op_record.save()
            device.delete()
            return HttpResponse('{"status":"success", "msg":"巡检设备删除成功!"}',
                                content_type='application/json')
        except Exception as e:
            return HttpResponse('{"status":"falied", "msg":"巡检设备删除失败!"}',
                                content_type='application/json')
Example #13
0
 def post(self, request):
     if request.user.role > 1:
         request_form = AreaForm(request.POST)
         obj = Area()  # 定义数据库类
         obj.name = request.POST.get('name')
         obj.status = request.POST.get('area_status')
         obj.add_user = request.user  # 添加人为当前用户
         obj.add_time = time.strftime("%Y-%m-%d %H:%M:%S",
                                      time.localtime())  # 添加时间为当前时间
         obj.save()
         # 添加操作记录
         op_record = UserOperationRecord()
         op_record.op_user = request.user
         op_record.belong = 1
         op_record.status = 1
         op_record.op_num = obj.id
         op_record.operation = 1
         op_record.action = "添加设备区域[ %s ]" % (request.POST.get('name'))
         op_record.save()
         return redirect('/asset/management/machine/move/in')
Example #14
0
File: views.py Project: levvli/oms
    def post(self, request):
        try:
            cont_id = request.POST.get('id')
            content = InspectContentInfo.objects.get(id=int(cont_id))

            # 添加操作记录
            op_record = UserOperationRecord()
            op_record.op_user = request.user
            op_record.belong = 5
            op_record.status = 1
            op_record.op_num = content.id
            op_record.operation = 4
            op_record.action = "删除巡检任务:%s:%s" % (content.id, content.task_name)
            op_record.save()
            content.delete()
            return HttpResponse('{"status":"success", "msg":"巡检任务删除成功!"}',
                                content_type='application/json')
        except Exception as e:
            return HttpResponse('{"status":"falied", "msg":"巡检任务删除失败!"}',
                                content_type='application/json')
Example #15
0
File: views.py Project: levvli/oms
    def post(self, request):
        if request.user.role < 3:
            add_dept_form = AddDeptForm(request.POST)
            if add_dept_form.is_valid():
                name = request.POST.get('name')

                if UserDepartment.objects.filter(name=name):
                    return HttpResponse(
                        '{"status":"failed", "msg":"该部门名称已经被使用!"}',
                        content_type='application/json')

                # 获取信息
                dept = UserDepartment()
                dept.unit_id = request.POST.get('unit_id')
                dept.unit_name = UserCompany.objects.get(id=dept.unit_id).name
                dept.name = name
                dept.connect = request.POST.get('connect')
                dept.connect_phone = request.POST.get('connect_phone')
                dept.create_user = request.user.username
                dept.comment = request.POST.get('comment')
                dept.save()

                # 添加操作记录
                op_record = UserOperationRecord()
                op_record.op_user = request.user
                op_record.belong = 2
                op_record.status = 1
                op_record.op_num = dept.id
                op_record.operation = 1
                op_record.action = "新增部门 [ %s ]" % dept.name
                op_record.save()

                return HttpResponse('{"status":"success", "msg":"部门添加成功!"}',
                                    content_type='application/json')
            else:
                return HttpResponse(
                    '{"status":"failed", "msg":"部门信息填写错误,请检查!"}',
                    content_type='application/json')
        else:
            return HttpResponse(status=403)
Example #16
0
File: views.py Project: levvli/oms
    def post(self, request):
        if request.user.role < 3:
            edit_user_form = EditUserForm(request.POST)
            if edit_user_form.is_valid():
                # 被修改的用户
                user_id = int(request.POST.get('id'))
                edit_user = UserProfile.objects.get(id=user_id)

                # 修改其它信息
                edit_user.user_name = request.POST.get('user_name')
                edit_user.mobile = request.POST.get('mobile')
                edit_user.email = request.POST.get('email')
                edit_user.status = request.POST.get('status')
                edit_user.comment = request.POST.get('comment')
                edit_user.update_user = request.user.username
                edit_user.update_time = datetime.datetime.now()

                # 保存修改
                edit_user.save()

                # 添加操作记录
                op_record = UserOperationRecord()
                op_record.op_user = request.user
                op_record.belong = 2
                op_record.status = 1
                op_record.operation = 2
                op_record.op_num = edit_user.id
                op_record.action = "修改用户 [ %s ]" % request.POST.get(
                    'user_name')

                op_record.save()

                return HttpResponse('{"status":"success", "msg":"用户修改成功!"}',
                                    content_type='application/json')
            else:
                return HttpResponse(
                    '{"status":"failed", "msg":"填写的内容不正确,请检查!"}',
                    content_type='application/json')
        else:
            return HttpResponse(status=403)
Example #17
0
File: views.py Project: levvli/oms
    def post(self, request):
        if request.user.role < 3:
            add_unit_form = AddUnitForm(request.POST)
            if add_unit_form.is_valid():
                name = request.POST.get('name')

                if UserCompany.objects.filter(name=name):
                    return HttpResponse(
                        '{"status":"failed", "msg":"该单位名称已经被使用!"}',
                        content_type='application/json')

                # 获取信息
                unit = UserCompany()
                unit.name = name
                unit.connect = request.POST.get('connect')
                unit.connect_phone = request.POST.get('connect_phone')
                unit.address = request.POST.get('address')
                unit.create_user = request.user.user_name
                unit.comment = request.POST.get('comment')
                unit.save()

                # 添加操作记录
                op_record = UserOperationRecord()
                op_record.op_user = request.user
                op_record.belong = 2
                op_record.status = 1
                op_record.op_num = unit.id
                op_record.operation = 1
                op_record.action = "新增单位 [ %s ]" % unit.name
                op_record.save()

                return HttpResponse('{"status":"success", "msg":"单位添加成功!"}',
                                    content_type='application/json')
            else:
                return HttpResponse(
                    '{"status":"failed", "msg":"单位信息填写错误,请检查!"}',
                    content_type='application/json')
        else:
            return HttpResponse(status=403)
Example #18
0
File: views.py Project: levvli/oms
    def post(self, request):
        if request.user.role < 3:
            add_cont_form = AddContForm(request.POST)
            if add_cont_form.is_valid():
                content = InspectContentInfo()
                content.task_name = request.POST.get('task_name')
                content.task_type = request.POST.get('task_type')
                content.dept_id = request.POST.get('dept_id')
                content.dept_name = UserDepartment.objects.get(
                    id=content.dept_id).name
                content.unit_id = request.POST.get('unit_id')
                content.unit_name = UserCompany.objects.get(
                    id=content.unit_id).name
                content.user_id = request.POST.get('user_id')
                content.user_name = UserProfile.objects.get(
                    id=content.user_id).user_name
                content.create_user = request.user.user_name

                content.start_time = request.POST.get('start_time')
                content.end_time = request.POST.get('end_time')
                content.save()

                # 添加操作记录
                op_record = UserOperationRecord()
                op_record.op_user = request.user
                op_record.belong = 5
                op_record.status = 1
                op_record.op_num = content.id
                op_record.operation = 1
                op_record.action = "添加巡检任务:%s" % (content.task_name)
                op_record.save()
                return HttpResponse('{"status":"success", "msg":"巡检任务添加成功!"}',
                                    content_type='application/json')
            else:
                return HttpResponse(
                    '{"status":"failed", "msg":"巡检任务填写错误,请检查!"}',
                    content_type='application/json')
        else:
            return HttpResponse(status=403)
Example #19
0
    def get(self, request):
        # 保存登录信息
        login_record = UserLoginInfo()
        login_record.action = 2
        login_record.user = request.user
        login_record.agent = request.META['HTTP_USER_AGENT']
        login_record.ip = request.META['REMOTE_ADDR']
        # login_record.address = get_ip_location(request.META['REMOTE_ADDR'])
        login_record.address = '中国 广东 深圳'
        login_record.save()

        # 添加操作记录
        op_record = UserOperationRecord()
        op_record.op_user = request.user
        op_record.belong = 3
        op_record.status = 1
        op_record.op_num = request.user.id
        op_record.operation = 6
        op_record.action = "用户 [ %s ] 退出了系统" % request.user.chinese_name
        op_record.save()

        logout(request)

        return HttpResponseRedirect(reverse('users:login'))
Example #20
0
File: views.py Project: levvli/oms
    def post(self, request):
        if request.user.role < 3:
            edit_dev_info_form = EditDevForm(request.POST)
            if edit_dev_info_form.is_valid():

                # 获取设备
                device = InspectDevInfo.objects.get(id=request.POST.get('id'))
                device.dev_name = request.POST.get('dev_name')
                device.install_position = request.POST.get('install_position')
                device.comment = request.POST.get('comment')
                device.status = request.POST.get('status')
                device.update_user = request.user.id
                device.update_time = datetime.datetime.now()

                device.save()

                # 添加操作记录
                op_record = UserOperationRecord()
                op_record.op_user = request.user
                op_record.belong = 5
                op_record.status = 1
                op_record.op_num = device.id
                op_record.operation = 2
                op_record.action = "修改巡检设备:%s:%s" % (device.dev_id,
                                                     device.dev_name)
                op_record.save()

                return HttpResponse(
                    '{"status":"success", "msg":"巡检设备信息修改成功!"}',
                    content_type='application/json')
            else:
                return HttpResponse(
                    '{"status":"failed", "msg":"巡检设备信息填写错误,请检查!"}',
                    content_type='application/json')
        else:
            return HttpResponse(status=403)
Example #21
0
    def post(self, request):
        if request.user.role > 1:
            add_user_form = AddUserForm(request.POST)
            if add_user_form.is_valid():
                username = request.POST.get('username')
                email = request.POST.get('email')
                password = request.POST.get('password')
                re_password = request.POST.get('re_password')

                if UserProfile.objects.filter(username=username):
                    return HttpResponse(
                        '{"status":"failed", "msg":"该用户名已经被另外的用户使用!"}',
                        content_type='application/json')

                if UserProfile.objects.filter(email=email):
                    return HttpResponse(
                        '{"status":"failed", "msg":"该邮箱已经被另外的用户使用!"}',
                        content_type='application/json')

                if password != re_password:
                    return HttpResponse(
                        '{"status":"failed", "msg":"两次密码不一致,请检查!"}',
                        content_type='application/json')

                # 获取信息
                chinese_name = request.POST.get('chinese_name')
                mobile = request.POST.get('mobile')
                gender = request.POST.get('gender')
                position = request.POST.get('position')
                role = request.POST.get('role')
                status = request.POST.get('status')

                # 添加用户
                user = UserProfile()
                user.username = username
                user.chinese_name = chinese_name
                user.email = email
                user.mobile = mobile
                user.gender = gender
                user.position = UserPosition.objects.get(id=int(position))
                user.role = int(role)
                user.status = int(status)
                user.password = make_password(password)
                user.is_active = False
                user.save()

                # 添加操作记录
                op_record = UserOperationRecord()
                op_record.op_user = request.user
                op_record.belong = 2
                op_record.status = 1
                op_record.op_num = user.id
                op_record.operation = 1
                op_record.action = "新增用户 [ %s ]" % chinese_name
                op_record.save()

                return HttpResponse(
                    '{"status":"success", "msg":"用户添加成功,但未激活,请知悉!"}',
                    content_type='application/json')
            else:
                return HttpResponse(
                    '{"status":"failed", "msg":"填写的内容不正确,请检查!"}',
                    content_type='application/json')
        else:
            return HttpResponse(status=403)
Example #22
0
    def post(self, request):
        user_login_form = UerLoginForm(request.POST)

        # 输入合法
        if user_login_form.is_valid():
            # 获取提交的登录信息
            login_username = request.POST.get('username')
            login_password = request.POST.get('password')

            # 认证用户
            user = authenticate(username=login_username,
                                password=login_password)

            # 判断用户是否正确
            if user is not None:
                if not user.is_active:
                    return HttpResponseRedirect(
                        reverse('users:send_active_email'))
                elif (user.status != 1):
                    msg = '用户已停用,请联系管理员!'
                else:
                    uid1 = UserProfile.objects.get(username=login_username).id

                    # 判断用户是否登录
                    # all_session = Session.objects.all()
                    #
                    # if all_session is not None:
                    #     for session in all_session:
                    #         uid2 = session.get_decoded().get('_auth_user_id')
                    #         if uid1 == uid2:
                    #             session.delete()

                    login(request, user)

                    # 保存登录信息
                    login_record = UserLoginInfo()
                    login_record.action = 1
                    login_record.user = user
                    login_record.agent = request.META['HTTP_USER_AGENT']
                    login_record.ip = request.META['REMOTE_ADDR']
                    login_record.address = '中国 广东 深圳'
                    # login_record.address = get_ip_location(request.META['REMOTE_ADDR'])
                    login_record.save()

                    # 添加操作记录
                    op_record = UserOperationRecord()
                    op_record.op_user = user
                    op_record.belong = 3
                    op_record.status = 1
                    op_record.op_num = user.id
                    op_record.operation = 5
                    op_record.action = "用户 [ %s ] 登录了系统" % user.chinese_name
                    op_record.save()

                    return HttpResponseRedirect(reverse('users:index'))
            else:
                msg = '用户名或密码错误!'

            # 账户有问题的情况
            context = {
                'msg': msg,
                'user_login_form': user_login_form,
            }
            return render(request, 'users/login/login.html', context=context)
        else:
            # msg = '用户账户或密码不满足长度要求!'
            context = {
                # 'msg': msg,
                'user_login_form': user_login_form,
            }
            return render(request, 'users/login/login.html', context=context)
Example #23
0
    def post(self, request):
        if request.user.role > 1:
            edit_user_form = EditUserForm(request.POST)
            if edit_user_form.is_valid():
                # 被修改的用户
                uid = int(request.POST.get('uid'))
                edit_user = UserProfile.objects.get(id=uid)

                # 判断修改用户名
                username = request.POST.get('username')
                if edit_user.username != username:
                    if UserProfile.objects.filter(username=username):
                        return HttpResponse(
                            '{"status":"failed", "msg":"该用户名已经被另外的用户使用!"}',
                            content_type='application/json')
                    else:
                        edit_user.username = username

                # 判断修改邮箱
                email = request.POST.get('email')
                if edit_user.email != email:
                    if UserProfile.objects.filter(email=email):
                        return HttpResponse(
                            '{"status":"failed", "msg":"该邮箱已经被另外的用户使用!"}',
                            content_type='application/json')
                    else:
                        edit_user.email = email

                # 修改密码
                password = request.POST.get('password', '')
                re_password = request.POST.get('re_password', '')
                if password != '':
                    if password != re_password:
                        return HttpResponse(
                            '{"status":"failed", "msg":"两次密码不一致,请检查!"}',
                            content_type='application/json')
                    else:
                        edit_user.password = make_password(password)

                # 获取其它信息
                chinese_name = request.POST.get('chinese_name')
                mobile = request.POST.get('mobile')
                gender = request.POST.get('gender')
                position = request.POST.get('position')
                role = request.POST.get('role')
                status = request.POST.get('status')

                # 添加操作记录
                op_record = UserOperationRecord()
                op_record.op_user = request.user
                op_record.belong = 2
                op_record.status = 1
                op_record.operation = 2
                op_record.op_num = edit_user.id
                op_record.action = "修改用户 [ %s ]" % chinese_name

                # 判断是否修改用户状态,保存操作记录
                if edit_user.status != int(status):

                    # 启用
                    if int(status) == 1:
                        op_record.operation = 3
                        op_record.action = "启用用户 [ %s ]" % chinese_name

                    # 停用
                    if int(status) == 2:
                        op_record.operation = 4
                        op_record.action = "停用用户 [ %s ]" % chinese_name

                op_record.save()

                # 修改其它信息
                edit_user.chinese_name = chinese_name
                edit_user.mobile = mobile
                edit_user.gender = gender
                edit_user.position_id = int(position)
                edit_user.role = int(role)
                edit_user.status = int(status)

                # 保存修改
                edit_user.save()

                return HttpResponse('{"status":"success", "msg":"用户修改成功!"}',
                                    content_type='application/json')
            else:
                return HttpResponse(
                    '{"status":"failed", "msg":"填写的内容不正确,请检查!"}',
                    content_type='application/json')
        else:
            return HttpResponse(status=403)