Esempio n. 1
0
class Log(db.Document):
    # 管理员日志
    __tablename__ = 'log'
    meta = {
        'collection': __tablename__,
    }
    _id = db.IntField(primary_key=True)
    remark = db.StringField(default='', db_field='r')  # 备注
    date = db.IntField(default=common.getstamp(), db_field='d')  # 创建时间
    admin_id = db.IntField(default=0, db_field='a')  # 管理员ID

    @staticmethod
    def saveinfo(remark='', aid=0):
        Log(remark=remark,
            admin_id=aid == 0 and g.current_user._id or aid,
            _id=collection.get_next_id(Log.__tablename__),
            date=common.getstamp()).save()

    @staticmethod
    def getlist(aid=0, index=1, count=10):
        # 获取列表 0全部  -1官方  -2专家
        pageindex = (index - 1) * count
        if aid == 0:
            return Log.objects.order_by("-_id").skip(pageindex).limit(count)
        else:
            return Log.objects(
                admin_id=aid).order_by("-_id").skip(pageindex).limit(count)

    @staticmethod
    def getcount(aid=0):
        if aid == 0:
            return Log.objects.count()
        else:
            return Log.objects(admin_id=aid).count()
Esempio n. 2
0
 def update(pid,gid,did,action):
     #更新锁状态
     update = {}
     update['set__lockstate'] = action
     update['set__activetime'] = common.getstamp()
     update['set__state'] = 1
     return Lock.objects(park_id=pid,gateway_id=gid,device_id=did).update_one(**update)
Esempio n. 3
0
class ExpertApply(db.Document):
    __tablename__ = 'expertapply'
    meta = {
        'collection': __tablename__,
    }
    _id = db.IntField(primary_key=True)
    name = db.StringField(default='', max_length=32, db_field='n')  # 姓名
    phone = db.StringField(default='', max_length=20, db_field='p')  #手机号
    date = db.IntField(default=common.getstamp(), db_field='d')  # 创建时间

    @staticmethod
    def getlist(eid=0, index=1, pagesize=10):

        pageindex = (index - 1) * pagesize
        return ExpertApply.objects().order_by("-_id").skip(pageindex).limit(
            pagesize)

    @staticmethod
    def getcount(eid=0):
        return ExpertApply.objects.count()

    @staticmethod
    def isphone(phone):
        #.exclude('password_hash') 不包含字段
        return ExpertApply.objects(phone=phone)
Esempio n. 4
0
 def clearonline():
     #清理不在线设备
     logging.debug('已清理')
     nowtime = common.getstamp()
     update = {}
     #update['set__lockstate'] = action
     update['set__lasttime'] = nowtime
     update['set__state'] = 0
     #print str(nowtime-450)
     return Lock.objects(state=1,activetime__lt=nowtime-8).update(**update)
Esempio n. 5
0
    def saveinfo(self):
        self._id = collection.get_next_id(self.__tablename__)
        istrue = Expert.isphone(phone=self.phone)
        if istrue == 0:
            self.date = common.getstamp()
            self.save()

            return self._id
        else:
            return -1
Esempio n. 6
0
    def saveinfo(self):
        self._id = collection.get_next_id(self.__tablename__)
        istrue = Expert.isphone(phone=self.phone)
        if istrue == 0:
            self.date = common.getstamp()
            self.save()

            return self._id
        else:
            return -1
Esempio n. 7
0
    def saveinfo(self):
        self._id = collection.get_next_id(self.__tablename__)

        if self.username == '-1':
            self.username = '******' + str(self._id)
        elif self.username == '-2':
            self.username = '******' + str(self._id)
        elif self.username == '-3':
            self.username = '******' + str(self._id)

        self.password = self.password_hash
        self.date = common.getstamp()
        self.save()

        return self._id
Esempio n. 8
0
    def saveinfo(self):
        self._id = collection.get_next_id(self.__tablename__)

        if self.username == '-1':
            self.username = '******'+str(self._id)
        elif self.username == '-2':
            self.username = '******'+str(self._id)
        elif self.username == '-3':
            self.username = '******'+str(self._id)

        self.password = self.password_hash
        self.date = common.getstamp()
        self.save()

        return self._id
Esempio n. 9
0
    def saveinfo_snslogin(self):
        if self.username == '-1':
            self.username = '******' + str(self._id)
        elif self.username == '-2':
            self.username = '******' + str(self._id)
        elif self.username == '-3':
            self.username = '******' + str(self._id)
        elif len(self.username) == 0:
            if self.role_id == 2:
                self.username = '******' + str(self._id)
            elif self.role_id == 3:
                self.username = '******' + str(self._id)

        self.password = self.password_hash
        self.date = common.getstamp()
        self.save()
