예제 #1
0
 def post(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     try:
         eid = request.data['eid']
         thisEvent = event.objects.get(id=int(eid))
     except:
         return myResponse.Error("后端异常")
     if thisEvent.handler.user.openid != request.session.get("openId"):
         return myResponse.AuthError("您无权修改该事件")
     try:
         detectProblemType = request.data['detectProblemType']
         detectInfo = request.data['detectInfo']
         handleWay = request.data['handleWay']
         finalStatus = request.data['finalStatus']
         status = request.data['status']
         thisEvent.detectInfo = detectInfo
         thisEvent.handlerWay = handleWay
         thisEvent.finalStatus = finalStatus
         thisEvent.detectProblemType = detectProblemType
         thisEvent.status = status
         thisEvent.save()
         if status == "处理完成":
             thisEvent.appointment.status = 4
             thisEvent.appointment.save()
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK(data=EventSerializers(thisEvent).data)
예제 #2
0
 def post(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     try:
         thisFunctionary = functionary.objects.get(
             user__openid=request.session.get("openId"))
     except:
         return myResponse.AuthError("您不是工作人员")
     try:
         img = request.FILES.get("img")
         eid = request.data['eid']
         type = request.data['type']
     except:
         return myResponse.Error("上传异常")
     try:
         res = upload(img.file, img.name)
         if res == 200:
             thisImage = eventImage(
                 event=event.objects.get(id=int(eid)),
                 type=type,
                 url="https://xwareimage.oss-cn-beijing.aliyuncs.com/" +
                 img.name)
             thisImage.save()
         else:
             return myResponse.Error("后端异常")
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK(data=thisImage.url)
예제 #3
0
 def get(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     try:
         thisFunctionary = functionary.objects.get(
             user__openid=request.session.get("openId"))
     except:
         return myResponse.AuthError("您不是工作人员")
     try:
         UUID = request.query_params['uuid']
         thisAppointment = Appointment.objects.get(uuid=UUID)
     except:
         return myResponse.AuthError("预约获取错误")
     try:
         if thisAppointment.status != 2 and thisAppointment.status != 1 and thisAppointment.status != 3:
             return myResponse.AuthError("事件已结束")
         thisEvent = event(appointment=thisAppointment,
                           handler=thisFunctionary,
                           status="正在维修")
         thisEvent.save()
         thisAppointment.status = 3
         thisAppointment.save()
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK("绑定成功", data={"eid": thisEvent.id})
예제 #4
0
 def get(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     try:
         aid = request.query_params['aid']
         thisAppointment = Appointment.objects.get(id=int(aid))
     except:
         return myResponse.Error("预约获取异常")
     if request.session.get("openId") != thisAppointment.user.openid:
         return myResponse.AuthError("您无权获取该预约")
     return myResponse.OK(
         data=AppointmentDetailSerializers(thisAppointment).data)
예제 #5
0
 def post(self, request):
     try:
         fid = request.query_params['fid']
         thisFunctionary = functionary.objects.get(id=fid)
     except:
         return myResponse.Error("后端错误")
     if thisFunctionary.userName != request.session.get(
             "username") and request.session.get(
                 "auth") <= thisFunctionary.auth:
         return myResponse.AuthError("您无此权限")
     js_body = json.loads(request.body)
     try:
         old = js_body['old']
         newPassword = js_body['new']
     except:
         return myResponse.Error("字段错误")
     if request.session.get("auth") >= 4:
         thisFunctionary.passWord = passwordSalt(newPassword)
     else:
         if thisFunctionary.passWord == passwordSalt(old):
             thisFunctionary.passWord = passwordSalt(newPassword)
         else:
             return myResponse.Error("旧密码错误")
     thisFunctionary.save()
     return myResponse.OK("修改成功")
예제 #6
0
 def put(self, request):
     try:
         fid = request.query_params['fid']
         thisFunctionary = functionary.objects.get(id=fid)
     except:
         return myResponse.Error("后端错误")
     if thisFunctionary.userName != request.session.get(
             "username") and request.session.get(
                 "auth") <= thisFunctionary.auth:
         return myResponse.AuthError("您无此权限")
     js_body = json.loads(request.body)
     try:
         realName = js_body['realName']
         if request.session.get("auth") >= 4 and int(
                 js_body['auth']) < request.session.get("auth"):
             auth = js_body['auth']
         else:
             auth = thisFunctionary.auth
     except:
         return myResponse.Error("字段不足")
     thisFunctionary.auth = auth
     thisFunctionary.realName = realName
     thisFunctionary.save()
     return myResponse.OK(
         data=f_serializer.FunctionarySerializers(thisFunctionary).data)
예제 #7
0
 def get(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     try:
         eid = request.query_params['eid']
         thisEvent = event.objects.get(id=int(eid))
     except:
         return myResponse.Error("后端异常")
     if thisEvent.handler.user.openid == request.session.get("openId"):
         return myResponse.OK(data=EventSerializers(thisEvent).data)
     elif thisEvent.appointment.user.openid == request.session.get(
             "openId"):
         return myResponse.OK(data=EventSerializers(thisEvent).data)
     else:
         return myResponse.AuthError("您无权限查看该事件")
예제 #8
0
 def get(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     try:
         thisFunctionary = functionary.objects.get(
             user__openid=request.session.get("openId"))
     except:
         return myResponse.AuthError("您不是工作人员")
     allMyEvent = event.objects.filter(
         handler=thisFunctionary).order_by("-id")
     pg = SelfdefinedPage()
     pgr = pg.paginate_queryset(queryset=allMyEvent,
                                request=request,
                                view=self)
     return myResponse.OK(data=shortEventSerializers(pgr, many=True).data)
예제 #9
0
 def post(self, request):
     data = json.loads(request.body)
     if "username" not in data or "password" not in data:
         return myResponse.Error("数据不全")
     username = data['username']
     password = passwordSalt(data['password'])
     userList = functionary.objects.filter(userName=username)
     if userList.count() == 0:
         return myResponse.AuthError("无此用户")
     thisuser = userList[0]
     if thisuser.passWord != password:
         return myResponse.AuthError("密码错误")
     request.session['auth'] = thisuser.auth
     request.session['username'] = thisuser.userName
     return myResponse.OK(
         "登录成功",
         f_serializer.FunctionarySerializers(thisuser).data)
예제 #10
0
 def get(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     allApp = Appointment.objects.filter(
         user__openid=request.session.get("openId")).order_by("-id")
     return myResponse.OK(
         data=shortAppointmentSerializers(allApp, many=True).data)
예제 #11
0
 def post(self, request):
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     thisUser = user.objects.get(openid=request.session.get("openId"))
     try:
         username = request.data['username']
         password = request.data['password']
         thisFunctionary = functionary.objects.get(userName=username)
         finalPassword = passwordSalt(password)
         if thisFunctionary.passWord != finalPassword:
             return myResponse.AuthError("密码错误")
         thisFunctionary.user = thisUser
         thisFunctionary.save()
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK(
         data={"userInfo": userHandle(request.session.get("openId"))})
예제 #12
0
 def post(self, request):
     data = request.data
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     if not ("problemType" in data and "ProblemDetail" in data
             and "sid" in data):
         return myResponse.Error("请求参数过少")
     try:
         sid = data['sid']
         problemType = data['problemType']
         ProblemDetail = data['ProblemDetail']
         thisUUID = uuid.uuid4()
         thisUser = user.objects.get(openid=request.session.get("openId"))
         thisSlot = TimeSlot.objects.get(id=int(sid))
         exist = Appointment.objects.filter(user=thisUser,
                                            slot__Date=thisSlot.Date,
                                            status__lte=4)
         if exist.count() != 0:
             return myResponse.AuthError("该日您已有预约")
         sourseInfo = {
             "realName": thisUser.realName,
             "phone": thisUser.phone,
             "NO": thisUser.NO,
         }
         newAppointment = Appointment(
             problemType=problemType,
             uuid=thisUUID,
             user=thisUser,
             slot=thisSlot,
             describe=ProblemDetail,
             sourseInfo=sourseInfo,
         )
         newAppointment.save()
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK(
         "提交成功", data=shortAppointmentSerializers(newAppointment).data)
예제 #13
0
 def post(self, request):
     if request.session.get("auth") < 4:
         return myResponse.AuthError("您无此权限")
     js_body = json.loads(request.body)
     try:
         username = js_body['username']
         password = js_body['password']
         realName = js_body['realName']
         auth = js_body['auth']
     except:
         return myResponse.Error("字段不全")
     if functionary.objects.filter(userName=username).count() != 0:
         return myResponse.Error("已存在用户名")
     if request.session.get("auth") <= int(auth):
         return myResponse.AuthError("权限不足")
     newFunctionary = functionary(
         userName=username,
         passWord=passwordSalt(password),
         auth=int(auth),
         realName=realName,
     )
     newFunctionary.save()
     return myResponse.OK(
         data=f_serializer.FunctionarySerializers(newFunctionary).data)
예제 #14
0
 def post(self, request):
     data = request.data
     if not request.session.has_key("openId") or request.session.get(
             "openId") == "":
         return myResponse.AuthError("您未登录")
     if not ("realName" in data and "phone" in data and "NO" in data):
         return myResponse.Error("请求参数过少")
     try:
         realName = request.data["realName"]
         phone = request.data["phone"]
         NO = request.data["NO"]
         thisUser = user.objects.get(openid=request.session.get("openId"))
         thisUser.realName = realName
         thisUser.phone = phone
         thisUser.NO = NO
         thisUser.save()
     except:
         return myResponse.Error("后端异常")
     return myResponse.OK(
         "修改成功", {"userInfo": userHandle(request.session.get("openId"))})
예제 #15
0
 def wrapper(self, request):
     if (not request.session.has_key("auth")
         ) or request.session.get("auth") < power:
         return myResponse.AuthError("权限不足")
     return func(self, request)
예제 #16
0
 def wrapper(self, request):
     if not request.session.has_key('username') or request.session.get(
             'username') == "":
         return myResponse.AuthError("您未登录")
     return func(self, request)