Exemple #1
0
 def getOAUserInfoList(self, info):
     startIndex = info['startIndex']
     pageCount = info['pageCount']
     try:
         query = db.session.query(UserInfo).filter(
             UserInfo.customizedCompanyID == CUSTOMIZEDCOMPANYID)
         allResult = query.order_by(desc(UserInfo.createTime)).offset(
             startIndex).limit(pageCount).all()
         dataList = [
             UserInfo.generateOAInfo(result) for result in allResult
         ]
         countQuery = db.session.query(func.count(UserInfo.userID)).filter(
             UserInfo.customizedCompanyID == CUSTOMIZEDCOMPANYID)
         count = countQuery.first()
         count = count[0]
         callBackInfo = {}
         callBackInfo['dataList'] = dataList
         callBackInfo['count'] = count
         return (True, callBackInfo)
     except Exception as e:
         print e
         traceback.print_exc()
         errorInfo = ErrorInfo['TENDER_02']
         errorInfo['detail'] = str(e)
         db.session.rollback()
         return (False, errorInfo)
Exemple #2
0
 def createOAUserInfo(self, info):
     userName = info['userName'].replace('\'', '\\\'').replace('\"', '\\\"')
     tel = info['tel'].replace('\'', '\\\'').replace('\"', '\\\"')
     password = info['password']
     userID = self.generateID(userName)
     info['userID'] = userID
     # info['customizedCompanyID'] = CUSTOMIZEDCOMPANYID
     info['tel'] = tel
     info['password'] = self.getMD5String(password)
     info['userType'] = info['userTypeID']
     info['jobNumber'] = info['jobNumber']
     info['createTime'] = datetime.now()
     try:
         # 获取boss的公司ID
         bossUserID = info['bossUserID']
         bossResult = db.session.query(UserInfo).filter(
             UserInfo.userID == bossUserID).first()
         if bossResult is None:
             return (False, ErrorInfo['TENDER_09'])
         customizedCompanyID = bossResult.customizedCompanyID
         info['customizedCompanyID'] = customizedCompanyID
         #判断是否已经存在该员工
         query = db.session.query(UserInfo).filter(UserInfo.tel == tel)
         result = query.first()
         if result is not None:
             # 如果用户已存在 判断用户的公司是否是0
             staffCustomizedCompanyID = result.customizedCompanyID
             if staffCustomizedCompanyID is not None and staffCustomizedCompanyID != 0:
                 return (False, ErrorInfo['TENDER_37'])
             query.update(
                 {
                     UserInfo.customizedCompanyID: customizedCompanyID,
                     UserInfo.userType: info['userType']
                 },
                 synchronize_session=False)
             # return (False, ErrorInfo['TENDER_07'])
         else:
             UserInfo.create(createInfo=info)
         db.session.commit()
         return (True, userID)
     except Exception as e:
         print e
         errorInfo = ErrorInfo['TENDER_02']
         errorInfo['detail'] = str(e)
         db.session.rollback()
         return (False, errorInfo)
Exemple #3
0
 def getUserInfoListByIDTuple(info):
     foreignIDTuple = info['foreignIDTuple']
     startIndex = info['startIndex']
     pageCount = info['pageCount']
     query = db.session.query(UserInfo).filter(
         UserInfo.userID.in_(foreignIDTuple)).order_by(
             desc(UserInfo.createTime)).offset(startIndex).limit(pageCount)
     allResult = query.all()
     userInfoList = [UserInfo.generate(result) for result in allResult]
     return filter(None, userInfoList)
Exemple #4
0
 def addUserInfo(self, userName, password, phone, email):
     userInfo = UserInfo()
     userInfo.user_name = userName
     userInfo.password = password
     userInfo.phone = phone
     userInfo.email = email
     return self.session.add(userInfo)
Exemple #5
0
    def getUserInfo(self, info):
        userID = info['userID']

        try:
            result = db.session.query(UserInfo).filter(
                UserInfo.userID == userID).first()
            if result is None:
                return (False, ErrorInfo['TENDER_23'])
            return (True, UserInfo.generate(userInfo=result))
        except Exception as e:
            print e
            errorInfo = ErrorInfo['TENDER_02']
            errorInfo['detail'] = str(e)
            db.session.rollback()
            return (False, errorInfo)