Esempio n. 10
0
    def saveinfo_snslogin(self):
        if self.username == '-1':
            self.username = '******'+str(self._id)
        elif self.username == '-2':
            self.username = '******'+str(self._id)
        elif self.username == '-3':
            self.username = '******'+str(self._id)
        elif len(self.username)==0:
            if self.role_id==2:
                self.username = '******'+str(self._id)
            elif self.role_id==3:
                self.username = '******'+str(self._id)

        self.password = self.password_hash
        self.date = common.getstamp()
        self.save()
Esempio n. 11
0
    def reset_password(self, token, new_password):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except:
            return False
        if data.get('reset') != self.id:
            return False
        self.password = new_password

        update = {}
        update['set__password_hash'] = self.password_hash
        update['set__stats__lastaction'] = common.getstamp()
        User.objects(_id=self._id).update_one(**update)

        return True
Esempio n. 12
0
    def reset_password(self, token, new_password):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except:
            return False
        if data.get('reset') != self.id:
            return False
        self.password = new_password

        update = {}
        update['set__password_hash'] = self.password_hash
        update['set__stats__lastaction'] = common.getstamp()
        User.objects(_id=self._id).update_one(**update)

        return True
Esempio n. 13
0
    def saveinfo_app(self):
        #前端注册用户信息

        if len(self.username) == 0:
            if self.role_id == 2:
                self.username = '******' + str(self._id)
            elif self.role_id == 3:
                self.username = '******' + str(self._id)
        istrue = User.isusername(username=self.username)
        if istrue == 0:
            self.password = self.password_hash
            self.date = common.getstamp()
            self.save()

            return self._id
        else:
            return -1
Esempio n. 14
0
    def saveinfo_app(self):
        #前端注册用户信息
        
        if len(self.username)==0:
                if self.role_id==2:
                    self.username = '******'+str(self._id)
                elif self.role_id==3:
                    self.username = '******'+str(self._id)
        istrue = User.isusername(username=self.username)
        if istrue == 0:
            self.password = self.password_hash
            self.date = common.getstamp()
            self.save()

            return self._id
        else:
            return -1
Esempio n. 15
0
    def saveinfo(self):
        if self._id > 0:
            update = {}
            # update.append({'set__email': self.email})

            update['set__park_id'] = self.park_id
            update['set__gateway_id'] = self.gateway_id
            update['set__device_id'] = self.device_id
            #update['set__lockstate'] = self.lockstate
            #update['set__state'] = self.state

            Lock.objects(_id=self._id).update_one(**update)
            return 1
        else:
            self._id = collection.get_next_id(self.__tablename__)
            self.date = common.getstamp()
            self.save()
            return self._id
Esempio n. 16
0
class Client(Document):  # 客户端
    __tablename__ = 'client'
    meta = {
        'collection': __tablename__,
    }
    _id = IntField(primary_key=True)
    _type = IntField(default=0, db_field='t')  # 类型
    user_id = IntField(default=0, db_field='u')  # 创建时间
    device_id = StringField(default='',
                            max_length=64,
                            required=True,
                            db_field='di')
    activa_data = IntField(default=common.getstamp(), db_field='ad')  # 最后活动时间
    state = IntField(default=0, db_field='s')  # 状态

    @staticmethod
    def getcount(devid):
        return Client.objects(device_id=devid).count()
Esempio n. 17
0
    def useredit(self):
        # 更新个人信息(用户)
        if self._id > 0:
            #print str(self._id)
            update = {}
            if len(self.name) > 0:
                update['set__name'] = self.name
            if self.sex>-1:
                update['set__sex'] = self.sex
            if len(self.avaurl)>0:
                update['set__avaurl'] = self.avaurl
            if self.role_id==2 or self.role_id==1:
                if self.domainid>-1:
                    update['set__domainid'] = self.domainid
                if self.industryid>-1:
                    update['set__industryid'] = self.industryid
            update['set__stats__lastaction'] = common.getstamp()
            User.objects(_id=self._id).update_one(**update)

            if self.role_id==2:
                u_info = User.objects(_id=self._id).first()
                User.Create_Q_YUNSOU_DATA(u_info)
