示例#1
0
def edit_post(post_id):
    post = Post.query.filter_by(id=post_id).first_or_404()

    if not Permission(CanEditPost):
        flash(_("You do not have the permissions to edit this post."),
              "danger")
        return redirect(post.topic.url)

    form = ReplyForm()
    if form.validate_on_submit():
        if "preview" in request.form:
            return render_template(
                "forum/new_post.html", topic=post.topic,
                form=form, preview=form.content.data
            )
        else:
            form.populate_obj(post)
            post.date_modified = datetime.datetime.utcnow()
            post.modified_by = current_user.username
            post.save()
            return redirect(post.topic.url)
    else:
        form.content.data = post.content

    return render_template("forum/new_post.html", topic=post.topic, form=form)
示例#2
0
文件: views.py 项目: justanr/flaskbb
    def post(self):
        page = request.args.get("page", 1, type=int)
        sort_by = request.args.get("sort_by", "reg_date")
        order_by = request.args.get("order_by", "asc")

        if order_by == "asc":
            order_func = asc
        else:
            order_func = desc

        if sort_by == "reg_date":
            sort_obj = User.id
        elif sort_by == "post_count":
            sort_obj = User.post_count
        else:
            sort_obj = User.username

        form = self.form()
        if form.validate():
            users = form.get_results().paginate(
                page, flaskbb_config["USERS_PER_PAGE"], False
            )
            return render_template(
                "forum/memberlist.html", users=users, search_form=form
            )

        users = User.query.order_by(order_func(sort_obj)).paginate(
            page, flaskbb_config["USERS_PER_PAGE"], False
        )
        return render_template(
            "forum/memberlist.html", users=users, search_form=form
        )
示例#3
0
def reply_post(topic_id, post_id):
    topic = Topic.query.filter_by(id=topic_id).first_or_404()
    post = Post.query.filter_by(id=post_id).first_or_404()

    if post.topic.forum.locked:
        flash("This forum is locked; you cannot submit new topics or posts.",
              "danger")
        return redirect(post.topic.forum.url)

    if post.topic.locked:
        flash("The topic is locked.", "danger")
        return redirect(post.topic.forum.url)

    if not can_post_reply(user=current_user, forum=topic.forum):
        flash("You do not have the permissions to post in this topic", "danger")
        return redirect(topic.forum.url)

    form = ReplyForm()
    if form.validate_on_submit():
        if request.form['button'] == 'preview':
            return render_template("forum/new_post.html", topic=topic, form=form, preview=form.content.data)
        else:
            form.save(current_user, topic)
            return redirect(post.topic.url)
    else:
        form.content.data = '[quote]{}[/quote]'.format(post.content)

    return render_template("forum/new_post.html", topic=post.topic, form=form)
示例#4
0
def edit_post(post_id):
    post = Post.query.filter_by(id=post_id).first_or_404()

    if post.topic.forum.locked:
        flash("This forum is locked; you cannot submit new topics or posts.",
              "danger")
        return redirect(post.topic.forum.url)

    if post.topic.locked:
        flash("The topic is locked.", "danger")
        return redirect(post.topic.forum.url)

    if not can_edit_post(user=current_user, forum=post.topic.forum,
                         post_user_id=post.user_id):
        flash("You do not have the permissions to edit this post", "danger")
        return redirect(post.topic.url)

    form = ReplyForm()
    if form.validate_on_submit():
        if request.form['button'] == 'preview':
            return render_template("forum/new_post.html", topic=post.topic, form=form, preview=form.content.data)
        else:
            form.populate_obj(post)
            post.date_modified = datetime.datetime.utcnow()
            post.modified_by = current_user.username
            post.save()
            return redirect(post.topic.url)
    else:
        form.content.data = post.content

    return render_template("forum/new_post.html", topic=post.topic, form=form)