Exemple #6
0
 def __createUserInfo(self, info):
     tel = info['tel']
     password = info['password']
     userName = info['userName']
     companyName = info['companyName']
     jobPosition = info['jobPosition']
     # portrait = 'ladyPortrait.png'
     portrait = 'gentlemanPortrait.png'
     (status, reason) = self.checkSmsCode(info)
     if status is not True:
         return (False, reason)
     # 判断是否已经注册
     result = db.session.query(UserInfo).filter(UserInfo.tel == tel).first()
     if result is not None:
         errorInfo = ErrorInfo['TENDER_07']
         errorInfo['detail'] = None
         return (False, errorInfo)
     # 添加用户信息
     userID = self.generateID(tel)
     createTime = datetime.now()
     password = self.getMD5String(password)
     userInfo = UserInfo(userID=userID,
                         userName=userName,
                         password=password,
                         portraitPath=portrait,
                         tel=tel,
                         createTime=createTime,
                         companyName=companyName,
                         jobPosition=jobPosition)
     # 添加用户注册IP地址记录
     joinID = self.generateID(userID)
     ipAddress = info['ipAddress']
     userIP = UserIP(joinID=joinID,
                     userID=userID,
                     createTime=createTime,
                     ipAddress=ipAddress)
     try:
         db.session.add(userInfo)
         db.session.add(userIP)
         db.session.commit()
     except Exception as e:
         print e
         errorInfo = ErrorInfo['TENDER_02']
         errorInfo['detail'] = str(e)
         db.session.rollback()
         return (False, errorInfo)
     return (True, userID)
Exemple #7
0
 def getUserListBackground(self, jsonInfo):
     info = json.loads(jsonInfo)
     startIndex = info['startIndex']
     pageCount = info['pageCount']
     tokenID = info['tokenID']
     (status, userID) = self.isTokenValid(tokenID)
     if status is not True:
         errorInfo = ErrorInfo['TENDER_01']
         return (False, errorInfo)
     #获取tenderID列表
     query = db.session.query(UserInfo)
     info['query'] = query
     allResult = query.offset(startIndex).limit(pageCount).all()
     userInfoList = [UserInfo.generate(result) for result in allResult]
     countQuery = db.session.query(func.count(UserInfo.userID))
     count = countQuery.first()
     count = count[0]
     biddingResult = {}
     biddingResult['dataList'] = userInfoList
     biddingResult['count'] = count
     return (True, biddingResult)
Exemple #8
0
    def getTenderUserInfoList(self, info):
        userType = info['userType']
        try:
            query = db.session.query(UserInfo).filter(
                and_(
                    UserInfo.customizedCompanyID ==
                    info['customizedCompanyID'], UserInfo.userType >= userType,
                    UserInfo.userType != USER_TAG_BOSS))
            if info.has_key('startIndex'):
                startIndex = info['startIndex']
                pageCount = info['pageCount']
                query = query.order_by(desc(
                    UserInfo.createTime)).offset(startIndex).limit(pageCount)
            allResult = query.all()
            dataList = [
                UserInfo.generateOAInfo(result) for result in allResult
            ]

            countQuery = db.session.query(func.count(UserInfo.userID)).filter(
                and_(
                    UserInfo.customizedCompanyID ==
                    info['customizedCompanyID'], UserInfo.userType >= userType,
                    UserInfo.userType != USER_TAG_BOSS))
            count = countQuery.first()
            count = count[0]
            callBackInfo = {}
            callBackInfo['dataList'] = dataList
            callBackInfo['count'] = count
            return (True, callBackInfo)
        except Exception as e:
            print e
            traceback.print_exc()
            errorInfo = ErrorInfo['TENDER_02']
            errorInfo['detail'] = str(e)
            db.session.rollback()
            return (False, errorInfo)
Exemple #9
0
    def getUserInfoDetailBackground(self, jsonInfo):
        info = json.loads(jsonInfo)
        tokenID = info['tokenID']
        userID = info['userID']
        (status, myUserID) = self.isTokenValid(tokenID)
        if status is not True:
            errorInfo = ErrorInfo['TENDER_01']
            return (False, errorInfo)
        try:
            result = db.session.query(UserInfo).filter(
                UserInfo.userID == userID).first()

            if result is None:
                errorInfo = ErrorInfo['TENDER_09']
                return (False, errorInfo)

            userDetail = UserInfo.generate(userInfo=result)
        except Exception as e:
            print e
            errorInfo = ErrorInfo['TENDER_02']
            errorInfo['detail'] = str(e)
            db.session.rollback()
            return (False, errorInfo)
        return (True, userDetail)