Esempio n. 18
0
    def useredit(self):
        # 更新个人信息(用户)
        if self._id > 0:
            #print str(self._id)
            update = {}
            if len(self.name) > 0:
                update['set__name'] = self.name
            if self.sex > -1:
                update['set__sex'] = self.sex
            if len(self.avaurl) > 0:
                update['set__avaurl'] = self.avaurl
            if self.role_id == 2 or self.role_id == 1:
                if self.domainid > -1:
                    update['set__domainid'] = self.domainid
                if self.industryid > -1:
                    update['set__industryid'] = self.industryid
            update['set__stats__lastaction'] = common.getstamp()
            User.objects(_id=self._id).update_one(**update)

            if self.role_id == 2:
                u_info = User.objects(_id=self._id).first()
                User.Create_Q_YUNSOU_DATA(u_info)
Esempio n. 19
0
 def saveinfo(remark='', aid=0):
     Log(remark=remark,
         admin_id=aid == 0 and g.current_user._id or aid,
         _id=collection.get_next_id(Log.__tablename__),
         date=common.getstamp()).save()
Esempio n. 20
0
    def editinfo(self):
    	#后台更新用户信息
        if self._id > 0:
            update = {}
            # update.append({'set__email': self.email})
            update['set__role_id'] = self.role_id
            if len(self.email) > 0:
                update['set__email'] = self.email
            if len(self.username) > 0:
                update['set__username'] = self.username
            if len(self.name) > 0:
                update['set__name'] = self.name
            print self.password_hash
            if len(self.password_hash) > 0:
                self.password = self.password_hash
                update['set__password_hash'] = self.password_hash
            print self.password_hash
            update['set__confirmed'] = self.confirmed
            update['set__domainid'] = self.domainid
            update['set__industryid'] = self.industryid
            update['set__sex'] = self.sex
            update['set__job'] = self.job
            update['set__geo'] = self.geo
            update['set__intro'] = self.intro
            update['set__content'] = self.content
            update['set__bgurl'] = self.bgurl
            update['set__fileurl'] = self.fileurl
            update['set__avaurl'] = self.avaurl
            update['set__label'] = self.label
            update['set__workexp'] = self.workexp
            update['set__edu'] = self.edu
            update['set__openplatform'] = self.openplatform

            update['set__stats__lastaction'] = common.getstamp()
            '''
            update['set__stats__baidu'] = self.stats.baidu
            update['set__stats__weixin'] = self.stats.weixin
            update['set__stats__zhihu'] = self.stats.zhihu
            update['set__stats__sina'] = self.stats.sina
            update['set__stats__twitter'] = self.stats.twitter
            update['set__stats__facebook'] = self.stats.facebook
            update['set__stats__github'] = self.stats.github

            update['set__stats__baiduurl'] = self.stats.baiduurl
            update['set__stats__weixinurl'] = self.stats.weixinurl
            update['set__stats__zhihuurl'] = self.stats.zhihuurl
            update['set__stats__sinaurl'] = self.stats.sinaurl
            update['set__stats__twitterurl'] = self.stats.twitterurl
            update['set__stats__facebookurl'] = self.stats.facebookurl
            update['set__stats__githuburl'] = self.stats.githuburl
            '''
            update['set__state'] = self.state
            update['set__sort'] = self.sort
            User.objects(_id=self._id).update_one(**update)

            if self.role_id==2:
                User.Create_Q_YUNSOU_DATA(self)
            '''
            #更新whoosh
            updata_whoosh = {}
            updata_whoosh['_id']=self._id
            updata_whoosh['n']=unicode(self.name)
            updata_whoosh['l']=self.label
            updata_whoosh['j']=self.job
            searchwhoosh.update(updata_whoosh)
            '''
            logmsg = '编辑'+(self.role_id==2 and '用户'or '专家')+'-'+str(self._id)+'-'+self.name +'-' + self.job
            Log.saveinfo(remark=logmsg)

            return 1
        else:

            self._id = collection.get_next_id(self.__tablename__)
            if len(self.username)==0:
                    if self.role_id==2:
                        self.username = '******'+str(self._id)
                    elif self.role_id==3:
                        self.username = '******'+str(self._id)
            istrue = User.isusername(username=self.username)
            if istrue == 0:
                self.password = self.password_hash
                self.date = common.getstamp()
                self.save()

                '''
                #更新whoosh
                updata_whoosh = {}
                updata_whoosh['_id']= self._id
                updata_whoosh['n']= unicode(self.name)
                updata_whoosh['j']= unicode(self.job)
                updata_whoosh['l']=self.label
                searchwhoosh.update(updata_whoosh)
                '''
                logmsg = '创建'+(self.role_id==2 and '用户'or '专家')+'-'+str(self._id)+'-'+self.name +'-' + self.job
                Log.saveinfo(remark=logmsg)

                return self._id
            else:
                return -1