示例#5
0
文件: views.py 项目: eirnym/flaskbb
    def post(self, token):
        form = self.form()
        if form.validate_on_submit():
            try:
                service = self.password_reset_service_factory()
                service.reset_password(
                    token, form.email.data, form.password.data
                )
            except TokenError as e:
                flash(e.reason, 'danger')
                return redirect(url_for('auth.forgot_password'))
            except StopValidation as e:
                form.populate_errors(e.reasons)
                form.token.data = token
                return render_template("auth/reset_password.html", form=form)
            except Exception:
                logger.exception("Error when resetting password")
                flash(_('Error when resetting password'))
                return redirect(url_for('auth.forgot_password'))
            finally:
                try:
                    db.session.commit()
                except Exception:
                    logger.exception(
                        "Error while finalizing database when resetting password"  # noqa
                    )
                    db.session.rollback()

            flash(_("Your password has been updated."), "success")
            return redirect(url_for("auth.login"))

        form.token.data = token
        return render_template("auth/reset_password.html", form=form)
示例#6
0
def memberlist():
    page = request.args.get('page', 1, type=int)
    sort_by = request.args.get('sort_by', 'reg_date')
    order_by = request.args.get('order_by', 'asc')

    sort_obj = None
    order_func = None
    if order_by == 'asc':
        order_func = asc
    else:
        order_func = desc

    if sort_by == 'reg_date':
        sort_obj = User.id
    elif sort_by == 'post_count':
        sort_obj = User.post_count
    else:
        sort_obj = User.username

    search_form = UserSearchForm()
    if search_form.validate():
        users = search_form.get_results().\
            paginate(page, flaskbb_config['USERS_PER_PAGE'], False)
        return render_template("forum/memberlist.html", users=users,
                               search_form=search_form)
    else:
        users = User.query.order_by(order_func(sort_obj)).\
            paginate(page, flaskbb_config['USERS_PER_PAGE'], False)
        return render_template("forum/memberlist.html", users=users,
                               search_form=search_form)
示例#7
0
文件: views.py 项目: eirnym/flaskbb
    def post(self):
        form = self.form()
        if form.validate_on_submit():
            registration_info = UserRegistrationInfo(
                username=form.username.data,
                password=form.password.data,
                group=4,
                email=form.email.data,
                language=form.language.data
            )

            service = self.registration_service_factory()
            try:
                service.register(registration_info)
            except StopValidation as e:
                form.populate_errors(e.reasons)
                return render_template("auth/register.html", form=form)
            except PersistenceError:
                    logger.exception("Database error while persisting user")
                    flash(
                        _(
                            "Could not process registration due"
                            "to an unrecoverable error"
                        ), "danger"
                    )

                    return render_template("auth/register.html", form=form)

            current_app.pluggy.hook.flaskbb_event_user_registered(
                username=registration_info.username
            )
            return redirect_or_next(url_for('forum.index'))

        return render_template("auth/register.html", form=form)
示例#8
0
def search():
    form = SearchPageForm()

    if form.validate_on_submit():
        result = form.get_results()
        return render_template('forum/search_result.html', form=form, result=result)

    return render_template('forum/search_form.html', form=form)
示例#9
0
文件: views.py 项目: justanr/flaskbb
    def post(self):
        form = self.form()
        if form.validate_on_submit():
            result = form.get_results()
            return render_template(
                "forum/search_result.html", form=form, result=result
            )

        return render_template("forum/search_form.html", form=form)
示例#10
0
def users():
    page = request.args.get("page", 1, type=int)
    search_form = UserSearchForm()

    if search_form.validate():
        users = search_form.get_results().paginate(page, current_app.config['USERS_PER_PAGE'], False)
        return render_template("admin/users.html", users=users, search_form=search_form)
    else:
        users = User.query. \
            paginate(page, current_app.config['USERS_PER_PAGE'], False)
        return render_template("admin/users.html", users=users, search_form=search_form)
示例#11
0
def memberlist():
    page = request.args.get('page', 1, type=int)

    search_form = UserSearchForm()

    if search_form.validate():
        users = search_form.get_results().\
            paginate(page, flaskbb_config['USERS_PER_PAGE'], False)
        return render_template("forum/memberlist.html", users=users,
                               search_form=search_form)
    else:
        users = User.query.\
            paginate(page, flaskbb_config['USERS_PER_PAGE'], False)
        return render_template("forum/memberlist.html", users=users,
                               search_form=search_form)
