def view_forum(forum): forum = Forum.objects(identifier=forum).first() if forum is None: abort(404) categories = Category.objects(forum=forum) recent_topics = Topic.objects(forum=forum).order_by('-last_post_date').limit(10) if current_user.is_authenticated(): read_topics = recent_topics.filter(users_read_topic__in=[current_user.id]).scalar('id') else: read_topics = None return render_template("forum_topics_display.html", categories=categories, forum=forum, topics=recent_topics, read_topics=read_topics, forum_menu_current='latest', **forum_template_data(forum)) #@blueprint.route('/f/a/s/') #def setup(): # category = Category.objects.first() # forum = Forum.objects(identifier="main").first() # board = Board() # board.name = "General Chat" # board.forum = forum # board.categories = [category] # board.description = "Put chatter here pls" # board.save() # return 'yes'
def login(): if current_user.is_authenticated(): return redirect(request.args.get("next", '/')) if session.get('tfa-logged-in', False): del session['tfa-logged-in'] del session['tfa-user'] del session['tfa-remember'] form = LoginForm(request.form) if request.method == "POST" and form.validate(): try: user = authenticate_user(form.username.data, form.password.data) except LoginException, e: form.errors["login"] = [e.message] return render_template("login.html", form=form, title="Login") if user.tfa: session['tfa-logged-in'] = True session['tfa-user'] = user.name session['tfa-remember'] = form.remember.data return redirect( url_for('auth.verify', next=request.args.get('next'))) #if not user.verified: # flash(u"Please check your mail.") # return redirect(url_for('auth.login', ext='html')) if login_user(user, remember=form.remember.data): flash("Logged in!", category="success") return redirect(request.args.get("next", '/'))
def login(): if current_user.is_authenticated(): return redirect(request.args.get("next", '/')) if session.get('tfa-logged-in', False): del session['tfa-logged-in'] del session['tfa-user'] del session['tfa-remember'] form = LoginForm(request.form) if request.method == "POST" and form.validate(): try: user = authenticate_user(form.username.data, form.password.data) except LoginException, e: form.errors["login"] = [e.message] return render_template("login.html", form=form, title="Login") if user.tfa: session['tfa-logged-in'] = True session['tfa-user'] = user.name session['tfa-remember'] = form.remember.data return redirect(url_for('auth.verify', next=request.args.get('next'))) #if not user.verified: # flash(u"Please check your mail.") # return redirect(url_for('auth.login', ext='html')) if login_user(user, remember=form.remember.data): flash("Logged in!", category="success") return redirect(request.args.get("next", '/'))
def view_forum(forum): forum = Forum.objects(identifier=forum).first() if forum is None: abort(404) categories = Category.objects(forum=forum) recent_topics = Topic.objects( forum=forum).order_by('-last_post_date').limit(10) if current_user.is_authenticated(): read_topics = recent_topics.filter( users_read_topic__in=[current_user.id]).scalar('id') else: read_topics = None return render_template("forum_topics_display.html", categories=categories, forum=forum, topics=recent_topics, read_topics=read_topics, forum_menu_current='latest', **forum_template_data(forum)) #@blueprint.route('/f/a/s/') #def setup(): # category = Category.objects.first() # forum = Forum.objects(identifier="main").first() # board = Board() # board.name = "General Chat" # board.forum = forum # board.categories = [category] # board.description = "Put chatter here pls" # board.save() # return 'yes'
def view_board(board_id, board_name, page): board = Board.objects(board_id=board_id).first() if board is None: abort(404) if not board_name == board.get_url_name(): return redirect(board.get_url()) forum = board.forum # Get our sorted topics and the number of topics. topics = Topic.objects(board=board).order_by('-last_post_date') topic_num = len(topics) # Calculate the total number of pages and make sure the request is a valid page. num_pages = int(math.ceil(topic_num / float(TOPICS_PER_PAGE))) if num_pages < page: if page == 1: return render_template('forum_topics_display.html', board=board, forum=forum, topics=[], read_topics=[], forum_menu_current=board.id, **forum_template_data(forum)) abort(404) # Compile the list of topics we want displayed. display_topics = topics.skip( (page - 1) * TOPICS_PER_PAGE).limit(TOPICS_PER_PAGE) if current_user.is_authenticated(): read_topics = display_topics.filter( users_read_topic__in=[current_user.id]).scalar('id') else: read_topics = None # Find the links we want for the next/prev buttons if applicable. #next_page = url_for('forum.view_board', page=page + 1, **board.get_url_info()) if page < num_pages \ # else None #prev_page = url_for('forum.view_board', page=page - 1, **board.get_url_info()) if page > 1 and not num_pages == 1 \ # else None # Mash together a list of what pages we want linked to in the pagination bar. #links = [] #for page_mod in range(-min(PAGINATION_VALUE_RANGE, page - 1), min(PAGINATION_VALUE_RANGE, num_pages-page) + 1): # num = page + page_mod # links.append({'num': num, 'url': url_for('forum.view_board', page=num, **board.get_url_info()), 'active': (num == page)}) # Render it all out :D return render_template('forum_topics_display.html', board=board, forum=forum, topics=display_topics, read_topics=read_topics, forum_menu_current=board.id, **forum_template_data(forum))
def donate(): funds_target = 49 donations = DonationTransaction.objects(valid=True) transactions = Transaction.objects() return render_template( 'donate.html', funds_target=funds_target, funds_current=transactions.sum('amount'), total_fees=donations.sum('fee'), total_donations=DonationTransaction.objects(valid=True, gross__gt=0).sum('gross'), num_donations=len(donations), top_donations=donations.order_by('-amount').limit(5).only('gross', 'fee', 'username', 'valid'), signed_user=username_signer.dumps(current_user.name) if current_user.is_authenticated() else None )
def appeal_reply_edit(appeal_reply_id): edit_form = AppealReplyTextEditForm(request.form) appeal_reply = AppealReply.objects(id=appeal_reply_id).first() if appeal_reply is None: abort(404) if not (current_user.has_permission("bans.appeal.manage") or (current_user.is_authenticated() and current_user == appeal_reply.creator)): abort(403) if request.method == "POST" and edit_form.validate(): appeal_reply.text = edit_form.text.data appeal_reply.edits.append(AppealEdit(text=edit_form.text.data, user=current_user.to_dbref())) appeal_reply.save() return redirect(url_for('bans.view_ban', ban_uid=appeal_reply.ban.uid))
def donate(): funds_target = 49 donations = DonationTransaction.objects(valid=True) transactions = Transaction.objects() return render_template( 'donate.html', funds_target=funds_target, funds_current=transactions.sum('amount'), total_fees=donations.sum('fee'), total_donations=DonationTransaction.objects(valid=True, gross__gt=0).sum('gross'), num_donations=len(donations), top_donations=donations.order_by('-amount').limit(5).only( 'gross', 'fee', 'username', 'valid'), signed_user=username_signer.dumps(current_user.name) if current_user.is_authenticated() else None)
def appeal_reply_edit(appeal_reply_id): edit_form = AppealReplyTextEditForm(request.form) appeal_reply = AppealReply.objects(id=appeal_reply_id).first() if appeal_reply is None: abort(404) if not (current_user.has_permission("bans.appeal.manage") or (current_user.is_authenticated() and current_user == appeal_reply.creator)): abort(403) if request.method == "POST" and edit_form.validate(): appeal_reply.text = edit_form.text.data appeal_reply.edits.append( AppealEdit(text=edit_form.text.data, user=current_user.to_dbref())) appeal_reply.save() return redirect(url_for('bans.view_ban', ban_uid=appeal_reply.ban.uid))
def view_board(board_id, board_name, page): board = Board.objects(board_id=board_id).first() if board is None: abort(404) if not board_name == board.get_url_name(): return redirect(board.get_url()) forum = board.forum # Get our sorted topics and the number of topics. topics = Topic.objects(board=board).order_by('-last_post_date') topic_num = len(topics) # Calculate the total number of pages and make sure the request is a valid page. num_pages = int(math.ceil(topic_num / float(TOPICS_PER_PAGE))) if num_pages < page: if page == 1: return render_template('forum_topics_display.html', board=board, forum=forum, topics=[], read_topics=[], forum_menu_current=board.id, **forum_template_data(forum)) abort(404) # Compile the list of topics we want displayed. display_topics = topics.skip((page - 1) * TOPICS_PER_PAGE).limit(TOPICS_PER_PAGE) if current_user.is_authenticated(): read_topics = display_topics.filter(users_read_topic__in=[current_user.id]).scalar('id') else: read_topics = None # Find the links we want for the next/prev buttons if applicable. #next_page = url_for('forum.view_board', page=page + 1, **board.get_url_info()) if page < num_pages \ # else None #prev_page = url_for('forum.view_board', page=page - 1, **board.get_url_info()) if page > 1 and not num_pages == 1 \ # else None # Mash together a list of what pages we want linked to in the pagination bar. #links = [] #for page_mod in range(-min(PAGINATION_VALUE_RANGE, page - 1), min(PAGINATION_VALUE_RANGE, num_pages-page) + 1): # num = page + page_mod # links.append({'num': num, 'url': url_for('forum.view_board', page=num, **board.get_url_info()), 'active': (num == page)}) # Render it all out :D return render_template('forum_topics_display.html', board=board, forum=forum, topics=display_topics, read_topics=read_topics, forum_menu_current=board.id, **forum_template_data(forum))
def register_pool(username): if current_user.is_authenticated(): flash("You are already logged in. Log out to register another account.", category="alert") return redirect(url_for('static_pages.landing_page')) if User.objects(name=username).first() is not None: flash("This user is already registered.", category="alert") return redirect(url_for('auth.login')) #Is verified auth_check = check_authenticated_ip(request.remote_addr, username=username) if auth_check: form = RegistrationForm(request.form) if request.method == "GET": return render_template('register_3.html', username=username, form=form, title="Step 3 - Register") elif request.method == "POST": if form.validate(): uuid = auth_check.uuid.hex player = MinecraftPlayer.find_or_create_player(uuid, auth_check.username) user = User( name=username, hash=bcrypt.hashpw(form.password.data, bcrypt.gensalt()), mail=form.mail.data, minecraft_player=player) user.save() flash("Registration complete!", category="success") return redirect(url_for('auth.login')) return render_template('register_3.html', username=username, form=form, title="Step 3 - Register") #Is not verified else: if request.method == "GET": return render_template('register_2.html', username=username, title="Waiting... - Step 2 - Register") else: abort(405)
def view_topic(topic_id, topic_name, page): if page == 0: abort(404) topic_reply_form = TopicReplyForm() topic = Topic.objects(topic_url_id=topic_id).exclude().first() if topic is None: abort(404) if not topic_name == topic.get_url_name(): return redirect(topic.get_url()) if current_user.is_authenticated(): topic.update(add_to_set__users_read_topic=current_user.to_dbref()) board = topic.board forum = board.forum # Get our sorted posts and the number of posts. posts = Post.objects(topic=topic).order_by('+date') num_posts = len(posts) # Calculate the total number of pages and make sure the request is a valid page. num_pages = int(math.ceil(num_posts / float(POSTS_PER_PAGE))) if num_pages < page: if page == 1: return render_template('forum_topic_view.html', topic=topic, board=board, forum=forum, posts=posts, topic_reply_form=topic_reply_form, total_pages=num_pages, current_page=page, next=None, prev=None, links=[]) abort(404) # Compile the list of topics we want displayed. display_posts = posts.skip( (page - 1) * POSTS_PER_PAGE).limit(POSTS_PER_PAGE) # Find the links we want for the next/prev buttons if applicable. next_page = url_for( 'forum.view_topic', page=page + 1, **topic.get_url_info()) if page < num_pages else None prev_page = url_for( 'forum.view_topic', page=page - 1, **topic.get_url_info()) if page > 1 and not num_pages == 1 else None # Mash together a list of what pages we want linked to in the pagination bar. links = [] for page_mod in range(-min(PAGINATION_VALUE_RANGE, page - 1), min(PAGINATION_VALUE_RANGE, num_pages - page) + 1): num = page + page_mod links.append({ 'num': num, 'url': url_for('forum.view_topic', page=num, **topic.get_url_info()), 'active': (num == page) }) return render_template('forum_topic_view.html', topic=topic, board=board, forum=forum, posts=display_posts, topic_reply_form=topic_reply_form, total_pages=num_pages, current_page=page, next=next_page, prev=prev_page, links=links, markdown_escape=markdown_escape, post_edit=PostEditForm(), forum_menu_current=board.id, **forum_template_data(forum))
def register_start(): if current_user.is_authenticated(): flash("You are already logged in. Log out to register another account.", category="alert") return redirect(url_for('static_pages.landing_page')) return render_template('register_1.html', title="Step 1 - Register")
def view_topic(topic_id, topic_name, page): if page == 0: abort(404) topic_reply_form = TopicReplyForm() topic = Topic.objects(topic_url_id=topic_id).exclude().first() if topic is None: abort(404) if not topic_name == topic.get_url_name(): return redirect(topic.get_url()) if current_user.is_authenticated(): topic.update(add_to_set__users_read_topic=current_user.to_dbref()) board = topic.board forum = board.forum # Get our sorted posts and the number of posts. posts = Post.objects(topic=topic).order_by("+date") num_posts = len(posts) # Calculate the total number of pages and make sure the request is a valid page. num_pages = int(math.ceil(num_posts / float(POSTS_PER_PAGE))) if num_pages < page: if page == 1: return render_template( "forum_topic_view.html", topic=topic, board=board, forum=forum, posts=posts, topic_reply_form=topic_reply_form, total_pages=num_pages, current_page=page, next=None, prev=None, links=[], ) abort(404) # Compile the list of topics we want displayed. display_posts = posts.skip((page - 1) * POSTS_PER_PAGE).limit(POSTS_PER_PAGE) # Find the links we want for the next/prev buttons if applicable. next_page = url_for("forum.view_topic", page=page + 1, **topic.get_url_info()) if page < num_pages else None prev_page = ( url_for("forum.view_topic", page=page - 1, **topic.get_url_info()) if page > 1 and not num_pages == 1 else None ) # Mash together a list of what pages we want linked to in the pagination bar. links = [] for page_mod in range(-min(PAGINATION_VALUE_RANGE, page - 1), min(PAGINATION_VALUE_RANGE, num_pages - page) + 1): num = page + page_mod links.append( {"num": num, "url": url_for("forum.view_topic", page=num, **topic.get_url_info()), "active": (num == page)} ) return render_template( "forum_topic_view.html", topic=topic, board=board, forum=forum, posts=display_posts, topic_reply_form=topic_reply_form, total_pages=num_pages, current_page=page, next=next_page, prev=prev_page, links=links, markdown_escape=markdown_escape, post_edit=PostEditForm(), forum_menu_current=board.id, **forum_template_data(forum) )