Esempio n. 21
0
    def editinfo(self):
        #后台更新用户信息
        if self._id > 0:
            update = {}
            # update.append({'set__email': self.email})
            update['set__role_id'] = self.role_id
            if len(self.email) > 0:
                update['set__email'] = self.email
            if len(self.username) > 0:
                update['set__username'] = self.username
            if len(self.name) > 0:
                update['set__name'] = self.name
            print self.password_hash
            if len(self.password_hash) > 0:
                self.password = self.password_hash
                update['set__password_hash'] = self.password_hash
            print self.password_hash
            update['set__confirmed'] = self.confirmed
            update['set__domainid'] = self.domainid
            update['set__industryid'] = self.industryid
            update['set__sex'] = self.sex
            update['set__job'] = self.job
            update['set__geo'] = self.geo
            update['set__intro'] = self.intro
            update['set__content'] = self.content
            update['set__bgurl'] = self.bgurl
            update['set__fileurl'] = self.fileurl
            update['set__avaurl'] = self.avaurl
            update['set__label'] = self.label
            update['set__workexp'] = self.workexp
            update['set__edu'] = self.edu
            update['set__openplatform'] = self.openplatform

            update['set__stats__lastaction'] = common.getstamp()
            '''
            update['set__stats__baidu'] = self.stats.baidu
            update['set__stats__weixin'] = self.stats.weixin
            update['set__stats__zhihu'] = self.stats.zhihu
            update['set__stats__sina'] = self.stats.sina
            update['set__stats__twitter'] = self.stats.twitter
            update['set__stats__facebook'] = self.stats.facebook
            update['set__stats__github'] = self.stats.github

            update['set__stats__baiduurl'] = self.stats.baiduurl
            update['set__stats__weixinurl'] = self.stats.weixinurl
            update['set__stats__zhihuurl'] = self.stats.zhihuurl
            update['set__stats__sinaurl'] = self.stats.sinaurl
            update['set__stats__twitterurl'] = self.stats.twitterurl
            update['set__stats__facebookurl'] = self.stats.facebookurl
            update['set__stats__githuburl'] = self.stats.githuburl
            '''
            update['set__state'] = self.state
            update['set__sort'] = self.sort
            User.objects(_id=self._id).update_one(**update)

            if self.role_id == 2:
                User.Create_Q_YUNSOU_DATA(self)
            '''
            #更新whoosh
            updata_whoosh = {}
            updata_whoosh['_id']=self._id
            updata_whoosh['n']=unicode(self.name)
            updata_whoosh['l']=self.label
            updata_whoosh['j']=self.job
            searchwhoosh.update(updata_whoosh)
            '''
            logmsg = '编辑' + (self.role_id == 2 and '用户' or '专家') + '-' + str(
                self._id) + '-' + self.name + '-' + self.job
            Log.saveinfo(remark=logmsg)

            return 1
        else:

            self._id = collection.get_next_id(self.__tablename__)
            if len(self.username) == 0:
                if self.role_id == 2:
                    self.username = '******' + str(self._id)
                elif self.role_id == 3:
                    self.username = '******' + str(self._id)
            istrue = User.isusername(username=self.username)
            if istrue == 0:
                self.password = self.password_hash
                self.date = common.getstamp()
                self.save()
                '''
                #更新whoosh
                updata_whoosh = {}
                updata_whoosh['_id']= self._id
                updata_whoosh['n']= unicode(self.name)
                updata_whoosh['j']= unicode(self.job)
                updata_whoosh['l']=self.label
                searchwhoosh.update(updata_whoosh)
                '''
                logmsg = '创建' + (
                    self.role_id == 2 and '用户' or '专家') + '-' + str(
                        self._id) + '-' + self.name + '-' + self.job
                Log.saveinfo(remark=logmsg)

                return self._id
            else:
                return -1
Esempio n. 22
0
 def saveinfo(remark='',aid=0):
     Log(remark=remark,admin_id=aid==0 and g.current_user._id or aid,_id=collection.get_next_id(Log.__tablename__),date=common.getstamp()).save()
Esempio n. 23
0
 def saveinfo(self):
     self._id = collection.get_next_id(self.__tablename__)
     self.date = common.getstamp()
     self.save()
Esempio n. 24
0
 def saveinfo(self):
     self._id = collection.get_next_id(self.__tablename__)
     self.date = common.getstamp()
     self.save()