Exemple #10
0
def createUser(info):
    wechatManager = WechatManager()
    util = Util()
    openID = info['fromUserName']
    (status, userInfo) = wechatManager.getUserInfo(openID=openID)
    if status is True:
        try:
            unionid = util.generateUnionID(userInfo['nickname'])
            query = db.session.query(UserInfo).filter(
                UserInfo.unionid == unionid)
            result = query.first()
            userID = util.generateID(openID)
            createInfo = {}
            createInfo['userID'] = userID
            createInfo['userName'] = userInfo['nickname']
            createInfo['tel'] = ''
            createInfo['createTime'] = datetime.now()
            createInfo['openid1'] = openID
            createInfo['unionid'] = unionid
            if result is not None:
                #第一种情况,用户已经登录过小程序
                appUserID = result.userID
                openid2 = result.openid2
                #(0)创建新的用户记录
                createInfo['openid2'] = openid2
                UserInfo.createWeChat(createInfo=createInfo)
                #(1)变更Tender中userID
                # 速度太慢,暂时不修改。 若要绑定手机号,一手机号ID为主
                # db.session.query(Tender).filter(
                #     Tender.userID == appUserID
                # ).update({Token.userID: userID}, synchronize_session=False)
                #(2)变更订阅表subscribedKey中userID
                db.session.query(SubscribedKey).filter(
                    SubscribedKey.userID == appUserID).update(
                        {SubscribedKey.userID: userID},
                        synchronize_session=False)
                #(3)变更关注表Favorite中的userID
                db.session.query(Favorite).filter(
                    Favorite.userID == appUserID).update(
                        {Favorite.userID: userID}, synchronize_session=False)
                #(4)变更tokenID表中的userID
                db.session.query(Token).filter(
                    Token.userID == appUserID).update(
                        {Token.userID: userID}, synchronize_session=False)
                # search key update
                db.session.query(SearchKey).filter(
                    and_(SearchKey.tag == SEARCH_KEY_TAG_SUBSCRIBE,
                         SearchKey.foreignID == appUserID)).update(
                             {SearchKey.foreignID: userID},
                             synchronize_session=False)
                #(5)删除userInfo中的appUserID
                db.session.query(UserInfo).filter(
                    UserInfo.userID == appUserID).delete(
                        synchronize_session=False)
            else:
                # 第二种情况,用户没有登录过小程序
                # createInfo = {}
                UserInfo.createPublic(createInfo=createInfo)
            db.session.commit()
        except Exception as e:
            return (False, str(e))
Exemple #11
0
    def doWechatAppLogin(self, info):
        appID = info['appID']
        appSecret = info['appSecret']
        columnOpenID = info['columnOpenID']
        stringOpenID = info['stringOpenID']

        #第一步:获取参数code, encryptedData, rawData, signature, iv
        code = info['code']
        encryptedData = info['encryptedData']
        rawData = info['rawData']
        rawData = str(rawData)
        signature = info['signature']
        iv = info['iv']
        #第二步: 获取唯一的openid, session_key
        url = 'https://api.weixin.qq.com/sns/jscode2session?appid=%s' \
              '&secret=%s&js_code=%s&grant_type=authorization_code' % (appID, appSecret, code)
        f = urllib.urlopen(url)
        ret = json.loads(f.read())
        #判断是否获取成功
        if (len(ret['session_key']) > 1 and len(ret['openid']) > 1):
            #第三步:根据openid, 生成tokenID, 将tokenID, session_key 存入到数据库中
            openID = ret['openid']
            sessionKey = ret['session_key']
            sessionKey = str(sessionKey)
            #第四步, 验证签名
            newSignature = hashlib.sha1(rawData + sessionKey).hexdigest()
            if (newSignature == signature):
                encryptedData = encryptedData.encode('utf-8')
                resultDict = self.decrypt(encryptedData, iv, sessionKey)
                tokenManager = TokenManager()
                unionid = self.generateUnionID(resultDict['nickName'])
                #查询是否存在已经创建的用户
                query = db.session.query(UserInfo).filter(
                    UserInfo.unionid == unionid)
                result = query.first()
                userQuery = query.filter(columnOpenID == openID)
                userResult = userQuery.first()
                if userResult is not None:
                    #第一种情况,用户已经登录过小程序
                    userID = userResult.userID
                else:

                    #第二种情况,用户登录过公众号, 小程序为第一次登录
                    userID = self.generateID(openID)
                    if result is not None:
                        updateInfo = {
                            UserInfo.userID: userID,
                            columnOpenID: openID
                        }
                        query.update(updateInfo, synchronize_session=False)
                    else:
                        #第三种情况,用户没有登录过公众号, 小程序为第一次登录
                        createInfo = {}
                        createInfo['userID'] = userID
                        createInfo['userName'] = resultDict['nickName']
                        createInfo['tel'] = ''
                        createInfo[stringOpenID] = openID
                        createInfo['createTime'] = datetime.now()
                        createInfo['unionid'] = self.generateUnionID(
                            resultDict['nickName'])
                        UserInfo.createApplet(createInfo=createInfo)
                db.session.commit()
                tokenID = tokenManager.createToken(userID=userID)
                return (True, tokenID)
        else:
            return (False, None)