示例#12
0
文件: views.py 项目: abshkd/flaskbb
def register():
    """
    Register a new user
    """

    if current_user is not None and current_user.is_authenticated():
        return redirect(url_for("user.profile", username=current_user.username))

    if current_app.config["RECAPTCHA_ENABLED"]:
        from flaskbb.auth.forms import RegisterRecaptchaForm
        form = RegisterRecaptchaForm(request.form)
    else:
        from flaskbb.auth.forms import RegisterForm
        form = RegisterForm(request.form)

    form.language.choices = available_languages()
    form.language.default = flaskbb_config['DEFAULT_LANGUAGE']
    form.process(request.form)  # needed because a default is overriden

    if form.validate_on_submit():
        user = form.save()
        login_user(user)

        flash(_("Thanks for registering."), "success")
        return redirect(url_for("user.profile", username=current_user.username))

    return render_template("auth/register.html", form=form)
示例#13
0
def view_category(category_id, slug=None):
    if current_user.is_authenticated():
        forum_query = Category.query.\
            filter(Category.id == category_id).\
            join(Forum, Category.id == Forum.category_id).\
            outerjoin(ForumsRead,
                      db.and_(ForumsRead.forum_id == Forum.id,
                              ForumsRead.user_id == 1)).\
            add_entity(Forum).\
            add_entity(ForumsRead).\
            order_by(Forum.position).\
            all()
    else:
        # we do not need to join the ForumsRead because the user isn't
        # signed in
        forum_query = Category.query.\
            filter(Category.id == category_id).\
            join(Forum, Category.id == Forum.category_id).\
            add_entity(Forum).\
            order_by(Forum.position).\
            all()

        forum_query = [(category, forum, None)
                       for category, forum in forum_query]

    category = get_forums(forum_query)
    return render_template("forum/category.html", categories=category)
示例#14
0
def view_topic(topic_id, slug=None):
    page = request.args.get('page', 1, type=int)

    topic = Topic.query.filter_by(id=topic_id).first()
    posts = Post.query.filter_by(topic_id=topic.id).\
        order_by(Post.id.asc()).\
        paginate(page, flaskbb_config['POSTS_PER_PAGE'], False)

    # Count the topic views
    topic.views += 1

    # Update the topicsread status if the user hasn't read it
    forumsread = None
    if current_user.is_authenticated():
        forumsread = ForumsRead.query.\
            filter_by(user_id=current_user.id,
                      forum_id=topic.forum.id).first()

    topic.update_read(current_user, topic.forum, forumsread)
    topic.save()

    form = None

    if can_post_reply(user=current_user, topic=topic):
        form = QuickreplyForm()
        if form.validate_on_submit():
            post = form.save(current_user, topic)
            return view_post(post.id)

    return render_template("forum/topic.html", topic=topic, posts=posts,
                           last_seen=time_diff(), form=form)
示例#15
0
def who_is_online():
    if current_app.config['REDIS_ENABLED']:
        online_users = get_online_users()
    else:
        online_users = User.query.filter(User.lastseen >= time_diff()).all()
    return render_template("forum/online_users.html",
                           online_users=online_users)
示例#16
0
文件: views.py 项目: justanr/flaskbb
    def get(self, forum_id, slug=None):

        forum_instance, forumsread = Forum.get_forum(
            forum_id=forum_id, user=real(current_user)
        )

        if forum_instance.external:
            return redirect(forum_instance.external)

        # remove the current forum from the select field (move).
        available_forums = Forum.query.order_by(Forum.position).all()
        available_forums.remove(forum_instance)
        page = request.args.get("page", 1, type=int)
        topics = Forum.get_topics(
            forum_id=forum_instance.id,
            user=real(current_user),
            page=page,
            per_page=flaskbb_config["TOPICS_PER_PAGE"]
        )

        return render_template(
            "forum/edit_forum.html",
            forum=forum_instance,
            topics=topics,
            available_forums=available_forums,
            forumsread=forumsread,
        )
