Exemplo n.º 1
0
def getdifuser(request):
    if request.method == "POST":
        pageNo = request.POST.get("page", None)  # 读取get数据,None为默认值
        userid = request.POST.get("userid", None)  # 读取get数据,None为默认值
        showtype = request.POST.get("showtype", None)  # 读取get数据,None为默认值
    if request.method == "GET":
        pageNo = request.GET.get("page", None)  # 读取get数据,None为默认值
        userid = request.GET.get("userid", None)  # 读取get数据,None为默认值
        showtype = request.GET.get("showtype", None)  # 读取get数据,None为默认值

    print("查询各种各样的用户:用户ID:" + userid+"类型"+showtype)

    result = {}
    alluser =[]

    me = UserDAO.getUserInfoId(userid)
    if(not me):
        result["respcode"]= ResultCode.FAIL
        result["message"]= "用户不存在!请先注册登陆"
        result["data"]= ""
        result["errorcode"]= ResultCode.FAIL
        print("用户不存在")
        return result

    page = PageForId()
    page.pageNo=pageNo
    page.userId=userid
    page.pageSize=100  #一次查询100个
    page.deal=showtype
    totalPage = 0
    try:
        totalPage = MoreDAO.selectmorelistnumInfopage(page)
    except Exception as e1:
        print(e1)

    page.totalPage=totalPage
    page.pageSize=10
    page.start=10*(pageNo-1)   #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    allmore = MoreDAO.selectmorelistInfopage(page)
    if(allmore  and  len(allmore) !=0):
        for i in range(len(allmore)):
            user1 = UserDAO.getUserInfoId(allmore[i].userid_destination)
            user_back = fun.user2else_back(user1)
            more = getuserdeal(userid,user1.id, ResultCode.USER_ZAN)
            if(more):
                user_back.ideal=ResultCode.USER_ZAN
            alluser.add(user_back)


    print("查询各种各样用户,数目为" ,len(alluser))
    result["respcode"]= ResultCode.SUCCESS
    result["message"]= "查询用户成功!"
    result["data"]= alluser
    result["errorcode"]= ResultCode.SUCCESS
    return result
