async def change_nickname(self): u = self.current_user if not u: return self.finish(RETCODE.PERMISSION_DENIED) post = await self.post_data() form = NicknameForm(**post) if not form.validate(): return self.finish(RETCODE.INVALID_POSTDATA, form.errors) if u.change_nickname_chance > 0: try: old_nickname = u.nickname u.nickname = form['nickname'].data u.change_nickname_chance -= 1 u.is_new_user = False u.save() self.finish( RETCODE.SUCCESS, { 'nickname': u.nickname, 'change_nickname_chance': u.change_nickname_chance }) ManageLog.add_by_post_changed(self, 'nickname', MOP.USER_NICKNAME_CHANGE, POST_TYPES.USER, True, {'nickname': old_nickname}, u, value=None) return except peewee.DatabaseError: db.rollback() self.finish(RETCODE.FAILED)
def check_in(self): self.last_check_in_time = self.last_check_in_time or 0 old_time = self.last_check_in_time last_midnight = get_today_start_timestamp() # 今日未签到 if self.last_check_in_time < last_midnight: self.last_check_in_time = int(time.time()) # 三天内有签到,连击 if old_time > last_midnight - config.USER_CHECKIN_COUNTER_INTERVAL: self.check_in_his += 1 else: self.check_in_his = 1 self.save() # 签到加分 credit = self.credit exp = self.exp self.credit += 5 self.exp += 5 self.save() ManageLog.add_by_credit_changed_sys(self, note='每日签到', value=[credit, self.credit]) ManageLog.add_by_exp_changed_sys(self, note='每日签到', value=[exp, self.exp]) return { 'credit': 5, 'exp': 5, 'time': self.last_check_in_time, 'check_in_his': self.check_in_his }
def check_in(self): self.last_check_in_time = self.last_check_in_time or 0 old_time = self.last_check_in_time last_midnight = get_today_start_timestamp() # 今日未签到 if self.last_check_in_time < last_midnight: self.last_check_in_time = int(time.time()) # 三天内有签到,连击 print(old_time, last_midnight - 3 * 24 * 60 * 60) if old_time > last_midnight - 3 * 24 * 60 * 60: self.check_in_his += 1 else: self.check_in_his = 1 self.save() # 签到加分 credit = self.credit reputation = self.reputation self.credit += 5 self.reputation += 5 self.save() ManageLog.add_by_credit_changed_sys(self, note='每日签到', value=[credit, self.credit]) ManageLog.add_by_reputation_changed_sys(self, note='每日签到', value=[reputation, self.reputation]) return { 'credit': 5, 'reputation': 5, 'time': self.last_check_in_time, 'check_in_his': self.check_in_his }
def after_update(self, raw_post: Dict, values: SQLValuesToWrite, old_records: List[DataRecord], records: List[DataRecord]): for old_record, record in zip(old_records, records): # 管理日志:修改评论状态 ManageLog.add_by_post_changed(self, 'state', MOP.COMMENT_STATE_CHANGE, POST_TYPES.COMMENT, values, old_record, record)
def after_update(self, raw_post: Dict, values: SQLValuesToWrite, old_records: List[DataRecord], records: List[DataRecord]): for old_record, record in zip(old_records, records): # 管理日志:重置访问令牌 ManageLog.add_by_post_changed(self, 'key', MOP.USER_KEY_RESET, POST_TYPES.USER, values, old_record, record, value=None) # 管理日志:重置密码 ManageLog.add_by_post_changed(self, 'password', MOP.USER_PASSWORD_CHANGE, POST_TYPES.USER, values, old_record, record, value=None)
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'])
def daily_access_reward(self): self.access_time = self.access_time or 0 old_time = self.access_time self.update_access_time() if old_time < get_today_start_timestamp(): credit = self.credit self.credit += 5 self.save() ManageLog.add_by_credit_changed_sys(self, note='每日登录', value=[credit, self.credit]) return 5
def daily_access_reward(self): self.access_time = self.access_time or 0 old_time = self.access_time self.update_access_time() if old_time < get_today_start_timestamp(): exp = self.exp self.exp += 5 self.save() ManageLog.add_by_exp_changed_sys(self, note='每日登录', value=[exp, self.exp]) return 5
def after_update(self, raw_post: Dict, values: SQLValuesToWrite, old_records: List[DataRecord], records: List[DataRecord]): for old_record, record in zip(old_records, records): # 注:此处记录不考虑可写不可读的情况。代码比较丑陋,后面改吧 o = old_record.to_dict() n = record.to_dict() to_remove = set() for k, v in n.items(): if k in o and o[k] == v: to_remove.add(k) for k, v in o.items(): if k in n and n[k] == v: to_remove.add(k) for k in to_remove: del o[k] del n[k] # 管理日志 ManageLog.new(self.current_user, self.current_role, POST_TYPES.BOARD, record['id'], MOP.BOARD_CHANGE, [o, n])
def after_update(self, raw_post: Dict, values: SQLValuesToWrite, old_records: List[DataRecord], records: List[DataRecord]): for old_record, record in zip(old_records, records): if 'content' in values: # 管理日志:正文编辑 ManageLog.new(self.current_user, self.current_role, POST_TYPES.TOPIC, record['id'], record['user_id'], MOP.TOPIC_CONTENT_CHANGE, None) Topic.update(edit_count=Topic.edit_count + 1).where(Topic.id == record['id']).execute() if 'title' in values: # 管理日志:标题编辑 ManageLog.new(self.current_user, self.current_role, POST_TYPES.TOPIC, record['id'], record['user_id'], MOP.TOPIC_TITLE_CHANGE, None) # 管理日志:改变状态 ManageLog.add_by_post_changed(self, 'state', MOP.POST_STATE_CHANGE, POST_TYPES.TOPIC, values, old_record, record) # 管理日志:改变可见度 ManageLog.add_by_post_changed(self, 'visible', MOP.POST_VISIBLE_CHANGE, POST_TYPES.TOPIC, values, old_record, record) # 管理日志:移动板块 if ManageLog.add_by_post_changed(self, 'board_id', MOP.TOPIC_BOARD_MOVE, POST_TYPES.TOPIC, values, old_record, record): statistic_move_topic(old_record['board_id'], record['board_id'], record['id']) # 管理日志:设置精华 ManageLog.add_by_post_changed(self, 'awesome', MOP.TOPIC_AWESOME_CHANGE, POST_TYPES.TOPIC, values, old_record, record) # 管理日志:置顶权重 ManageLog.add_by_post_changed(self, 'sticky_weight', MOP.TOPIC_STICKY_WEIGHT_CHANGE, POST_TYPES.TOPIC, values, old_record, record) # 管理日志:修改权重 ManageLog.add_by_post_changed(self, 'weight', MOP.TOPIC_WEIGHT_CHANGE, POST_TYPES.TOPIC, values, old_record, record)