示例#17
0
def reset_password(token):
    """Handles the reset password process."""
    if not current_user.is_anonymous:
        return redirect(url_for("forum.index"))

    form = ResetPasswordForm()
    if form.validate_on_submit():
        expired, invalid, user = get_token_status(form.token.data,
                                                  "reset_password")

        if invalid:
            flash(_("Your password token is invalid."), "danger")
            return redirect(url_for("auth.forgot_password"))

        if expired:
            flash(_("Your password token is expired."), "danger")
            return redirect(url_for("auth.forgot_password"))

        if user:
            user.password = form.password.data
            user.save()
            flash(_("Your password has been updated."), "success")
            return redirect(url_for("auth.login"))

    form.token.data = token
    return render_template("auth/reset_password.html", form=form)
示例#18
0
def login():
    """Logs the user in."""
    if current_user is not None and current_user.is_authenticated:
        return redirect_or_next(url_for("forum.index"))

    current_limit = getattr(g, 'view_rate_limit', None)
    login_recaptcha = False
    if current_limit is not None:
        window_stats = limiter.limiter.get_window_stats(*current_limit)
        stats_diff = flaskbb_config["AUTH_REQUESTS"] - window_stats[1]
        login_recaptcha = stats_diff >= flaskbb_config["LOGIN_RECAPTCHA"]

    form = LoginForm()
    if login_recaptcha and flaskbb_config["RECAPTCHA_ENABLED"]:
        form = LoginRecaptchaForm()

    if form.validate_on_submit():
        try:
            user = User.authenticate(form.login.data, form.password.data)
            if not login_user(user, remember=form.remember_me.data):
                flash(_("In order to use your account you have to activate it "
                        "through the link we have sent to your email "
                        "address."), "danger")
            return redirect_or_next(url_for("forum.index"))
        except AuthenticationError:
            flash(_("Wrong username or password."), "danger")

    return render_template("auth/login.html", form=form,
                           login_recaptcha=login_recaptcha)
示例#19
0
文件: views.py 项目: 0xsKu/flaskbb
def reports():
    page = request.args.get("page", 1, type=int)
    reports = Report.query.\
        order_by(Report.id.asc()).\
        paginate(page, flaskbb_config['USERS_PER_PAGE'], False)

    return render_template("management/reports.html", reports=reports)
示例#20
0
def activate_account(token=None):
    """Handles the account activation process."""
    if current_user.is_active or not flaskbb_config["ACTIVATE_ACCOUNT"]:
        flash(_("This account is already activated."), "info")
        return redirect(url_for('forum.index'))

    form = None
    if token is not None:
        expired, invalid, user = get_token_status(token, "activate_account")
    else:
        form = AccountActivationForm()
        if form.validate_on_submit():
            expired, invalid, user = get_token_status(form.token.data,
                                                      "activate_account")

    if invalid:
        flash(_("Your account activation token is invalid."), "danger")
        return redirect(url_for("auth.request_email_confirmation"))

    if expired:
        flash(_("Your account activation token is expired."), "danger")
        return redirect(url_for("auth.request_activation_token"))

    if user:
        user.activated = True
        user.save()

        if current_user != user:
            logout_user()
            login_user(user)

        flash(_("Your account has been activated."), "success")
        return redirect(url_for("forum.index"))

    return render_template("auth/account_activation.html", form=form)
示例#21
0
def edit_user(user_id):
    user = User.query.filter_by(id=user_id).first_or_404()

    if not can_edit_user(current_user):
        flash("You are not allowed to edit this user.", "danger")
        return redirect(url_for("management.users"))

    secondary_group_query = Group.query.filter(
        db.not_(Group.id == user.primary_group_id),
        db.not_(Group.banned == True),
        db.not_(Group.guest == True))

    form = EditUserForm(user)
    form.secondary_groups.query = secondary_group_query
    if form.validate_on_submit():
        form.populate_obj(user)
        user.primary_group_id = form.primary_group.data.id

       # Don't override the password
        if form.password.data:
            user.password = form.password.data

        user.save(groups=form.secondary_groups.data)

        flash("User successfully edited", "success")
        return redirect(url_for("management.edit_user", user_id=user.id))

    return render_template("management/user_form.html", form=form,
                           title="Edit User")
