示例#1
0
    async def after_insert(self, raw_post: Dict, values: SQLValuesToWrite,
                           record: DataRecord):
        if record['number'] == 1:
            u = User.get(User.id == record['id'])
            u.group = USER_GROUP.ADMIN
            u.save()

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

        record['access_token'] = self._key
示例#2
0
文件: user.py 项目: yisan/Icarus
    async def signup_cleanup(self, u):
        if u:
            # 添加统计记录
            post_stats_new(POST_TYPES.USER, u.id)
            UserNotifLastInfo.new(u.id)

            if u.email:
                await UserModel.reg_code_cleanup(u.email)

            t: UserToken = await self.setup_user_token(u.id)
            self.finish(RETCODE.SUCCESS, {'id': u.id, 'access_token': t.get_token()})
        else:
            self.finish(RETCODE.FAILED)
示例#3
0
    async def after_insert(self, values_lst: List[SQLValuesToWrite],
                           records: List[DataRecord]):
        for record in records:
            if record['number'] == 1:
                u = User.get(User.id == record['id'])
                u.group = USER_GROUP.ADMIN
                u.save()

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

            record['access_token'] = self._key
示例#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()

        # 发送注册邮件
        if config.EMAIL_ACTIVATION_ENABLE and not record['number'] == 1:
            await mail.send_register_activation(record.val)

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

        record['access_token'] = self._key
示例#5
0
文件: u10-u11.py 项目: yisan/Icarus
def work():
    sql_execute(
        'ALTER TABLE "topic" ADD COLUMN "update_time" BIGINT NULL DEFAULT NULL ;'
    )
    sql_execute(
        'ALTER TABLE "user" ADD COLUMN "ip_registered" inet NULL DEFAULT NULL;'
    )
    sql_execute('drop table "notif";')
    sql_execute('drop table "mention";')
    sql_execute('drop table "user_notif_record";')

    db.create_tables([UserNotifLastInfo], safe=True)
    for i in UserModel.select().execute():
        try:
            UserNotifLastInfo.create(id=i.id, update_time=int(time.time()))
        except peewee.IntegrityError as e:
            print(e)
            db.rollback()
示例#6
0
    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)

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

        return u