Exemplo n.º 2
0
def updateuserstate(request):
    result = {}
    user_receive = User()
    if request.method == "POST":
        userid = request.POST.get("userid", None)  # 读取get数据,None为默认值
        qunid = request.POST.get("qunid", None)  # 读取get数据,None为默认值
        userstate = request.POST.get("userstate", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        userid = request.GET.get("userid", None)  # 读取get数据,None为默认值
        qunid = request.GET.get("qunid", None)  # 读取get数据,None为默认值
        userstate = request.GET.get("userstate", None)  # 读取get数据,None为默认值

    print("修改用户在群组中的状态接口参数:用户id" + userid +"用户状态" + userstate)

    user_receive = UserDAO.getUserInfoId(userid)
    user_receive.state(userstate)
    UserDAO.updateUserInfo(user_receive)
    qun = QunDAO.getqunInfoqunid(qunid)

    userqun=Userqun()
    userqun.userid=userid
    userqun.qunid=qunid
    userqun = UserqunDAO.getuserqunInfouserqun(userqun)

    if(not userqun or not qun):
        result["data"]=""
        result["respcode"]= ResultCode.FAIL
        result["errorcode"]=ResultCode.FAIL
        result["message"]= "修改失败not "
        return result

    userqun.userstate=userstate
    UserqunDAO.updateuserqun(userqun)

    #如果升级为群主
    if(userstate==ResultCode.USERQUN_QUNZHU):

        #查找原群主关系组
        userqun.userid=qun.userid
        userqun.qunid=qunid
        userqun = UserqunDAO.getuserqunInfouserqun(userqun)
        userqun.userstate=ResultCode.USERQUN_FUZHU
        UserqunDAO.updateuserqun(userqun)
        #修改群信息
        qun.userid=userid
        QunDAO.updatequnInfoqun(qun)


    result["data"]= ""
    result["respcode"]= ResultCode.SUCCESS
    result["errorcode"]= ""
    result["message"]= "修改成功not "

    return result
Exemplo n.º 3
0
def queryAllchatuser(request):
    #第一层的结果集
    result = {}
    allchatuser_back = []
    if request.method == "POST":
        receive_id = request.POST.get("receive_id", None)  # 读取post数据,None为默认值
    if request.method == "GET":
        receive_id = request.GET.get("receive_id", None)  # 读取post数据,None为默认值
    print("查询所有聊天用户接口参数:接收者ID" + receive_id)

    try:
        allchatuser = ChatuserDAO.queryallchatuser(receive_id)

        if (allchatuser != None and len(allchatuser) > 0):
            userreceive = fun.user2else_back(UserDAO.getUserInfoId(receive_id))
            for chatuser in allchatuser:
                print("查询到总数为", len(allchatuser))
                if (chatuser.state != ResultCode.CHATUSER_HIDE):  #如果不隐藏该关系的话
                    chatuser_back = fun.chatuser2back(chatuser)
                    #如果是私信
                    if (chatuser_back.usertype == ResultCode.CHATUSER_TYPE_SEND
                            or chatuser_back.usertype()
                            == ResultCode.CHATUSER_TYPE_RECEIVE):
                        usertemp = UserDAO.getUserInfoId(
                            chatuser_back.send_id())
                        chatuser_back['send_user'] = fun.user2else_back(
                            usertemp)
                        chatuser_back['receive_user'] = userreceive
                        allchatuser_back.add(chatuser_back)
                        #如果是群聊
                    if (chatuser_back.usertype == ResultCode.CHATUSER_TYPE_QUN
                        ):
                        quntemp = QunDAO.getqunInfoqunid(chatuser_back.send_id)
                        chatuser_back['qun'] = quntemp
                        chatuser_back['receive_user'] = userreceive
                        allchatuser_back.add(chatuser_back)

        result["message"] = "查询成功"
        result["data"] = allchatuser_back
        result["errorcode"] = ""
        result["respcode"] = ResultCode.SUCCESS
        print("查询成功数目" + allchatuser_back.size())

    except Exception as e:
        print(e)
        result["message"] = "查询失败"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
        print("查询失败")

    return result
Exemplo n.º 4
0
    def logout(self, user):
        TN_INFO(user.getName() + " logged out.")

        room = user.getRoom()
        if room:
            self.userExitRoom(user, room)

        online_time = (datetime.now() - user.getLoginTime()).total_seconds()
        UserDAO.getInstance().addOnlineTime(user.getName(), int(online_time))

        self._online_users.remove(user)
        del user.getConnection()['user']
        del user
Exemplo n.º 5
0
def queryAllsixin(request):
    #第一层的结果集
    result = {}
    allmessage_back = []

    if request.method == "POST":
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    print("查询某人的所有接收私信接口参数:接收者ID" + receive_id + "page" + pageNo)

    #获取聊天数目
    page = PageForId()
    page.pageNo = pageNo
    page.receive_id = receive_id

    page.pageSize = 10
    page.start = 10 * (pageNo - 1)  #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    try:
        allMessage = Chat_MessageDAO.queryAllsixin(page.receive_id, page.start,
                                                   page.pageSize)  #通过abid查询
        if (allMessage != None and len(allMessage) > 0):
            receiveuser = fun.user2else_back(UserDAO.getUserInfoId(receive_id))
            for message in allMessage:
                senduser = fun.user2else_back(
                    UserDAO.getUserInfoId(message.getSend_id()))
                message_back = fun.chatmessage2back(message)
                message_back.send_user = senduser
                message_back.receive_user = receiveuser

                allmessage_back.add(message_back)

        result["message"] = "查询成功"
        result["data"] = allmessage_back
        result["errorcode"] = ""
        result["respcode"] = ResultCode.SUCCESS

    except Exception as e:
        print(e)
        result["message"] = "查询失败"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
        print("查询失败")

    return result
Exemplo n.º 6
0
def uploadUserIcon(request):
    result = {}
    user=User()
    if request.method == "POST":
        id = request.POST.get("id", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        id = request.GET.get("id", None)  # 读取get数据,None为默认值

    print("修改图像接口参数:用户id:"+id)
    realPath = request.getSession().getServletContext().getRealPath("userIcon/")

    if not os.path.exists(realPath):
        os.makedirs(realPath)
    try:
        files = request.FILES.getlist('files')
        multFile = files[0]
        filenameString = id + "_" + str(int(time.time())) + "_" + str(0) + ".png"

        filepath = realPath + "/" + filenameString

        f_obj = open(filepath, 'wb+')
        for chunk in multFile.chunks():
            f_obj.write(chunk)
        f_obj.close()

        fileName = "/userIcon/" + filenameString

        print("用户图像所在地址:" + realPath+"/"+fileName)
        user.image=fileName
        user.id=id
        UserDAO.updateUserIcon(user)

        users_back = UserDAO.getUserInfoId(user.id)
        loginResult = user2meBack(users_back)


        result["data"]= loginResult
        result["errorcode"]= ""
        result["message"]= "上传用户图像成功"
        result["respcode"]=ResultCode.SUCCESS
    except Exception as e:
        result["data"]= ""
        result["errorcode"]= ResultCode.VINT
        result["message"]= "文件不合法"
        result["respcode"]= ResultCode.FAIL


    return result
Exemplo n.º 7
0
    def onLogin(self, connection, decoded_request):
        if ('username' not in decoded_request):
            raise InvalidRequestError("key 'username' not found.")
        username = decoded_request['username']

        if ('password' not in decoded_request):
            raise InvalidRequestError("key 'password' not found.")
        password = decoded_request['password']

        dao = UserDAO.getInstance()
        if (dao.existUser(username) == False):
            raise RequestFailedError('Username does not exist.')

        if (dao.getPassword(username) != password):
            raise RequestFailedError('Wrong password.')

        # check whether user has been online
        for onlined_user in self._online_users:
            if username == onlined_user.getName():
                user_connection = onlined_user.getConnection()
                if user_connection.getRemoteAddr() != connection.getRemoteAddr(
                ):
                    raise RequestFailedError(
                        'This user has already logined on another computer.')
                else:
                    self.logout(user)

        user = User(username, connection)
        self._online_users.append(user)
        user.setLoginTime(datetime.now())
        connection['user'] = user
        TN_INFO(username + " logged in.")
        response = {'code': Code.SUCCESS}
        response['online_time'] = dao.getOnlineTime(username)
        connection.send(Protocol.makeMessageFromDict(response))
Exemplo n.º 8
0
def getallqunuser(request):
    if request.method == "POST":
        pageNo = request.POST.get("page", None)  # 读取get数据,None为默认值
        userid = request.POST.get("userid", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        pageNo = request.GET.get("page", None)  # 读取get数据,None为默认值
        userid = request.GET.get("userid", None)  # 读取get数据,None为默认值

    print("查询用户所在群下所有用户:用户ID:" + userid)

    result = {}

    page = PageForId()
    page.pageNo=pageNo
    page.userId=userid
    page.pageSize=20  #一次查询100个
    page.start=20*(pageNo-1)   #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    allUsers = UserDAO.queryallqunuser(page)
    alluserback = []
    for i in range(len(allUsers)):
        alluserback.add(fun.user2else_back(allUsers[i]))


    print("查询到用户,数目为" ,len(alluserback))
    result["respcode"]= ResultCode.SUCCESS
    result["message"]= "查询用户成功!"
    result["data"]= alluserback
    result["errorcode"]= ResultCode.SUCCESS
    return result
Exemplo n.º 9
0
def getalluser(request):
    if request.method == "POST":
        pageNo = request.POST.get("page", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        pageNo = request.GET.get("page", None)  # 读取get数据,None为默认值

    print("查询所有用户")

    result = {}
    alluserback = []


    page = PageForId()
    page.pageNo=pageNo
    page.pageSize=100  #一次查询100个

    page.start=100*(pageNo-1)   #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录

    alluser = UserDAO.queryalluser(page)

    if(alluser  and len(alluser) !=0):
        for i in range(len(alluser)):
            user_back = fun.user2else_back(alluser[i])
            alluserback.add(user_back)

    result["respcode"]= ResultCode.SUCCESS
    result["message"]= "查询用户成功!"
    result["data"]= alluserback
    result["errorcode"]= ResultCode.SUCCESS
    return result
Exemplo n.º 10
0
def getUserInfo(request):
    result = {}
    if request.method == "POST":
        userid = request.POST.get("userid", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        userid = request.GET.get("userid", None)  # 读取get数据,None为默认值

    print("查询用户资料接口参数:用户id:" + userid)

    user = UserDAO.getUserInfoId(userid)
    if (user):
        user_else= fun.user2else_back(user)
        result["message"]= "查询成功"
        result["respcode"]= ResultCode.SUCCESS
        result["data"]= user_else
        result["errorcode"]= ""
    else:
        # 没有查询到该用户
        result["message"]= "用户不存在"
        result["respcode"]=ResultCode.FAIL
        result["data"]=""
        result["errorcode"]=ResultCode.UNUSEREXIST
    

    return result
Exemplo n.º 11
0
 def __init__(self):
     self.database_connection = mysql.connect(
         host='localhost',
         user='******',
         password='',
         database='chitchatdb'
     )
     self.cursor = self.database_connection.cursor()
     self.userDAO = UserDAO(self.database_connection)
     self.messageDAO = MessageDAO(self.database_connection)
     self.host = server_host.host
     self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.socket.bind(self.host)
     self.socket.listen(5)
     self.connected_clients = {}
     self.lock = Lock()
     self.messages_queue = Queue()
Exemplo n.º 12
0
def getalldealdiaryforqunid(request):
    returnData={}
    if request.method == "POST":
        pageNo = request.POST.get("page", None)  # 读取post数据,None为默认值
        qunid = request.POST.get("qunid", None)  # 读取post数据,None为默认值
    if request.method == "GET":
        pageNo = request.GET.get("page", None)  # 读取get数据,None为默认值
        qunid = request.GET.get("qunid", None)  # 读取get数据,None为默认值

    print("查询指定群日志处理接口参数:群ID" + qunid+"pageNo:"+pageNo)

    qun = QunDAO.getqunInfoqunid(qunid)

    page = PageForId()
    page.pageNo(pageNo)
    page.qunid(qunid)
    page.pageSize(10)
    page.start(10*(pageNo-1))
    try:
        alluserdeal_back = []
        alluserdeal = UserDealDAO.selectuserdealforqunid(page)
        print("查询到数目"+len(alluserdeal))
        for i in range(len(alluserdeal)):
            userDeal_back = fun.userdeal2back(alluserdeal[i])
            userelse = fun.user2else_back(UserDAO.getUserInfoId(alluserdeal[i].userid))
            userDeal_back.user=userelse
            userDeal_back.qun=qun

            alldealdiary_back =[]
            alldealdiary = DiaryDealDAO.selectdealdiaryfordealid(userDeal_back.id)
            for t in range(len(alldealdiary)):

                dealDiary_Back = fun.dealdiary2back(alldealdiary[t])
                diary=DiaryDAO.selectDiary(alldealdiary[t].id)
                diaryback=fun.diary2back(diary)
                dealDiary_Back.diary(diaryback)
                alldealdiary_back.add(dealDiary_Back)

            userDeal_back.alldealdiary(alldealdiary_back)
            alluserdeal_back.add(userDeal_back)

        returnData["respcode"]=ResultCode.SUCCESS
        returnData["message"]="查询所有日志处理成功!"
        returnData["data"]=alluserdeal_back
        returnData["errorcode"]=ResultCode.SUCCESS
        print("查询成功数目"+len(alluserdeal_back))

    except Exception as e:
        returnData["respcode"]=ResultCode.FAIL
        returnData["message"]="查询所有日志处理失败!"
        returnData["errorcode"]=ResultCode.FAIL
        returnData["data"]=""
        print("查询失败")

    return returnData
Exemplo n.º 13
0
def updateUserPwd(request):
    result = {}
    if request.method == "POST":
        id = request.POST.get("id", None)  # 读取get数据,None为默认值
        oldpassword = request.POST.get("oldpassword", None)  # 读取get数据,None为默认值
        newpassword = request.POST.get("newpassword", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        id = request.GET.get("id", None)  # 读取get数据,None为默认值
        oldpassword = request.GET.get("oldpassword", None)  # 读取get数据,None为默认值
        newpassword = request.GET.get("newpassword", None)  # 读取get数据,None为默认值

    print("修改密码接口参数:源密码" + oldpassword + "新密码" + newpassword)

    user = UserDAO.getUserInfoId(id)
    if (user):
        if (oldpassword==user.password):
            user.password=newpassword
            UserDAO.updateUserPwd(user)
            result["message"]= "修改密码成功not "
            result["respcode"]= ResultCode.SUCCESS
            result["data"]= ResultCode.SUCCESS
            result["errorcode"]= ""
        else:
            result["message"]= "旧密码错误"
            result["respcode"]= ResultCode.FAIL
            result["data"]=""
            result["errorcode"]= ResultCode.OLDPWDFAIL

    else:
        result["message"]= "用户不存在"
        result["respcode"]= ResultCode.FAIL
        result["data"]= ""
        result["errorcode"]= ResultCode.UNUSEREXIST


    return result
Exemplo n.º 14
0
    def onRegister(self, connection, decoded_request):
        if ('username' not in decoded_request):
            raise InvalidRequestError("key 'username' not found.")
        username = decoded_request['username']

        if ('password' not in decoded_request):
            raise InvalidRequestError("key 'password' not found.")
        password = decoded_request['password']

        dao = UserDAO.getInstance()
        if (dao.existUser(username)):
            raise RequestFailedError('Username already exists.')

        dao.addUser(username, password)
        response = {'code': Code.SUCCESS}
        connection.send(Protocol.makeMessageFromDict(response))
Exemplo n.º 15
0
def queryqunchat(request):
    #第一层的结果集
    result = {}
    allmessage_back = []

    if request.method == "POST":
        qunid = int(request.POST.get("qunid", None))  # 读取post数据,None为默认值
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        qunid = int(request.GET.get("qunid", None))  # 读取post数据,None为默认值
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    print("查询群聊接口参数:接收者ID" + receive_id + "page" + pageNo)

    #首先查询是否存在聊天关系
    chatuser1 = Chatuser()
    chatuser1.send_id = qunid
    chatuser1.receive_id = receive_id
    chatuser1.usertype = ResultCode.CHATUSER_TYPE_QUN
    chatuser1 = ChatuserDAO.querychatqunexist(chatuser1)
    if (chatuser1 == None):
        result["message"] = "暂无聊天信息"
        result["data"] = ""
        result["errorcode"] = ""
        result["respcode"] = ResultCode.FAIL
        print("不存在聊天关系")
        return result

    #设置聊天关系为已读
    #获取聊天数目
    page = PageForId()
    page.pageNo = pageNo
    page.receive_id = receive_id
    page.send_id = qunid

    totalPage = 0
    try:
        page.abid = chatuser1.abid
        totalPage = Chat_MessageDAO.querysixinnumwithhe(
            chatuser1.abid)  #查询Aid_Bid
    except Exception as e1:
        # TODO Auto-generated catch block
        print(e1)

    page.totalPage = totalPage
    page.pageSize = 20
    page.start = 20 * (pageNo - 1)  #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    try:
        allMessage = Chat_MessageDAO.queryAllsixinwithhe(
            page.abid, page.start, page.pageSize)  #通过abid查询
        if (len(allMessage) > 0):
            #修改聊天用户的状态   在群聊中
            page.state = ResultCode.CHATUSER_OLD
            ChatuserDAO.updatachatuserstateforuser(page)
            qun = QunDAO.getqunInfoqunid(qunid)
            for message in allMessage:
                message_back = fun.chatmessage2back(message)
                #获取消息发送者信息
                senduser = fun.user2else_back(
                    UserDAO.getUserInfoId(message_back.send_id))
                message_back.send_user = senduser
                message_back.qun = qun

                allmessage_back.add(message_back)

        result["message"] = "查询成功"
        result["data"] = allmessage_back
        result["errorcode"] = ""
        result["respcode"] = ResultCode.SUCCESS

    except Exception as e:
        print(e)
        result["message"] = "查询失败"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
        print("查询失败")

    return result
Exemplo n.º 16
0
def queryAllsixinwithhe(request):
    #第一层的结果集
    result = {}
    allmessage_back = []
    if request.method == "POST":
        send_id = int(request.POST.get("send_id", None))  # 读取post数据,None为默认值
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        send_id = int(request.POST.get("send_id", None))  # 读取post数据,None为默认值
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    print("查询和某人的所有私信接口参数:接收者ID" + receive_id + "发送者id" + send_id + "page" +
          pageNo)

    #首先查询是否存在聊天关系
    chatuser1 = Chatuser()
    chatuser1.send_id = send_id
    chatuser1.receive_id = receive_id
    chatuser1.usertype = ResultCode.CHATUSER_TYPE_RECEIVE
    chatuser1 = ChatuserDAO.querychatuserexist(chatuser1)
    if (chatuser1 == None):
        chatuser1 = Chatuser()
        chatuser1.send_id = send_id
        chatuser1.receive_id = receive_id
        chatuser1.usertype = ResultCode.CHATUSER_TYPE_SEND
        chatuser1 = ChatuserDAO.querychatuserexist(chatuser1)
        if (chatuser1 == None):
            result["message"] = "不存在聊天关系"
            result["data"] = allmessage_back
            result["errorcode"] = ""
            result["respcode"] = ResultCode.SUCCESS
            print("不存在聊天关系")
            return result

    #设置聊天关系为已读
#获取聊天数目
        page = PageForId()
    page.pageNo = pageNo
    page.receive_id = receive_id
    page.send_id = send_id

    totalPage = 0
    try:
        page.abid = chatuser1.abid
        totalPage = Chat_MessageDAO.querysixinnumwithhe(chatuser1.abid)
    #查询Aid_Bid
    except Exception as e:
        print(e)

        page.totalPage = totalPage
        page.pageSize = 10
        page.start = 10 * (pageNo - 1)  #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
        print("共有聊天记录" + totalPage + "abid:" + page.abid)
    try:
        allMessage = Chat_MessageDAO.queryAllsixinwithhe(
            page.abid, page.start, page.pageSize)  #通过abid查询
        if (allMessage != None and len(allMessage) > 0):
            page.state = ResultCode.CHATUSER_OLD
            ChatuserDAO.updatachatuserstateforuser(chatuser1)  #修改聊天用户的状态
            senduser = fun.user2else_back(UserDAO.getUserInfoId(send_id))
            receiveuser = fun.user2else_back(UserDAO.getUserInfoId(receive_id))
            for message in allMessage:
                print("查询聊天记录" + message.content)
                message_back = fun.chatmessage2back(message)
                if (message_back.send_id == send_id):
                    message_back.send_user = senduser
                    message_back.receive_user = receiveuser
                else:
                    message_back.send_user = receiveuser
                    message_back.receive_user = senduser

                allmessage_back.add(message_back)

        result["message"] = "查询成功"
        result["data"] = allmessage_back
        result["errorcode"] = ""
        result["respcode"] = ResultCode.SUCCESS

    except Exception as e:
        print(e)
        result["message"] = "查询失败"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
        print("查询失败")

    return result
Exemplo n.º 17
0
    def __init__(self, parent=None, cameraPort=0, rfidPort=None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)

        '''
              Initialize hardware input
        '''
        self.cameraScanner = CameraScanner(self, 1280, 720, 10, cameraPort)
        self.RFIDScanner = RFIDScanner(self, rfidPort)


        '''
                Initialize Data access object

        '''
        self.userDAO = UserDAO.UserDAO(self)
        self.bookDAO = BookDAO.BookDAO(self)
        self.notificationDAO = NotificationDAO.NotificationDAO(self)

        '''
            Initialize camera viewer (widget)
        '''
        self.window_width_idScan = self.groupBox_scanner.geometry().width()
        self.window_height_idScan = self.groupBox_scanner.geometry().height()
        self.camViewWidget_ID = CameraViewerWidget(self.camViewWidget_ID)
        self.idFrameUpdater = QtCore.QTimer(self)
        self.idFrameUpdater.timeout.connect(self.update_id_frame)
        self.idFrameUpdater.start(1)

        self.window_width_bookScan = self.tab_camera.geometry().width()
        self.window_height_bookScan = self.tab_camera.geometry().height()
        self.camViewWidget_Book = CameraViewerWidget(self.camViewWidget_Book)
        self.bookFrameUpdater = QtCore.QTimer(self)
        self.bookFrameUpdater.timeout.connect(self.update_book_frame)
        self.bookFrameUpdater.start(1)

        '''
            Setup UI components
        '''
        self.onlyInt = QtGui.QIntValidator()
        self.lineEdit_userID.setValidator(self.onlyInt)
        self.lineEdit_bookID.setValidator(self.onlyInt)

        self.button_login_with_id.clicked.connect(self.login_clicked)
        self.pushButton_addBook.clicked.connect(lambda: self.queryBookInfo(self.lineEdit_bookID.text()))
        self.pushButton_clear.clicked.connect(self.clearBook)
        self.label_IDerror.hide()
        self.label_borrow_error.hide()
        self.pushButton_back_to_p1.clicked.connect(self.onButtonToPage1)
        self.pushButton_confirm_borrow.clicked.connect(self.onBorrowBookButtonClicked)

        line_connect_icon = QtGui.QIcon('res/line_connect.png')
        self.pushButton_line_connect.setIcon(line_connect_icon)
        self.pushButton_line_connect.setIconSize(QtCore.QSize(200, 80))
        self.pushButton_line_connect.clicked.connect(self.onLineConnectButtonClicked)
        self.pushButton_line_connect_back.clicked.connect(self.init_page_2)

        self.webView = QtWebEngineWidgets.QWebEngineView(self.webView)

        '''
            Initialize variables
        '''
        self.currentUser = None              # Current logged in user
        self.scanMode = 1                    # scanner scan mode (id or books)
        self.bookBasket = []                 # Book basket for borrow



        self.initKeypad()
        self.init_page_1()
Exemplo n.º 18
0
def deldealinfomore(request):
    result = {}
    if request.method == "POST":
        deal = request.POST.get("deal", 0)  # 读取post数据,None为默认值
        userid_source = request.POST.get("userid_source",
                                         0)  # 读取post数据,None为默认值
        diaryid_source = request.POST.get("diaryid_source",
                                          0)  # 读取post数据,None为默认值
        qunid_source = request.POST.get("qunid_source", 0)  # 读取post数据,None为默认值
        userid_destination = request.POST.get("userid_destination",
                                              0)  # 读取post数据,None为默认值
        diaryid_destination = request.POST.get("diaryid_destination",
                                               0)  # 读取post数据,None为默认值
        qunid_destination = request.POST.get("qunid_destination",
                                             0)  # 读取post数据,None为默认值
    if request.method == "GET":
        deal = request.GET.get("deal", 0)  # 读取get数据,None为默认值
        userid_source = request.GET.get("userid_source", 0)  # 读取get数据,None为默认值
        diaryid_source = request.GET.get("diaryid_source",
                                         0)  # 读取get数据,None为默认值
        qunid_source = request.GET.get("qunid_source", 0)  # 读取get数据,None为默认值
        userid_destination = request.GET.get("userid_destination",
                                             0)  # 读取get数据,None为默认值
        diaryid_destination = request.GET.get("diaryid_destination",
                                              0)  # 读取get数据,None为默认值
        qunid_destination = request.GET.get("qunid_destination",
                                            0)  # 读取get数据,None为默认值

    print("删除更多操作接口参数:deal" + deal)
    more = More()
    more.deal = deal
    more.userid_source = userid_source
    more.userid_destination = userid_destination
    more.diaryid_source = diaryid_source
    more.diaryid_destination = diaryid_destination
    more.qunid_source = qunid_source
    more.qunid_destination = qunid_destination
    more = MoreDAO.selectmoreInfomore(more)

    if (more):
        MoreDAO.deldealInfoid(more.id)
        result["data"] = ""
        result["respcode"] = ResultCode.SUCCESS
        result["errorcode"] = ResultCode.SUCCESS
        result["message"] = "删除处理成功"

        #如果是日志点赞则添加到日志属性中去
        if (more.diaryid_destination):
            diary = DiaryDAO.selectDiary(more.diaryid_destination)
            if (diary):
                if (more.deal == ResultCode.DIARY_ZAN):
                    diary.zannum = diary.zannum - 1
                    DiaryDAO.updatediary(diary)
                elif (more.deal == ResultCode.DIARY_SHOUCANG):
                    diary.shoucangnum = diary.shoucangnum - 1
                    DiaryDAO.updatediary(diary)

                elif (more.deal == ResultCode.DIARY_TUIJIAN):
                    diary.tuijiannum = diary.tuijiannum - 1
                    DiaryDAO.updatediary(diary)

        #如果是群组点赞  则添加到群属性中
        elif (more.qunid_destination()):
            qun = QunDAO.getqunInfoqunid(more.qunid_destination)
            if (qun):
                if (more.deal == ResultCode.QUN_ZAN):
                    qun.zannum = qun.zannum - 1
                    QunDAO.updatequnInfoqun(qun)

                elif (more.deal == ResultCode.QUN_SHOUCANG):
                    qun.shoucangnum = qun.shoucangnum - 1
                    QunDAO.updatequnInfoqun(qun)
                elif (more.deal == ResultCode.QUN_TUIJIAN):
                    qun.tuijiannum = qun.tuijiannum - 1
                    QunDAO.updatequnInfoqun(qun)

        #如果是用户点赞  则添加到用户属性中
        elif (more.userid_destination):
            user = UserDAO.getUserInfoId(more.userid_destination)
            if (user):
                if (more.deal == ResultCode.USER_ZAN):
                    user.zannum = user.zannum - 1
                    UserDAO.updateUserInfo(user)
                if (more.deal == ResultCode.USER_SHOUCANG):
                    user.shoucangnum = user.shoucangnum - 1
                    UserDAO.updateUserInfo(user)
                if (more.deal == ResultCode.USER_TUIJIAN):
                    user.tuijiannum = user.tuijiannum - 1
                    UserDAO.updateUserInfo(user)

    return result
Exemplo n.º 19
0
def deldeal(request):

    result = {}
    if request.method == "POST":
        id = request.POST.get("id", None)  # 读取post数据,None为默认值
    if request.method == "GET":
        id = request.GET.get("id", None)  # 读取get数据,None为默认值

    print("删除更多操作接口参数:操作id" + id)
    more = MoreDAO.selectdealInfoid(id)
    try:
        MoreDAO.deldealInfoid(id)
        result["data"] = ""
        result["respcode"] = ResultCode.SUCCESS
        result["errorcode"] = ResultCode.SUCCESS
        result["message"] = "删除处理成功"

        #如果是日志点赞则添加到日志属性中去
        if (more.diaryid_destination):
            diary = DiaryDAO.selectDiary(more.diaryid_destination)
            if (diary):
                if (more.deal == ResultCode.DIARY_ZAN):
                    diary.zannum = diary.zannum - 1
                    DiaryDAO.updatediary(diary)
                elif (more.deal == ResultCode.DIARY_SHOUCANG):
                    diary.shoucangnum = diary.shoucangnum - 1
                    DiaryDAO.updatediary(diary)

                elif (more.deal == ResultCode.DIARY_TUIJIAN):
                    diary.tuijiannum = diary.tuijiannum - 1
                    DiaryDAO.updatediary(diary)
        #如果是群组点赞  则添加到群属性中
        elif (more.qunid_destination):
            qun = QunDAO.getqunInfoqunid(more.qunid_destination)
            if (qun):
                if (more.deal == ResultCode.QUN_ZAN):
                    qun.zannum = qun.zannum - 1
                    QunDAO.updatequnInfoqun(qun)
                elif (more.deal == ResultCode.QUN_SHOUCANG):
                    qun.shoucangnum = qun.shoucangnum - 1
                    QunDAO.updatequnInfoqun(qun)
                elif (more.deal == ResultCode.QUN_TUIJIAN):
                    qun.tuijiannum = qun.tuijiannum - 1
                    QunDAO.updatequnInfoqun(qun)

        #如果是用户点赞  则添加到用户属性中
        elif (more.userid_destination):
            user = UserDAO.getUserInfoId(more.userid_destination)
            if (user):
                if (more.deal == ResultCode.USER_ZAN):
                    user.zannum = user.zannum - 1
                    UserDAO.updateUserInfo(user)
                if (more.deal == ResultCode.USER_SHOUCANG):
                    user.shoucangnum = user.shoucangnum - 1
                    UserDAO.updateUserInfo(user)
                if (more.deal == ResultCode.USER_TUIJIAN):
                    user.tuijiannum = user.tuijiannum - 1
                    UserDAO.updateUserInfo(user)

    except Exception as e:
        result["data"] = ""
        result["respcode"] = ResultCode.FAIL
        result["errorcode"] = ResultCode.FAIL
        result["message"] = "删除处理成功"
    return result
Exemplo n.º 20
0
def adddeal(request):

    result = {}

    if request.method == "POST":
        deal = request.POST.get("deal", None)  # 读取post数据,None为默认值
        userid_source = request.POST.get("userid_source",
                                         0)  # 读取post数据,None为默认值
        diaryid_source = request.POST.get("diaryid_source",
                                          0)  # 读取post数据,None为默认值
        qunid_source = request.POST.get("qunid_source", 0)  # 读取post数据,None为默认值
        userid_destination = request.POST.get("userid_destination",
                                              0)  # 读取post数据,None为默认值
        diaryid_destination = request.POST.get("diaryid_destination",
                                               0)  # 读取post数据,None为默认值
        qunid_destination = request.POST.get("qunid_destination",
                                             0)  # 读取post数据,None为默认值
    if request.method == "GET":
        deal = request.GET.get("deal", None)  # 读取get数据,None为默认值
        userid_source = request.GET.get("userid_source", 0)  # 读取get数据,None为默认值
        diaryid_source = request.GET.get("diaryid_source",
                                         0)  # 读取get数据,None为默认值
        qunid_source = request.GET.get("qunid_source", 0)  # 读取get数据,None为默认值
        userid_destination = request.GET.get("userid_destination",
                                             0)  # 读取get数据,None为默认值
        diaryid_destination = request.GET.get("diaryid_destination",
                                              0)  # 读取get数据,None为默认值
        qunid_destination = request.GET.get("qunid_destination",
                                            0)  # 读取get数据,None为默认值

    print("添加更多操作接口参数:操作类型" + deal + "源用户id" + userid_source + "源日志id:" +
          diaryid_source + "目的用户id:" + userid_destination + "目的日志id:" +
          diaryid_destination + "源群id:" + qunid_source + "目的群id:" +
          qunid_destination)

    if (userid_source == userid_destination):
        result["data"] = ""
        result["respcode"] = ResultCode.FAIL
        result["errorcode"] = ResultCode.FAIL
        result["message"] = "添加处理失败"
        return result

    more = More()
    more.deal = deal
    more.userid_source = userid_source
    more.userid_destination = userid_destination
    more.diaryid_source = diaryid_source
    more.diaryid_destination = diaryid_destination
    more.qunid_source = qunid_source
    more.qunid_destination = qunid_destination
    more1 = MoreDAO.selectmoreInfomore(more)
    if (more1):
        result["data"] = more1
        result["respcode"] = ResultCode.SUCCESS
        result["errorcode"] = ResultCode.SUCCESS
        result["message"] = "添加处理成功"

    else:
        try:
            MoreDAO.adddeal(more)
            more = MoreDAO.selectmoreInfomore(more)
            result["data"] = more
            result["respcode"] = ResultCode.SUCCESS
            result["errorcode"] = ResultCode.SUCCESS
            result["message"] = "添加处理成功"

            #如果是日志点赞则添加到日志属性中去
            if (diaryid_destination != 0):
                diary = DiaryDAO.selectDiary(diaryid_destination)
                if (diary):
                    if (deal == ResultCode.DIARY_ZAN):
                        diary.zannum = diary.zannum + 1
                        DiaryDAO.updatediary(diary)
                    elif (deal == ResultCode.DIARY_SHOUCANG):
                        diary.shoucangnum = diary.shoucangnum + 1
                        DiaryDAO.updatediary(diary)
                    elif (deal == ResultCode.DIARY_TUIJIAN):
                        diary.tuijiannum = diary.tuijiannum + 1
                        DiaryDAO.updatediary(diary)
            #如果是群组点赞  则添加到群属性中
            elif (qunid_destination != 0):
                qun = QunDAO.getqunInfoqunid(qunid_destination)
                if (qun):
                    if (deal == ResultCode.QUN_ZAN):
                        qun.zannum = qun.zannum + 1
                        QunDAO.updatequnInfoqun(qun)

                    elif (deal == ResultCode.QUN_SHOUCANG):
                        qun.shoucangnum = qun.shoucangnum + 1
                        QunDAO.updatequnInfoqun(qun)
                    elif (deal == ResultCode.QUN_TUIJIAN):
                        qun.tuijiannum = qun.tuijiannum + 1
                        QunDAO.updatequnInfoqun(qun)

            #如果是用户点赞  则添加到用户属性中
            elif (userid_destination != 0):
                user = UserDAO.getUserInfoId(userid_destination)
                if (user):
                    if (deal == ResultCode.USER_ZAN):
                        user.zannum = user.zannum + 1
                        UserDAO.updateUserInfo(user)
                    if (deal == ResultCode.USER_SHOUCANG):
                        user.shoucangnum = user.shoucangnum + 1
                        UserDAO.updateUserInfo(user)
                    if (deal == ResultCode.USER_TUIJIAN):
                        user.tuijiannum = user.tuijiannum + 1
                        UserDAO.updateUserInfo(user)

        except Exception as e:
            result["data"] = ""
            result["respcode"] = ResultCode.FAIL
            result["errorcode"] = ResultCode.FAIL
            result["message"] = "添加处理失败"

    return result
Exemplo n.º 21
0
class Server:
    def __init__(self):
        self.database_connection = mysql.connect(
            host='localhost',
            user='******',
            password='',
            database='chitchatdb'
        )
        self.cursor = self.database_connection.cursor()
        self.userDAO = UserDAO(self.database_connection)
        self.messageDAO = MessageDAO(self.database_connection)
        self.host = server_host.host
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.bind(self.host)
        self.socket.listen(5)
        self.connected_clients = {}
        self.lock = Lock()
        self.messages_queue = Queue()

    def run(self):
        while True:
            print('Waiting for connection')
            client_connection, client_address = self.socket.accept()

            print('Client at {} connected'.format(client_address))
            Thread(target=self.handle_connection, args=(client_connection,)).start()

    def handle_connection(self, client_connection: socket.socket):
        thread_name = current_thread().getName()
        print('\t{}: Started'.format(thread_name))

        try:
            local_data = local()
            while True:
                data = bytes()
                received = bytes()

                while True:
                    received += client_connection.recv(4096)
                    if not received:
                        break
                    elif len(received) < 4096:
                        data += received
                        break
                    else:
                        data += received

                request = json.loads(data.decode())

                if request['request'] == 'login' or request['request'] == 'register':
                    user_data = request['user']
                    user = User(user_data['username'], user_data['password'])

                    if request['request'] == 'login':
                        print('\t{}: Checking if user is registered'.format(thread_name))
                        user.id = self.userDAO.get_user_id(user)

                        if user.id == 0:
                            print('\t{}: User is not registered'.format(thread_name))
                            response = {'info': 'Invalid username or password'}
                        else:
                            print('\t{}: User logged in'.format(thread_name))
                            local_data.user = user
                            self.connected_clients[local_data.user.id] = client_connection
                            response = {'info': 'Logged'}
                    else:
                        print('\t{}: Trying to add user to the database'.format(thread_name))
                        user = self.userDAO.insert(user)

                        if user is None:
                            print('\t{}: User already exists'.format(thread_name))
                            response = {'info': 'User already exists'}
                        else:
                            print('\t{}: User registered'.format(thread_name))
                            user.id = self.userDAO.get_id_by_username(user.username)
                            local_data.user = user
                            response = {'info': 'Successfully registered'}

                    client_connection.sendall(json.dumps(response).encode())

                    if response['info'] == 'Invalid username or password' \
                       or response['info'] == 'User already exists':
                        break
                elif request['request'] == 'search_for':
                    print('\t{}: Searching for user'.format(thread_name))
                    other_id = self.userDAO.get_id_by_username(request['username'])

                    if other_id == 0:
                        response = {'search_result': {'info': '{} does not exist'.format(request['username'])}}
                        client_connection.sendall(json.dumps(response).encode())
                    else:
                        json_user = self.userDAO.get_user_by_id(other_id)
                        local_data.other_client = User(json_user['username'], json_user['password'], _id=other_id)
                        response = {'search_result': {'info': '{} found'.format(request['username'])}}
                        client_connection.sendall(json.dumps(response).encode())
                elif request['request'] == 'prefetch_messages':
                    print('\t{}: Fetching user messages'.format(thread_name))
                    messages = self.messageDAO.prefetch(local_data.user.id, local_data.other_client.id, 20)

                    for message in messages:
                        if message.sender_id == local_data.user.id:
                            sender_username = local_data.user.username
                        else:
                            sender_username = local_data.other_client.username

                        json_message = {
                            'fetched_message': {
                                'sender': sender_username,
                                'content': message.content
                            }
                        }
                        client_connection.sendall(json.dumps(json_message).encode())
                        time.sleep(0.08)
                elif request['request'] == 'send_message':
                    json_message = request['message']
                    message = Message(local_data.user.id,
                                      local_data.other_client.id,
                                      content=json_message['content'],
                                      send_time=json_message['send_time'],
                                      status=1)
                    self.messageDAO.insert(message)
                    message = {
                        'message': {
                            'sender': local_data.user.username,
                            'content': json_message['content']
                        }
                    }
                    client_connection.sendall(json.dumps(message).encode())

                    if local_data.other_client.id in self.connected_clients.keys():
                        connection = self.connected_clients[local_data.other_client.id]
                        connection.sendall(json.dumps(message).encode())

        except ConnectionError or Exception:
            print('\t{}: Some error happened, connection will be closed'.format(thread_name))
            client_connection.close()

            for _id, connection in self.connected_clients.items():
                if connection == client_connection:
                    with self.lock:
                        self.connected_clients.pop(_id)
                        break

        finally:
            print('\t{}: Connection closed'.format(thread_name))
            client_connection.close()
Exemplo n.º 22
0
def userLogin(request):
    result = {}
    user = User()
    if request.method == "POST":
        phone = request.POST.get("phone", None)  # 读取get数据,None为默认值
        password = request.POST.get("password", None)  # 读取get数据,None为默认值
        identity = request.POST.get("identity", None)  # 读取get数据,None为默认值
        school = request.POST.get("school", None)  # 读取get数据,None为默认值
        qunidstr = request.POST.get("qunid", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        phone = request.GET.get("phone", None)  # 读取get数据,None为默认值
        password = request.GET.get("password", None)  # 读取get数据,None为默认值
        identity = request.GET.get("identity", None)  # 读取get数据,None为默认值
        school = request.GET.get("school", None)  # 读取get数据,None为默认值
        qunidstr = request.GET.get("qunid", None)  # 读取get数据,None为默认值



    print("用户登录接口参数:电话" + phone + "密码" + password)
    user.phone=phone
    user.password=password

    user = UserDAO.userLogin(user)
    if (user):
        if(identity):
           user.identity=identity
        if(school):
           user.school=school
        UserDAO.updateUserInfo(user)
        #如果登陆时需要加入群组,这里加入群组
        if(qunidstr):
            try:
                qunid = int(qunidstr)
                qun=QunDAO.getqunInfoqunid(qunid)
                userqun = Userqun()
                userqun.userid=user.id
                userqun.qunid=qunid
                userquntemp = UserqunDAO.getuserqunInfouserqun(userqun)
                if(not userquntemp):
                    if(qun.quntype==ResultCode.QUN_USER or qun.quntype==ResultCode.QUN_USER_DIARY or qun.quntype==ResultCode.QUN_USER_DIARY_NOT_USER):
                       userqun.userstate(ResultCode.USERQUN_NOT)

                    else:
                        userqun.userstate(ResultCode.USERQUN_YUAN)

                    UserqunDAO.adduserqun(userqun)

                    #添加群聊关系
                    chatuser =Chatuser()
                    chatuser.send_id=qunid
                    chatuser.receive_id=user.id
                    chatuser.usertype=ResultCode.CHATUSER_TYPE_QUN
                    chatuser.state=ResultCode.CHATUSER_HIDE
                    chatuser.abid=str(qunid)
                    chatuser.content=""
                    chatuser.time=TimeUtil.getCurrentTime()
                    chatuser.date=TimeUtil.getCurrentDate()
                    ChatuserDAO.addchatuser(chatuser)

            except Exception as e:
                print(e)


        user_me_back = user2meBack(user)
        appBean=AppVersionDAO.queryVersionById(1)
        result["data"]= user_me_back
        result["respcode"]= ResultCode.SUCCESS
        result["errorcode"]= ""
        result["message"]=appBean  #将版本信息一并返回

    else:
            result["data"]=""
            result["respcode"]= ResultCode.FAIL
            result["errorcode"]=ResultCode.FAIL
            result["message"]="账号或密码错误"

    return result
Exemplo n.º 23
0
def userRegist(request):
    user = User()
    result = {}
    if request.method == "POST":
        phone = request.POST.get("phone", None)  # 读取post数据,None为默认值
        qunidstr = request.POST.get("qunid", None)  # 读取get数据,None为默认值
        password = request.POST.get("password", None)  # 读取post数据,None为默认值
        name = request.POST.get("name", None)  # 读取post数据,None为默认值
        identity = request.POST.get("identity", None)  # 读取post数据,None为默认值
        email = request.POST.get("email", None)  # 读取post数据,None为默认值
        address = request.POST.get("address", None)  # 读取post数据,None为默认值
        school = request.POST.get("school", None)  # 读取post数据,None为默认值
        usertype = request.POST.get("usertype", 0)  # 读取post数据,None为默认值
        usericon = request.POST.get("usericon", None)  # 读取get数据,None为默认值
        wechat = request.POST.get("wechat", None)  # 读取get数据,None为默认值
        alipay = request.POST.get("alipay", None)  # 读取get数据,None为默认值
        parameter1 = request.POST.get("parameter1", None)  # 读取get数据,None为默认值
        parameter2 = request.POST.get("parameter2", None)  # 读取get数据,None为默认值
        parameter3 = request.POST.get("parameter3", None)  # 读取get数据,None为默认值
        parameter4 = request.POST.get("parameter4", None)  # 读取get数据,None为默认值
        parameter5 = request.POST.get("parameter5", None)  # 读取get数据,None为默认值
        parameter6 = request.POST.get("parameter6", None)  # 读取get数据,None为默认值
        parameter7 = request.POST.get("parameter7", None)  # 读取get数据,None为默认值
        parameter8 = request.POST.get("parameter8", None)  # 读取get数据,None为默认值
        parameter9 = request.POST.get("parameter9", None)  # 读取get数据,None为默认值
        parameter10 = request.POST.get("parameter10", None)  # 读取get数据,None为默认值
        parameter11 = request.POST.get("parameter11", None)  # 读取get数据,None为默认值
        parameter12 = request.POST.get("parameter12", None)  # 读取get数据,None为默认值
        parameter13 = request.POST.get("parameter13", None)  # 读取get数据,None为默认值
        parameter14 = request.POST.get("parameter14", None)  # 读取get数据,None为默认值
        parameter15 = request.POST.get("parameter15", None)  # 读取get数据,None为默认值
        parameter16 = request.POST.get("parameter16", None)  # 读取get数据,None为默认值
        parameter17 = request.POST.get("parameter17", None)  # 读取get数据,None为默认值
        parameter18 = request.POST.get("parameter18", None)  # 读取get数据,None为默认值
        parameter19 = request.POST.get("parameter19", None)  # 读取get数据,None为默认值
        parameter20 = request.POST.get("parameter20", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        phone = request.GET.get("phone", None)  # 读取get数据,None为默认值
        qunidstr = request.GET.get("qunid", None)  # 读取get数据,None为默认值
        password = request.GET.get("password", None)  # 读取get数据,None为默认值
        name = request.GET.get("name", None)  # 读取get数据,None为默认值
        identity = request.GET.get("identity", None)  # 读取get数据,None为默认值
        email = request.GET.get("email", None)  # 读取get数据,None为默认值
        address = request.GET.get("address", None)  # 读取get数据,None为默认值
        school = request.GET.get("school", None)  # 读取get数据,None为默认值
        usertype = request.GET.get("usertype", 0)  # 读取post数据,None为默认值
        usericon = request.GET.get("usericon", None)  # 读取get数据,None为默认值
        wechat = request.GET.get("wechat", None)  # 读取get数据,None为默认值
        alipay = request.GET.get("alipay", None)  # 读取get数据,None为默认值
        parameter1 = request.GET.get("parameter1", None)  # 读取get数据,None为默认值
        parameter2 = request.GET.get("parameter2", None)  # 读取get数据,None为默认值
        parameter3 = request.GET.get("parameter3", None)  # 读取get数据,None为默认值
        parameter4 = request.GET.get("parameter4", None)  # 读取get数据,None为默认值
        parameter5 = request.GET.get("parameter5", None)  # 读取get数据,None为默认值
        parameter6 = request.GET.get("parameter6", None)  # 读取get数据,None为默认值
        parameter7 = request.GET.get("parameter7", None)  # 读取get数据,None为默认值
        parameter8 = request.GET.get("parameter8", None)  # 读取get数据,None为默认值
        parameter9 = request.GET.get("parameter9", None)  # 读取get数据,None为默认值
        parameter10 = request.GET.get("parameter10", None)  # 读取get数据,None为默认值
        parameter11 = request.GET.get("parameter11", None)  # 读取get数据,None为默认值
        parameter12 = request.GET.get("parameter12", None)  # 读取get数据,None为默认值
        parameter13 = request.GET.get("parameter13", None)  # 读取get数据,None为默认值
        parameter14 = request.GET.get("parameter14", None)  # 读取get数据,None为默认值
        parameter15 = request.GET.get("parameter15", None)  # 读取get数据,None为默认值
        parameter16 = request.GET.get("parameter16", None)  # 读取get数据,None为默认值
        parameter17 = request.GET.get("parameter17", None)  # 读取get数据,None为默认值
        parameter18 = request.GET.get("parameter18", None)  # 读取get数据,None为默认值
        parameter19 = request.GET.get("parameter19", None)  # 读取get数据,None为默认值
        parameter20 = request.GET.get("parameter20", None)  # 读取get数据,None为默认值


    print("注册用户接口参数:电话" + phone + "密码" + password + "名称:"+ name)
    if(not phone or not password):
        result["data"]= ""
        result["respcode"]= ResultCode.FAIL
        result["errorcode"]= ResultCode.FAIL
        result["message"]= "注册失败,电话密码不能为空not "
        print("注册失败,电话密码不能为空")
        return result

    #先查询手机号是否已经注册过了
    u = UserDAO.queryuserforphone(phone)
    if u:
        result["data"]= ResultCode.FAIL
        result["respcode"]= ResultCode.FAIL
        result["errorcode"]= ResultCode.USEREXIST
        result["message"]= "注册失败,用户已经存在not "
        print("注册失败用户存在")
    else:
        u1 = UserDAO.queryUserForidentity(identity)
        if u1:
            result["data"]= ResultCode.FAIL
            result["respcode"]= ResultCode.FAIL
            result["errorcode"]= ResultCode.USEREXIST
            result["message"]= "注册失败,该用户已经注册过一次not "
        else:
            user.usertype=usertype
            if(usertype==0):
                user.state=ResultCode.USERQUN_NOT    #客户从手机端注册,,默认为未审核
            if(usertype==1):
                user.state=ResultCode.USERQUN_QUNZHU    #代理商从pc端注册,默认为审核
            if(usericon):
                user.image=usericon
            user.email=email
            user.phone=phone
            user.password=password
            user.name=name
            user.address=address
            user.school=school
            user.identity=identity
            user.wechat=wechat
            user.alipay=alipay
            user.parameter1=parameter1
            user.parameter2=parameter2
            user.parameter3=parameter3
            user.parameter4=parameter4
            user.parameter5=parameter5
            user.parameter6=parameter6
            user.parameter7=parameter7
            user.parameter8=parameter8
            user.parameter9=parameter9
            user.parameter10=parameter10
            user.parameter11=parameter11
            user.parameter12=parameter12
            user.parameter13=parameter13
            user.parameter14=parameter14
            user.parameter15=parameter15
            user.parameter16=parameter16
            user.parameter17=parameter17
            user.parameter18=parameter18
            user.parameter19=parameter19
            user.parameter20=parameter20

            UserDAO.userRegist(user)   #注册函数  无返回值
            users = UserDAO.userLogin(user)   #同时登陆,返回数据,尤其是ID号
            #如果注册时需要加入群组,这里加入群组
            if(qunidstr):
                try:
                    qunid = int(qunidstr)
                    qun=QunDAO.getqunInfoqunid(qunid)
                    userqun = Userqun()
                    userqun.userid=users.id
                    userqun.qunid=qunid
                    userquntemp = UserqunDAO.getuserqunInfouserqun(userqun)
                    if(not userquntemp):
                        if(qun.quntype==ResultCode.QUN_USER or qun.quntype==ResultCode.QUN_USER_DIARY or qun.quntype==ResultCode.QUN_USER_DIARY_NOT_USER):
                           userqun.userstate=ResultCode.USERQUN_NOT
                        else:
                            userqun.userstate=ResultCode.USERQUN_YUAN
                        UserqunDAO.adduserqun(userqun)

                        #添加群聊关系
                        chatuser =Chatuser()
                        chatuser.send_id=qunid
                        chatuser.receive_id=users.id
                        chatuser.usertype=ResultCode.CHATUSER_TYPE_QUN
                        chatuser.state=ResultCode.CHATUSER_HIDE
                        chatuser.abid=str(qunid)
                        chatuser.content=""
                        chatuser.time=TimeUtil.getCurrentTime()
                        chatuser.date=TimeUtil.getCurrentDate()
                        ChatuserDAO.addchatuser(chatuser)
                except Exception as e:
                    print(e)
            userme= user2meBack(users)
            result["data"]= userme
            result["respcode"]= ResultCode.SUCCESS
            result["errorcode"]= ""
            result["message"]= "注册成功not "
            print("注册成功")

    return result
Exemplo n.º 24
0
def updateuserinf(request):
    result = {}
    user = User()
    if request.method == "POST":
        userid = request.POST.get("userid", None)  # 读取post数据,None为默认值
        phone = request.POST.get("phone", None)  # 读取post数据,None为默认值
        qunidstr = request.POST.get("qunid", None)  # 读取get数据,None为默认值
        password = request.POST.get("password", None)  # 读取post数据,None为默认值
        name = request.POST.get("name", None)  # 读取post数据,None为默认值
        identity = request.POST.get("identity", None)  # 读取post数据,None为默认值
        email = request.POST.get("email", None)  # 读取post数据,None为默认值
        address = request.POST.get("address", None)  # 读取post数据,None为默认值
        id_number = request.POST.get("id_number", None)  # 读取get数据,None为默认值
        push_userId = request.POST.get("push_userId", None)  # 读取get数据,None为默认值
        push_channelId = request.POST.get("push_channelId", None)  # 读取get数据,None为默认值
        school = request.POST.get("school", None)  # 读取post数据,None为默认值
        usertype = request.POST.get("usertype", 0)  # 读取post数据,None为默认值
        usericon = request.POST.get("usericon", None)  # 读取get数据,None为默认值
        wechat = request.POST.get("wechat", None)  # 读取get数据,None为默认值
        alipay = request.POST.get("alipay", None)  # 读取get数据,None为默认值
        parameter1 = request.POST.get("parameter1", None)  # 读取get数据,None为默认值
        parameter2 = request.POST.get("parameter2", None)  # 读取get数据,None为默认值
        parameter3 = request.POST.get("parameter3", None)  # 读取get数据,None为默认值
        parameter4 = request.POST.get("parameter4", None)  # 读取get数据,None为默认值
        parameter5 = request.POST.get("parameter5", None)  # 读取get数据,None为默认值
        parameter6 = request.POST.get("parameter6", None)  # 读取get数据,None为默认值
        parameter7 = request.POST.get("parameter7", None)  # 读取get数据,None为默认值
        parameter8 = request.POST.get("parameter8", None)  # 读取get数据,None为默认值
        parameter9 = request.POST.get("parameter9", None)  # 读取get数据,None为默认值
        parameter10 = request.POST.get("parameter10", None)  # 读取get数据,None为默认值
        parameter11 = request.POST.get("parameter11", None)  # 读取get数据,None为默认值
        parameter12 = request.POST.get("parameter12", None)  # 读取get数据,None为默认值
        parameter13 = request.POST.get("parameter13", None)  # 读取get数据,None为默认值
        parameter14 = request.POST.get("parameter14", None)  # 读取get数据,None为默认值
        parameter15 = request.POST.get("parameter15", None)  # 读取get数据,None为默认值
        parameter16 = request.POST.get("parameter16", None)  # 读取get数据,None为默认值
        parameter17 = request.POST.get("parameter17", None)  # 读取get数据,None为默认值
        parameter18 = request.POST.get("parameter18", None)  # 读取get数据,None为默认值
        parameter19 = request.POST.get("parameter19", None)  # 读取get数据,None为默认值
        parameter20 = request.POST.get("parameter20", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        userid = request.GET.get("userid", None)  # 读取get数据,None为默认值
        phone = request.GET.get("phone", None)  # 读取get数据,None为默认值
        qunidstr = request.GET.get("qunid", None)  # 读取get数据,None为默认值
        password = request.GET.get("password", None)  # 读取get数据,None为默认值
        name = request.GET.get("name", None)  # 读取get数据,None为默认值
        identity = request.GET.get("identity", None)  # 读取get数据,None为默认值
        email = request.GET.get("email", None)  # 读取get数据,None为默认值
        address = request.GET.get("address", None)  # 读取get数据,None为默认值
        id_number = request.GET.get("id_number", None)  # 读取get数据,None为默认值
        push_userId = request.GET.get("push_userId", None)  # 读取get数据,None为默认值
        push_channelId = request.GET.get("push_channelId", None)  # 读取get数据,None为默认值
        school = request.GET.get("school", None)  # 读取get数据,None为默认值
        usertype = request.GET.get("usertype", 0)  # 读取post数据,None为默认值
        usericon = request.GET.get("usericon", None)  # 读取get数据,None为默认值
        wechat = request.GET.get("wechat", None)  # 读取get数据,None为默认值
        alipay = request.GET.get("alipay", None)  # 读取get数据,None为默认值
        parameter1 = request.GET.get("parameter1", None)  # 读取get数据,None为默认值
        parameter2 = request.GET.get("parameter2", None)  # 读取get数据,None为默认值
        parameter3 = request.GET.get("parameter3", None)  # 读取get数据,None为默认值
        parameter4 = request.GET.get("parameter4", None)  # 读取get数据,None为默认值
        parameter5 = request.GET.get("parameter5", None)  # 读取get数据,None为默认值
        parameter6 = request.GET.get("parameter6", None)  # 读取get数据,None为默认值
        parameter7 = request.GET.get("parameter7", None)  # 读取get数据,None为默认值
        parameter8 = request.GET.get("parameter8", None)  # 读取get数据,None为默认值
        parameter9 = request.GET.get("parameter9", None)  # 读取get数据,None为默认值
        parameter10 = request.GET.get("parameter10", None)  # 读取get数据,None为默认值
        parameter11 = request.GET.get("parameter11", None)  # 读取get数据,None为默认值
        parameter12 = request.GET.get("parameter12", None)  # 读取get数据,None为默认值
        parameter13 = request.GET.get("parameter13", None)  # 读取get数据,None为默认值
        parameter14 = request.GET.get("parameter14", None)  # 读取get数据,None为默认值
        parameter15 = request.GET.get("parameter15", None)  # 读取get数据,None为默认值
        parameter16 = request.GET.get("parameter16", None)  # 读取get数据,None为默认值
        parameter17 = request.GET.get("parameter17", None)  # 读取get数据,None为默认值
        parameter18 = request.GET.get("parameter18", None)  # 读取get数据,None为默认值
        parameter19 = request.GET.get("parameter19", None)  # 读取get数据,None为默认值
        parameter20 = request.GET.get("parameter20", None)  # 读取get数据,None为默认值



    print("更新资料接口参数:" + "昵称:" + name + "手机号" + phone + "邮箱:" + email + "身份账号" + id_number + "地址:" + address)

    user = UserDAO.getUserInfoId(userid)
    if(not user):
        result["message"]= "修改用户资料失败"
        result["respcode"]= ResultCode.FAIL
        result["data"]="0"
        result["errorcode"]= ResultCode.FAIL
        return result

    user.id = userid
    if(name):  user.name=name
    if(qunidstr):  user.qunid=int(qunidstr)
    if(phone):  user.phone=phone
    if(email):  user.email=email
    if(id_number):  user.id_number=id_number
    if(address):  user.address=address
    if(school):  user.school=school
    if(wechat):  user.wechat=wechat
    if(alipay):  user.alipay=alipay
    if(usericon):  user.image=usericon
    if(push_userId):  user.push_userId=push_userId
    if(push_channelId):  user.push_channelId=push_channelId
    if(parameter1):  user.parameter1=parameter1
    if(parameter2):  user.parameter2=parameter2
    if(parameter3):  user.parameter3=parameter3
    if(parameter4):  user.parameter4=parameter4
    if(parameter5):  user.parameter5=parameter5
    if(parameter6):  user.parameter6=parameter6
    if(parameter7):  user.parameter7=parameter7
    if(parameter8):  user.parameter8=parameter8
    if(parameter9):  user.parameter9=parameter9
    if(parameter10):  user.parameter10=parameter10
    if(parameter11):  user.parameter11=parameter11
    if(parameter12):  user.parameter12=parameter12
    if(parameter13):  user.parameter13=parameter13
    if(parameter14):  user.parameter14=parameter14
    if(parameter15):  user.parameter15=parameter15
    if(parameter16):  user.parameter16=parameter16
    if(parameter17):  user.parameter17=parameter17
    if(parameter18):  user.parameter18=parameter18
    if(parameter19):  user.parameter19=parameter19
    if(parameter20):  user.parameter20=parameter20

    #升级为高级会员的条件,能创建群组
    if(id_number):
        pass
        #user.setState(ResultCode.USER_VIP)


    try:
        #先修该用户资料
        UserDAO.updateUserInfo(user)
        #根据用户id查询用户信息
        users_back = UserDAO.getUserInfoId(user.id)

        #将返回信息转变为本文信息类
        loginResult = user2meBack(users_back)

        result["data"]=  loginResult
        result["respcode"]=  ResultCode.SUCCESS
        result["errorcode"]=  ""
        result["message"]=  "修改用户资料成功"


    except Exception as e:
        print(e)
        result["message"]=  "修改用户资料失败"
        result["respcode"]=  ResultCode.FAIL
        result["data"]=  "0"
        result["errorcode"]=  ResultCode.FAIL

    return result