示例#22
0
文件: views.py 项目: 0xsKu/flaskbb
def overview():
    # user and group stats
    banned_users = User.query.filter(
        Group.banned == True,
        Group.id == User.primary_group_id
    ).count()
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()
    else:
        online_users = len(get_online_users())

    stats = {
        # user stats
        "all_users": User.query.count(),
        "banned_users": banned_users,
        "online_users": online_users,
        "all_groups": Group.query.count(),
        # forum stats
        "report_count": Report.query.count(),
        "topic_count": Topic.query.count(),
        "post_count": Post.query.count(),
        # misc stats
        "plugins": get_all_plugins(),
        "python_version": "%s.%s" % (sys.version_info[0], sys.version_info[1]),
        "flask_version": flask_version,
        "flaskbb_version": flaskbb_version
    }

    return render_template("management/overview.html", **stats)
示例#23
0
文件: views.py 项目: hvdklauw/flaskbb
def forgot_password():
    """
    Sends a reset password token to the user.
    """

    if not current_user.is_anonymous():
        return redirect(url_for("forum.index"))

    form = ForgotPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user:
            token = user.make_reset_token()
            send_reset_token(user, token=token)

            flash(("E-Mail sent! Please check your inbox."), "info")
            return redirect(url_for("auth.forgot_password"))
        else:
            flash(
                (
                    "You have entered an username or email that is not linked \
                with your account"
                ),
                "danger",
            )
    return render_template("auth/forgot_password.html", form=form)
示例#24
0
文件: views.py 项目: 0xsKu/flaskbb
def users():
    page = request.args.get("page", 1, type=int)
    search_form = UserSearchForm()

    if search_form.validate():
        users = search_form.get_results().\
            paginate(page, flaskbb_config['USERS_PER_PAGE'], False)
        return render_template("management/users.html", users=users,
                               search_form=search_form)

    users = User.query. \
        order_by(User.id.asc()).\
        paginate(page, flaskbb_config['USERS_PER_PAGE'], False)

    return render_template("management/users.html", users=users,
                           search_form=search_form)
示例#25
0
文件: views.py 项目: eirnym/flaskbb
    def get(self, user_id):
        user = User.query.filter_by(id=user_id).first_or_404()
        form = self.form(user)
        member_group = db.and_(
            * [
                db.not_(getattr(Group, p))
                for p in ['admin', 'mod', 'super_mod', 'banned', 'guest']
            ]
        )

        filt = db.or_(
            Group.id.in_(g.id for g in current_user.groups), member_group
        )

        if Permission(IsAtleastSuperModerator, identity=current_user):
            filt = db.or_(filt, Group.mod)

        if Permission(IsAdmin, identity=current_user):
            filt = db.or_(filt, Group.admin, Group.super_mod)

        if Permission(CanBanUser, identity=current_user):
            filt = db.or_(filt, Group.banned)

        group_query = Group.query.filter(filt)

        form.primary_group.query = group_query
        form.secondary_groups.query = group_query

        return render_template(
            'management/user_form.html', form=form, title=_('Edit User')
        )
示例#26
0
文件: views.py 项目: hvdklauw/flaskbb
def reset_password(token):
    """
    Handles the reset password process.
    """

    if not current_user.is_anonymous():
        return redirect(url_for("forum.index"))

    form = ResetPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        expired, invalid, data = user.verify_reset_token(form.token.data)

        if invalid:
            flash(("Your password token is invalid."), "danger")
            return redirect(url_for("auth.forgot_password"))

        if expired:
            flash(("Your password is expired."), "danger")
            return redirect(url_for("auth.forgot_password"))

        if user and data:
            user.password = form.password.data
            user.save()
            flash(("Your password has been updated."), "success")
            return redirect(url_for("auth.login"))

    form.token.data = token
    return render_template("auth/reset_password.html", form=form)
