def post(self, request):
     ''' 群主添加新管理员 '''
     check = CheckRequest(request)
     if not check.admin or check.admin.userType != 1:
         return JsonResponse({"status" : "error",
                             "msg" : "Only admin permitted"})
     uf = CheckAdminForm(check.jsonForm)
     if not uf.is_valid():
         return JsonResponse({"status" : "error",
                             "msg" : "Admin is invalid."})
     admin = GroupAdmin.objects.filter(
         groupId = check.admin.groupId,
         qq = uf.cleaned_data['qq'],
     ).first()
     if admin:
         return JsonResponse({"status": 'error',
                             'msg': "Admin exist."})
     admin = GroupAdmin(
         groupId=check.admin.groupId,
         qq=uf.cleaned_data['qq'],
         password = db_password(uf.cleaned_data['password']),
         login_random = new_random(),
         userType=0
         )
     admin.save()
     return JsonResponse({"status" : "success",
                          "msg" : "Update success."})
예제 #2
0
 def post(self, request):
     ''' 群主添加新管理员 '''
     check = CheckRequest(request)
     if not check.admin or check.admin.userType != 1:
         return JsonResponse({
             "status": "error",
             "msg": "Only admin permitted"
         })
     uf = CheckAdminForm(check.jsonForm)
     if not uf.is_valid():
         return JsonResponse({
             "status": "error",
             "msg": "Admin is invalid."
         })
     admin = GroupAdmin.objects.filter(
         groupId=check.admin.groupId,
         qq=uf.cleaned_data['qq'],
     ).first()
     if admin:
         return JsonResponse({"status": 'error', 'msg': "Admin exist."})
     admin = GroupAdmin(groupId=check.admin.groupId,
                        qq=uf.cleaned_data['qq'],
                        password=db_password(uf.cleaned_data['password']),
                        login_random=new_random(),
                        userType=0)
     admin.save()
     return JsonResponse({"status": "success", "msg": "Update success."})
예제 #3
0
 def post(self, request):
     ''' 群主添加新管理员 '''
     check = CheckRequest(request)
     if not check.admin or check.admin.userType != 1:
         return JsonResponse({"status" : "error",
                             "msg" : "只有群主才有权限"})
     uf = CheckAdminForm(check.jsonForm)
     if not uf.is_valid():
         return JsonResponse({"status" : "error",
                             "msg" : "Admin is invalid."})
     admin = GroupAdmin.objects.filter(
         groupId = check.admin.groupId,
         qq = uf.cleaned_data['qq'],
     ).first()
     if admin:
         return JsonResponse({"status": 'error',
                             'msg': "Admin exist."})
     admin = GroupAdmin(
         groupId=check.admin.groupId,
         qq=uf.cleaned_data['qq'],
         nick=uf.cleaned_data['nick'],
         login_random = new_random(),
         activate_random = new_random(),
         recover_random = new_random(),
         userType=0
         )
     admin.save()
     return JsonResponse({"status" : "success",
                          "msg" : "Update success.",
                          "data":{
                              "id": admin.id,
                              "groupId": admin.groupId,
                              "nick": admin.nick,
                              "qq": admin.qq,
                              "status": admin.status
                          }})
예제 #4
0
    def post(self, request):
        check = CheckRequest(request);
        if check.admin:
            return JsonResponse({
                "status": "error",
                "msg": "User logined"
            })
        uf = JoinForm(check.jsonForm)
        if uf.is_valid():
            groupId = uf.cleaned_data['groupId']
            groupName = uf.cleaned_data['groupName']
            qq = uf.cleaned_data['qq']
            nick = uf.cleaned_data['nick']
            password = uf.cleaned_data['password']
            #检测群是否存在
            checkGroup = Group.objects.filter(groupId__exact = groupId).first()
            if checkGroup:
                if checkGroup.status == 0:
                    return JsonResponse({
                        "status" : 'error',
                        'msg' : "此群已被注册,但正在验证中,群ID:%s" % groupId
                    })
                elif checkGroup.status == 1:
                    return JsonResponse({
                        "status" : 'error',
                        'msg' : "此群已被注册并验证通过,可申请转让,群ID:%s" % groupId
                    })
                elif checkGroup.status == 2:
                    GroupAdmin.objects.filter(groupId__exact = groupId).delete()
                    checkGroup.delete()
                else:
                    return JsonResponse({
                        "status" : 'error',
                        'msg' : "此群已被注册"
                    })
            group = Group(
                groupId = groupId,
                groupName = groupName
            )
            group.save()
            if not group.id:
                return JsonResponse({
                    "status" : 'error',
                    'msg' : "Save group error:%s" % uf.cleaned_data['groupId']
                })

            admin = GroupAdmin(
                groupId = groupId,
                qq = qq,
                nick = nick,
                password = db_password(password),
                login_random = new_random(),
                activate_random = new_random(),
                recover_random = new_random(),
                userType = 1
                )
            admin.save()
            if admin.id:
                return JsonResponse({
                    "status" : 'success',
                    'msg' : "",
                    'data':{
                        'id': admin.id,
                        'groupId' : admin.groupId,
                        'qq' : admin.qq,
                        'nick' : admin.nick,
                        'userType': admin.userType
                    }
                })
            else:
                return JsonResponse({
                    "status" : 'error',
                    'msg' : "Admin save error"
                })

        else:
            return JsonResponse({
                "status" : 'error',
                'msg' : "Illegal post: %s" % uf.errors
            })
    def post(self, request):
        check = CheckRequest(request)
        if check.admin:
            return JsonResponse({"status": "error", "msg": "User logined"})
        uf = JoinForm(check.jsonForm)
        if uf.is_valid():
            groupId = uf.cleaned_data['groupId']
            groupName = uf.cleaned_data['groupName']
            qq = uf.cleaned_data['qq']
            password = uf.cleaned_data['password']
            #检测群是否存在
            checkGroup = Group.objects.filter(groupId__exact=groupId).first()
            if checkGroup:
                if checkGroup.status == 0:
                    return JsonResponse({
                        "status": 'error',
                        'msg': "此群已被注册,但正在验证中,群ID:%s" % groupId
                    })
                elif checkGroup.status == 1:
                    return JsonResponse({
                        "status":
                        'error',
                        'msg':
                        "此群已被注册并验证通过,可申请转让,群ID:%s" % groupId
                    })
                elif checkGroup.status == 2:
                    GroupAdmin.objects.filter(groupId__exact=groupId).delete()
                    checkGroup.delete()
                else:
                    return JsonResponse({"status": 'error', 'msg': "此群已被注册"})
            group = Group(groupId=groupId, groupName=groupName)
            group.save()
            if not group.id:
                return JsonResponse({
                    "status":
                    'error',
                    'msg':
                    "Save group error:%s" % uf.cleaned_data['groupId']
                })

            admin = GroupAdmin(groupId=groupId,
                               qq=qq,
                               password=db_password(password),
                               login_random=new_random(),
                               activate_random=new_random(),
                               recover_random=new_random(),
                               userType=1)
            admin.save()
            if admin.id:
                return JsonResponse({"status": 'success', 'msg': ""})
            else:
                return JsonResponse({
                    "status": 'error',
                    'msg': "Admin save error"
                })

        else:
            return JsonResponse({
                "status": 'error',
                'msg': "Illegal post: %s" % uf.errors
            })