def inject_variables(): if get_authed(): mod_links = [('boards', ['mod.mod_boards', 'mod.mod_board_log']), ('reports', ['mod.mod_report'])] if request_has_role(roles.ROLE_ADMIN): mod_links += [ ('bans', ['mod.mod_bans']), ('moderators', ['mod.mod_moderators']), ('pages', ['mod.mod_pages']), ('site', ['mod.mod_site']), ] mod_links += [('account', ['mod.mod_self']), ('logout', ['mod.mod_auth'])] with_current_and_url = [] for mod_link in mod_links: current = any(i.startswith(request.endpoint) for i in mod_link[1]) with_current_and_url.append( (mod_link[0], url_for(mod_link[1][0]), current)) return dict(mod_links=with_current_and_url, is_authed=True) else: return {}
def _mod_auth_post(): if get_authed(): _mod_auth_deauth() else: _mod_auth_auth() return redirect(url_for('.mod_auth'))
def _gather_manage_params() -> ManagePostDetails: form = request.form board_name = form.get('board', None) if not validation.check_board_name_validity(board_name): abort(400) thread_refno = form.get('thread', type=int) valid_id_range(thread_refno) post_id = form.get('post_id', type=int) if not post_id: post_id = None if post_id is not None: valid_id_range(post_id) password = form.get('password', None) if not password: password = None if password and not validation.check_password_validity(password): abort(400) ip4 = get_request_ip4() mod_id = None if get_authed(): mod_id = request_moderator().id mode_string = form.get('mode') return ManagePostDetails(board_name, thread_refno, post_id, ip4, mod_id, mode_string, password)
def show_moderator_buttons(board_id): if get_authed(): moderator = request_moderator() if moderator_service.moderates_board_id(moderator, board_id): return True return False
def inject_variables(): if get_authed(): mod_links = [ ('boards', ['mod.mod_boards', 'mod.mod_board_log']), ('reports', ['mod.mod_report']) ] if request_has_role(roles.ROLE_ADMIN): mod_links += [ ('bans', ['mod.mod_bans']), ('moderators', ['mod.mod_moderators']), ('pages', ['mod.mod_pages']), ('site', ['mod.mod_site']), ] mod_links += [ ('account', ['mod.mod_self']), ('logout', ['mod.mod_auth']) ] with_current_and_url = [] for mod_link in mod_links: current = any(i.startswith(request.endpoint) for i in mod_link[1]) with_current_and_url.append((mod_link[0], url_for(mod_link[1][0]), current)) return dict( mod_links=with_current_and_url, is_authed=True ) else: return {}
def mod_auth(): if request.method == 'POST': return _mod_auth_post() else: authed = get_authed() moderator = request_moderator() if authed else None method = None if not authed: method = verification_service.get_method() return render_template('auth.html', authed=authed, moderator=moderator, method=method)
def _gather_post_params() -> Tuple[BoardModel, PostDetails]: form = request.form # Gather params thread_refno_raw = form.get('thread', None) thread_refno = None if thread_refno_raw is not None: try: thread_refno = int(thread_refno_raw) valid_id_range(thread_refno) except ValueError: abort(400) board_name = form.get('board', None) if not validation.check_board_name_validity(board_name): abort(400) board = board_service.find_board(board_name) if not board: abort(404) text = form.get('comment', None) name = form.get('name', None) subject = form.get('subject', None) password = form.get('password', None) # Convert empty strings to None if not text: text = None if not name: name = None if not subject: subject = None if not password: password = None file = request.files.get('file', None) has_file = file is not None and file.filename is not None and len(file.filename) > 0 ip4 = get_request_ip4() with_mod = form.get('with_mod', default=False, type=bool) mod_id = None if with_mod: moderator = request_moderator() if get_authed() else None if moderator is not None: mod_id = moderator.id return board, PostDetails(form, board_name, thread_refno, text, name, subject, password, has_file, ip4, mod_id, None)
def mod_log(what, moderator_name=None, moderator=None, ip4_str=None): """Logs to a log file.""" # Hax in_request_context = _request_ctx_stack.top is not None if in_request_context: if ip4_str is None: ip4_str = get_request_ip4_str() if moderator_name is None: if not moderator: moderator = request_moderator() if get_authed() else None if moderator is not None: moderator_name = moderator.username output = '' if ip4_str is not None: output += '[' + ip4_str + '] ' if moderator_name is not None: output += '[' + moderator_name + '] ' output += what mod_logger.info(output)
def mod_restrict(): if (request.endpoint != 'mod.mod_auth' and request.endpoint != 'mod.mod_reg') and not get_authed(): return mod_abort_redirect()