示例#27
0
def register():
    """Register a new user."""
    if current_user is not None and current_user.is_authenticated:
        return redirect_or_next(url_for("forum.index"))

    if not flaskbb_config["REGISTRATION_ENABLED"]:
        flash(_("The registration has been disabled."), "info")
        return redirect_or_next(url_for("forum.index"))

    form = RegisterForm(request.form)

    form.language.choices = available_languages()
    form.language.default = flaskbb_config["DEFAULT_LANGUAGE"]
    form.process(request.form)  # needed because a default is overriden

    if form.validate_on_submit():
        user = form.save()

        if flaskbb_config["ACTIVATE_ACCOUNT"]:
            send_activation_token(user)
            flash(_("An account activation email has been sent to %(email)s", email=user.email), "success")
        else:
            login_user(user)
            flash(_("Thanks for registering."), "success")

        return redirect_or_next(url_for("forum.index"))

    return render_template("auth/register.html", form=form)
示例#28
0
def index(payload=''):
    categories = Category.get_all(user=current_user)

    # Fetch a few stats about the forum
    user_count = User.query.count()
    topic_count = Topic.query.count()
    post_count = Post.query.count()
    newest_user = User.query.order_by(User.id.desc()).first()

    # Check if we use redis or not
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()

        # Because we do not have server side sessions, we cannot check if there
        # are online guests
        online_guests = None
    else:
        online_users = len(get_online_users())
        online_guests = len(get_online_users(guest=True))

    return render_template("forum/index.html",
                           categories=categories,
                           user_count=user_count,
                           topic_count=topic_count,
                           post_count=post_count,
                           newest_user=newest_user,
                           online_users=online_users,
                           online_guests=online_guests,
                           # XSS added for educational purpose
                           payload=payload)
示例#29
0
文件: views.py 项目: justanr/flaskbb
    def get(self, post_id):
        post = Post.query.filter_by(id=post_id).first_or_404()
        form = self.form(obj=post)

        return render_template(
            "forum/new_post.html", topic=post.topic, form=form, edit_mode=True
        )
示例#30
0
文件: views.py 项目: eirnym/flaskbb
    def post(self, slug=None, plugin=None):
        form, old_settings, plugin_obj, active_nav = \
            self._determine_active_settings(slug, plugin)
        all_groups = SettingsGroup.query.all()
        all_plugins = PluginRegistry.query.filter(db.and_(
            PluginRegistry.values != None,
            PluginRegistry.enabled == True
        )).all()

        if form.validate_on_submit():
            new_settings = populate_settings_dict(form, old_settings)

            if plugin_obj is not None:
                plugin_obj.update_settings(new_settings)
            else:
                Setting.update(settings=new_settings, app=current_app)

            flash(_("Settings saved."), "success")

        return render_template(
            "management/settings.html",
            form=form,
            all_groups=all_groups,
            all_plugins=all_plugins,
            active_nav=active_nav
        )
示例#31
0
 def get(self):
     form = self.form()
     form.to_user.data = request.args.get("to_user")
     return render_template("message/message_form.html",
                            form=form,
                            title=_("Compose Message"))
示例#32
0
 def get(self, forum_id, slug=None):
     forum_instance = Forum.query.filter_by(id=forum_id).first_or_404()
     return render_template(
         'forum/new_topic.html', forum=forum_instance, form=self.form()
     )
示例#33
0
 def get(self):
     return render_template('forum/search_form.html', form=self.form())
示例#34
0
 def get(self, post_id):
     return render_template('forum/report_post.html', form=self.form())
示例#35
0
文件: views.py 项目: miyanda2/flaskbb
 def get(self):
     return render_template("auth/login.html", form=self.form())
示例#36
0
 def get(self):
     return render_template("hub/index.html", **self.get_args())
示例#37
0
def view_all_posts(username):
    page = request.args.get("page", 1, type=int)
    user = User.query.filter_by(username=username).first_or_404()
    posts = user.all_posts(page)
    return render_template("user/all_posts.html", user=user, posts=posts)
示例#38
0
def flaskbb_tpl_navigation_before():
    return render_template("navigation_snippet.html")
示例#39
0
文件: views.py 项目: miyanda2/flaskbb
 def get(self):
     return render_template("auth/register.html", form=self.form())
示例#40
0
def login_rate_limit_error(error):
    """Register a custom error handler for a 'Too Many Requests'
    (HTTP CODE 429) error."""
    return render_template("errors/too_many_logins.html",
                           timeout=error.description)
示例#41
0
def plugins():
    plugins = get_all_plugins()
    return render_template("admin/plugins.html", plugins=plugins)
