Example #1
0
File: topic.py Project: 1y1n/Icarus
    def after_insert(self, raw_post: Dict, values: SQLValuesToWrite,
                     records: List[DataRecord]):
        record = records[0]
        statistic_add_topic(record['board_id'], record['id'])

        # 添加统计记录
        statistic_new(POST_TYPES.TOPIC, record['id'])
Example #2
0
    async def after_insert(self, raw_post: Dict,
                           values_lst: List[SQLValuesToWrite],
                           records: List[DataRecord]):
        for record in records:
            # 添加统计记录
            statistic_new(POST_TYPES.BOARD, record['id'])

            # 管理日志:重置密码
            ManageLog.new(self.current_user, self.current_role,
                          POST_TYPES.BOARD, record['id'], MOP.BOARD_NEW,
                          record['name'])
Example #3
0
    def after_insert(self, raw_post: Dict, values: SQLValuesToWrite, records: List[DataRecord]):
        record = records[0]

        if self.do_mentions:
            self.do_mentions(record['user_id'], POST_TYPES.TOPIC, record['id'], {
                'title': record['title'],
            })

        statistic_add_topic(record['board_id'], record['id'])

        # 添加统计记录
        statistic_new(POST_TYPES.TOPIC, record['id'])
Example #4
0
    async def after_insert(self, raw_post: Dict, values_lst: SQLValuesToWrite,
                           records: List[DataRecord]):
        record = records[0]
        if record['number'] == 1:
            u = User.get(User.id == record['id'])
            u.group = USER_GROUP.ADMIN
            u.save()

        # 添加统计记录
        statistic_new(POST_TYPES.USER, record['id'])
        UserNotifLastInfo.new(record['id'])

        record['access_token'] = self._key
Example #5
0
 def get_main_page_root_article(cls):
     try:
         return cls.select().where(cls.flag == 2,
                                   cls.root_id.is_null()).get()
     except cls.DoesNotExist:
         a = cls.insert(time=int(time.time()),
                        user_id=None,
                        flag=2,
                        is_current=True,
                        major_ver=1,
                        minor_ver=0,
                        title="主页面",
                        content='主页面文本').execute()
         statistic_new(POST_TYPES.WIKI, a.tobytes())
         return cls.get(cls.id == a)
Example #6
0
    async def after_insert(self, raw_post: Dict, values_lst: SQLValuesToWrite, records: List[DataRecord]):
        record = records[0]
        if record['number'] == 1:
            u = User.get(User.id == record['id'])
            u.group = USER_GROUP.ADMIN
            u.save()

        # 发送注册邮件
        if config.EMAIL_ACTIVATION_ENABLE:
            await mail.send_register_activation(record.val)

        # 添加统计记录
        statistic_new(POST_TYPES.USER, record['id'])
        UserNotifRecord.new(record['id'])

        record['access_token'] = self._key
Example #7
0
File: user.py Project: zaevi/Icarus
    async def create_user(self, password, email=None, phone=None) -> User:
        values = {}
        nprefix = config.USER_NICKNAME_AUTO_PREFIX + '_'

        if config.POST_ID_GENERATOR != config.AutoGenerator:
            # 若不使用数据库生成id
            uid = User.gen_id()
            values['id'] = uid.to_bin()
            values['nickname'] = nprefix + uid.to_hex()

        values['is_new_user'] = True
        values['change_nickname_chance'] = 1

        if email:
            values['email'] = email.lower()

        if phone:
            values['phone'] = phone

        # 密码
        ret = User.gen_password_and_salt(password)
        values.update(ret)

        values['group'] = USER_GROUP.NORMAL
        values['state'] = POST_STATE.NORMAL

        # 注册IP地址
        values['ip_registered'] = await get_fuzz_ip(self)

        # 生成 access_token
        values.update(User.gen_key())
        values['time'] = int(time.time())

        try:
            uid = User.insert(values).execute()
            u = User.get_by_pk(uid)
        except peewee.IntegrityError as e:
            db.rollback()
            if e.args[0].startswith('duplicate key'):
                return self.finish(RETCODE.ALREADY_EXISTS)
            return self.finish(RETCODE.FAILED)
        except peewee.DatabaseError:
            db.rollback()
            return self.finish(RETCODE.FAILED)

        times = 3
        success = False
        u.nickname = nprefix + to_hex(u.id.tobytes())

        # 尝试填充用户名
        while times >= 0:
            try:
                if u.number == 1:
                    u.group = USER_GROUP.ADMIN
                u.save()
                success = True
                break
            except peewee.DatabaseError:
                db.rollback()
                times -= 1
                u.nickname = nprefix + to_hex(os.urandom(8))

        if not success:
            return self.finish(RETCODE.FAILED)

        # 清理现场
        if email:
            await User.reg_code_cleanup(email)

        # 添加统计记录
        statistic_new(POST_TYPES.USER, u.id)
        UserNotifLastInfo.new(u.id)

        return u
Example #8
0
    def after_insert(self, raw_post: Dict, values: SQLValuesToWrite,
                     records: List[DataRecord]):
        record = records[0]

        # 添加统计记录
        statistic_new(POST_TYPES.WIKI, record['id'])