示例#1
0
文件: models.py 项目: txfyteen/chiki
    def get(key, tid, day=today(), hour=0, default=0, save=True):
        if callable(day):
            day = day()
        day = str(day)[:10]
        item = StatLog.objects(key=key, tid=tid, day=day).first()
        if item:
            return item.value

        if save:
            StatLog(key=key, tid=tid, day=day, hour=0, value=default).save()
        return default
示例#2
0
文件: models.py 项目: endsh/chiki
    def get(key, tid, day=today(), hour=0, default=0, save=True):
        if callable(day):
            day = day()
        day = str(day)[:10]
        item = StatLog.objects(key=key, tid=tid, day=day).first()
        if item:
            return item.value

        if save:
            StatLog(key=key, tid=tid, day=day, hour=0, value=default).save()
        return default
示例#3
0
    def validate_account(self, field):
        admin = AdminUser.objects(
            username=self.account.data).first()
        if not admin:
            raise ValueError('用户不存在')
        if not admin.active:
            raise ValueError('用户被冻结')
        if admin.password != self.password.data:
            AdminUserLoginLog.error(admin.id)
            count = AdminUserLoginLog.objects(
                created__gte=max(today(), admin.freezed or today()),
                user=admin.id,
                type=AdminUserLoginLog.TYPE.ERROR).count()
            if count >= 20:
                admin.active = False
                admin.freezed = datetime.now()
                admin.save()
            raise ValueError('密码错误')

        self.admin = admin
示例#4
0
文件: models.py 项目: endsh/chiki
 def inc(key, tid, day=lambda: today(), hour=0, value=1):
     if callable(day):
         day = day()
     day = str(day)[:10]
     item = StatLog.objects(key=key, tid=tid, day=day).modify(
         inc__value=value,
         set__modified=datetime.now(),
     )
     if not item:
         StatLog(key=key, tid=tid, day=day, hour=0, value=value).save()
         return value
     else:
         return item.value + 1
示例#5
0
文件: models.py 项目: txfyteen/chiki
 def inc(key, tid, day=lambda: today(), hour=0, value=1):
     if callable(day):
         day = day()
     day = str(day)[:10]
     item = StatLog.objects(key=key, tid=tid, day=day).modify(
         inc__value=value,
         set__modified=datetime.now(),
     )
     if not item:
         StatLog(key=key, tid=tid, day=day, hour=0, value=value).save()
         return value
     else:
         return item.value + 1
示例#6
0
 def token(self):
     now = datetime.now()
     key = self.config.get('config_key', 'siwei:token')
     token = json.loads(Item.data(key, '{}'))
     if not token or datetime.strptime(token['deadline'],
                                       '%Y-%m-%d %H:%M:%S') <= now:
         token = self.grant_token()
         if token:
             if not token['persisted']:
                 token['deadline'] = today() + timedelta(seconds=1800)
             else:
                 token['deadline'] = now + timedelta(
                     seconds=token['persisted'])
             token['deadline'] = token['deadline'].strftime(
                 '%Y-%m-%d %H:%M:%S')
             Item.set_data(key, json.dumps(token))
     return token
示例#7
0
文件: models.py 项目: endsh/chiki
 def code_day(phone):
     PhoneCode = um.models.PhoneCode
     return PhoneCode.objects(phone=phone, created__gte=today()).count()