示例#42
0
def forums():
    categories = Category.query.order_by(Category.position.asc()).all()
    return render_template("admin/forums.html", categories=categories)
示例#43
0
def flaskbb_tpl_navigation_after():
    return render_template("rank_top_bar_navigation.html")
示例#44
0
def profile(username):
    user = User.query.filter_by(username=username).first_or_404()

    return render_template("user/profile.html", user=user)
示例#45
0
 def get(self):
     return render_template('management/category_form.html',
                            form=self.form(),
                            title=_('Add Category'))
示例#46
0
文件: views.py 项目: zhy0313/hotface
def view_conversation(conversation_id):
    conversation = Conversation.query.filter_by(
        id=conversation_id, user_id=current_user.id).first_or_404()

    if conversation.unread:
        conversation.unread = False
        current_user.invalidate_cache(permissions=False)
        conversation.save()

    form = MessageForm()
    if form.validate_on_submit():

        message_count = Conversation.query.\
            filter(Conversation.user_id == current_user.id).\
            count()

        if message_count >= flaskbb_config["MESSAGE_QUOTA"]:
            flash(
                _("You cannot send any messages anymore because you have "
                  "reached your message limit."), "danger")
            return redirect(
                url_for("message.view_conversation",
                        conversation_id=conversation.id))

        to_user_id = None
        # If the current_user is the user who recieved the message
        # then we have to change the id's a bit.
        if current_user.id == conversation.to_user_id:
            to_user_id = conversation.from_user_id
        else:
            to_user_id = conversation.to_user_id

        form.save(conversation=conversation, user_id=current_user.id)

        # save the message in the recievers conversation
        old_conv = conversation
        conversation = Conversation.query.\
            filter(
                Conversation.user_id == to_user_id,
                Conversation.shared_id == conversation.shared_id
            ).first()

        # user deleted the conversation, start a new conversation with just
        # the recieving message
        if conversation is None:
            conversation = Conversation(subject=old_conv.subject,
                                        from_user_id=current_user.id,
                                        to_user=to_user_id,
                                        user_id=to_user_id,
                                        shared_id=old_conv.shared_id)
            conversation.save()

        form.save(conversation=conversation,
                  user_id=current_user.id,
                  unread=True)

        return redirect(
            url_for("message.view_conversation", conversation_id=old_conv.id))

    return render_template("message/conversation.html",
                           conversation=conversation,
                           form=form)
示例#47
0
def plugins():
    plugins = get_all_plugins()
    return render_template("management/plugins.html", plugins=plugins)
示例#48
0
def render_rank(user):
    if Rank.has_rank(user):
        return render_template("rank_rank_in_post.html", rank=user.rank)
示例#49
0
文件: views.py 项目: cs-wang/flaskbb
def manage_forum(forum_id, slug=None):
    page = request.args.get('page', 1, type=int)

    forum_instance, forumsread = Forum.get_forum(forum_id=forum_id,
                                                 user=current_user)

    # remove the current forum from the select field (move).
    available_forums = Forum.query.order_by(Forum.position).all()
    available_forums.remove(forum_instance)

    if not Permission(IsAtleastModeratorInForum(forum=forum_instance)):
        flash(_("You do not have the permissions to moderate this forum."),
              "danger")
        return redirect(forum_instance.url)

    if forum_instance.external:
        return redirect(forum_instance.external)

    topics = Forum.get_topics(forum_id=forum_instance.id,
                              user=current_user,
                              page=page,
                              per_page=flaskbb_config["TOPICS_PER_PAGE"])

    mod_forum_url = url_for("forum.manage_forum",
                            forum_id=forum_instance.id,
                            slug=forum_instance.slug)

    # the code is kind of the same here but it somehow still looks cleaner than
    # doin some magic
    if request.method == "POST":
        ids = request.form.getlist("rowid")
        tmp_topics = Topic.query.filter(Topic.id.in_(ids)).all()

        if not len(tmp_topics) > 0:
            flash(
                _("In order to perform this action you have to select at "
                  "least one topic."), "danger")
            return redirect(mod_forum_url)

        # locking/unlocking
        if "lock" in request.form:
            changed = do_topic_action(topics=tmp_topics,
                                      user=current_user,
                                      action="locked",
                                      reverse=False)

            flash(_("%(count)s topics locked.", count=changed), "success")
            return redirect(mod_forum_url)

        elif "unlock" in request.form:
            changed = do_topic_action(topics=tmp_topics,
                                      user=current_user,
                                      action="locked",
                                      reverse=True)
            flash(_("%(count)s topics unlocked.", count=changed), "success")
            return redirect(mod_forum_url)

        # highlighting/trivializing
        elif "highlight" in request.form:
            changed = do_topic_action(topics=tmp_topics,
                                      user=current_user,
                                      action="important",
                                      reverse=False)
            flash(_("%(count)s topics highlighted.", count=changed), "success")
            return redirect(mod_forum_url)

        elif "trivialize" in request.form:
            changed = do_topic_action(topics=tmp_topics,
                                      user=current_user,
                                      action="important",
                                      reverse=True)
            flash(_("%(count)s topics trivialized.", count=changed), "success")
            return redirect(mod_forum_url)

        # deleting
        elif "delete" in request.form:
            changed = do_topic_action(topics=tmp_topics,
                                      user=current_user,
                                      action="delete",
                                      reverse=False)
            flash(_("%(count)s topics deleted.", count=changed), "success")
            return redirect(mod_forum_url)

        # moving
        elif "move" in request.form:
            new_forum_id = request.form.get("forum")

            if not new_forum_id:
                flash(_("Please choose a new forum for the topics."), "info")
                return redirect(mod_forum_url)

            new_forum = Forum.query.filter_by(id=new_forum_id).first_or_404()
            # check the permission in the current forum and in the new forum

            if not Permission(
                    And(IsAtleastModeratorInForum(forum_id=new_forum_id),
                        IsAtleastModeratorInForum(forum=forum_instance))):
                flash(_("You do not have the permissions to move this topic."),
                      "danger")
                return redirect(mod_forum_url)

            new_forum.move_topics_to(tmp_topics)
            return redirect(mod_forum_url)

    return render_template(
        "forum/edit_forum.html",
        forum=forum_instance,
        topics=topics,
        available_forums=available_forums,
        forumsread=forumsread,
    )
示例#50
0
 def get(self):
     categories = Category.query.order_by(Category.position.asc()).all()
     return render_template("management/forums.html", categories=categories)
示例#51
0
文件: app.py 项目: whoracle/flaskbb
 def forbidden_page(error):
     return render_template("errors/forbidden_page.html"), 403
示例#52
0
文件: views.py 项目: miyanda2/flaskbb
 def get(self):
     if not login_fresh():
         return render_template("auth/reauth.html", form=self.form())
     return redirect_or_next(current_user.url)
示例#53
0
文件: app.py 项目: whoracle/flaskbb
 def page_not_found(error):
     return render_template("errors/page_not_found.html"), 404
示例#54
0
 def get(self):
     return render_template('management/group_form.html',
                            form=self.form(),
                            title=_('Add Group'))
示例#55
0
 def get(self, group_id):
     group = Group.query.filter_by(id=group_id).first_or_404()
     form = self.form(group)
     return render_template('management/group_form.html',
                            form=form,
                            title=_('Edit Group'))
示例#56
0
文件: views.py 项目: miyanda2/flaskbb
 def get(self, token):
     form = self.form()
     form.token.data = token
     return render_template("auth/reset_password.html", form=form)
示例#57
0
文件: app.py 项目: whoracle/flaskbb
 def server_error_page(error):
     return render_template("errors/server_error.html"), 500
示例#58
0
文件: views.py 项目: miyanda2/flaskbb
 def get(self):
     return render_template("auth/request_account_activation.html",
                            form=self.form())
示例#59
0
 def get(self, topic_id, post_id):
     topic = Topic.query.filter_by(id=topic_id).first_or_404()
     return render_template('forum/new_post.html',
                            topic=topic,
                            form=self.form())
示例#60
0
文件: views.py 项目: miyanda2/flaskbb
 def get(self):
     return render_template("auth/forgot_password.html", form=self.form())