Esempio n. 1
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, flask_config["USERS_PER_PAGE"], False)
        return render_template("management/users.html", users=users, search_form=search_form)

    users = jnt_models.User.query.order_by(jnt_models.User.id.asc()).paginate(
        page, flask_config["USERS_PER_PAGE"], False
    )

    return render_template("management/users.html", users=users, search_form=search_form)
Esempio n. 2
0
def banned_users():
    page = request.args.get("page", 1, type=int)
    search_form = UserSearchForm()

    users = jnt_models.User.query.filter(
        jnt_models.Group.banned == True, jnt_models.Group.id == jnt_models.User.primary_group_id
    ).paginate(page, flask_config["USERS_PER_PAGE"], False)

    if search_form.validate():
        users = search_form.get_results().paginate(page, flask_config["USERS_PER_PAGE"], False)

        return render_template("management/banned_users.html", users=users, search_form=search_form)

    return render_template("management/banned_users.html", users=users, search_form=search_form)
Esempio n. 3
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():
        user = UserMan.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 Token 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)
Esempio n. 4
0
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 janitoo_manager.auth.forms import RegisterRecaptchaForm
        form = RegisterRecaptchaForm(request.form)
    else:
        from janitoo_manager.auth.forms import RegisterForm
        form = RegisterForm(request.form)

    form.language.choices = available_languages()
    form.language.default = flask_config['DEFAULT_LANGUAGE']
    form.process()  # 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)
Esempio n. 5
0
def settings(slug=None):
    slug = slug if slug else "general"

    # get the currently active group
    active_group = jnt_models.SettingsGroup.query.filter_by(key=slug).first_or_404()
    # get all groups - used to build the navigation
    all_groups = jnt_models.SettingsGroup.query.all()

    SettingsForm = jnt_models.Setting.get_form(active_group)

    old_settings = jnt_models.Setting.get_settings(active_group)
    new_settings = {}

    form = SettingsForm()

    if form.validate_on_submit():
        for key, values in iteritems(old_settings):
            try:
                # check if the value has changed
                if values["value"] == form[key].data:
                    continue
                else:
                    new_settings[key] = form[key].data
            except KeyError:
                pass
        jnt_models.Setting.update(settings=new_settings, app=current_app)
        flash(_("Settings saved."), "success")
    else:
        for key, values in iteritems(old_settings):
            try:
                form[key].data = values["value"]
            except (KeyError, ValueError):
                pass

    return render_template("management/settings.html", form=form, all_groups=all_groups, active_group=active_group)
Esempio n. 6
0
def add_group():
    form = AddGroupForm()
    if form.validate_on_submit():
        form.save()
        flash(_("Group successfully added."), "success")
        return redirect(url_for("management.groups"))

    return render_template("management/group_form.html", form=form, title=_("Add Group"))
Esempio n. 7
0
def groups():
    page = request.args.get("page", 1, type=int)

    groups = jnt_models.Group.query.order_by(jnt_models.Group.id.asc()).paginate(
        page, flask_config["USERS_PER_PAGE"], False
    )

    return render_template("management/groups.html", groups=groups)
Esempio n. 8
0
def change_email():
    form = ChangeEmailForm(current_user)
    if form.validate_on_submit():
        current_user.email = form.new_email.data
        current_user.save()

        flash(_("E-Mail Address updated."), "success")
    return render_template("user/change_email.html", form=form)
Esempio n. 9
0
def add_user():
    form = AddUserForm()
    if form.validate_on_submit():
        form.save()
        flash(_("User successfully added."), "success")
        return redirect(url_for("management.users"))

    return render_template("management/user_form.html", form=form, title=_("Add User"))
Esempio n. 10
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        current_user.password = form.new_password.data
        current_user.save()

        flash(_("Password updated."), "success")
    return render_template("user/change_password.html", form=form)
Esempio n. 11
0
def unread_reports():
    page = request.args.get("page", 1, type=int)
    reports = (
        Report.query.filter(Report.zapped == None)
        .order_by(Report.id.desc())
        .paginate(page, flask_config["USERS_PER_PAGE"], False)
    )

    return render_template("management/unread_reports.html", reports=reports)
Esempio n. 12
0
def add_category():
    form = CategoryForm()

    if form.validate_on_submit():
        form.save()
        flash(_("Category successfully added."), "success")
        return redirect(url_for("management.forums"))

    return render_template("management/category_form.html", form=form, title=_("Add Category"))
Esempio n. 13
0
def change_user_details():
    form = ChangeUserDetailsForm(obj=current_user)

    if form.validate_on_submit():
        form.populate_obj(current_user)
        current_user.save()

        flash(_("Details updated."), "success")

    return render_template("user/change_user_details.html", form=form)
Esempio n. 14
0
def edit_category(category_id):
    category = jnt_models.Category.query.filter_by(id=category_id).first_or_404()

    form = CategoryForm(obj=category)

    if form.validate_on_submit():
        form.populate_obj(category)
        flash(_("Category successfully updated."), "success")
        category.save()

    return render_template("management/category_form.html", form=form, title=_("Edit Category"))
Esempio n. 15
0
def add_forum(category_id=None):
    form = AddForumForm()

    if form.validate_on_submit():
        form.save()
        flash(_("Forum successfully added."), "success")
        return redirect(url_for("management.forums"))
    else:
        form.groups.data = jnt_models.Group.query.order_by(jnt_models.Group.id.asc()).all()
        if category_id:
            category = jnt_models.Category.query.filter_by(id=category_id).first()
            form.category.data = category

    return render_template("management/forum_form.html", form=form, title=_("Add Forum"))
Esempio n. 16
0
def overview():
    python_version = "%s.%s" % (sys.version_info[0], sys.version_info[1])
    user_count = jnt_models.User.query.count()
    topic_count = Topic.query.count()
    post_count = Post.query.count()
    return render_template(
        "management/overview.html",
        python_version=python_version,
        flask_version=flask_version,
        janitoo_manager_version=janitoo_manager_version,
        user_count=user_count,
        topic_count=topic_count,
        post_count=post_count,
    )
Esempio n. 17
0
def reauth():
    """
    Reauthenticates a user
    """

    if not login_fresh():
        form = ReauthForm(request.form)
        if form.validate_on_submit():
            confirm_login()
            flash(_("Reauthenticated."), "success")
            return redirect(request.args.get("next") or
                            url_for("user.profile"))
        return render_template("auth/reauth.html", form=form)
    return redirect(request.args.get("next") or
                    url_for("user.profile", username=current_user.username))
Esempio n. 18
0
def edit_forum(forum_id):
    forum = Forum.query.filter_by(id=forum_id).first_or_404()

    form = EditForumForm(forum)
    if form.validate_on_submit():
        form.save()
        flash(_("Forum successfully updated."), "success")
        return redirect(url_for("management.edit_forum", forum_id=forum.id))
    else:
        if forum.moderators:
            form.moderators.data = ",".join([user.username for user in forum.moderators])
        else:
            form.moderators.data = None

    return render_template("management/forum_form.html", form=form, title=_("Edit Forum"))
Esempio n. 19
0
def edit_group(group_id):
    group = jnt_models.Group.query.filter_by(id=group_id).first_or_404()

    form = EditGroupForm(group)

    if form.validate_on_submit():
        form.populate_obj(group)
        group.save()

        if group.guest:
            jnt_models.Guest.invalidate_cache()

        flash(_("Group successfully updated."), "success")
        return redirect(url_for("management.groups", group_id=group.id))

    return render_template("management/group_form.html", form=form, title=_("Edit Group"))
Esempio n. 20
0
def login():
    """
    Logs the user in
    """

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

    form = LoginForm(request.form)
    if form.validate_on_submit():
        user, authenticated = UserMan.authenticate(form.login.data,
                                                form.password.data)

        if user and authenticated:
            login_user(user, remember=form.remember_me.data)
            return redirect(request.args.get("next") or
                            url_for("forum.index"))

        flash(_("Wrong Username or Password."), "danger")
    return render_template("auth/login.html", form=form)
Esempio n. 21
0
def settings():
    form = GeneralSettingsForm()

    form.theme.choices = [(theme.identifier, theme.name)
                          for theme in get_themes_list()]

    form.language.choices = [(locale.language, locale.display_name)
                             for locale in babel.list_translations()]

    if form.validate_on_submit():
        current_user.theme = form.theme.data
        current_user.language = form.language.data
        current_user.save()

        flash(_("Settings updated."), "success")
    else:
        form.theme.data = current_user.theme
        form.language.data = current_user.language

    return render_template("user/general_settings.html", form=form)
Esempio n. 22
0
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 = UserMan.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 a Username or E-Mail Address that is "
                    "not linked with your account."), "danger")
    return render_template("auth/forgot_password.html", form=form)
Esempio n. 23
0
def edit_user(user_id):
    user = jnt_models.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"))

    member_group = db.and_(
        *[db.not_(getattr(jnt_models.Group, p)) for p in ["admin", "mod", "super_mod", "banned", "guest"]]
    )

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

    if any(user.permissions[p] for p in ["super_mod", "admin"]):
        filt = db.or_(filt, jnt_models.Group.mod)

    if user.permissions["admin"]:
        filt = db.or_(filt, jnt_models.Group.admin, jnt_models.Group.super_mod)

    group_query = jnt_models.Group.query.filter(filt)

    form = EditUserForm(user)
    form.primary_group.query = group_query
    form.secondary_groups.query = 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 updated."), "success")
        return redirect(url_for("management.edit_user", user_id=user.id))

    return render_template("management/user_form.html", form=form, title=_("Edit User"))
Esempio n. 24
0
def index():
    network=janitoo.listener.network
    web_servers=network.find_webcontrollers()
    web_resources=network.find_webresources()
    return render_template('proxy/index.html', web_servers=web_servers, web_resources=web_resources)
Esempio n. 25
0
def profile(username):
    user = UserMan.query.filter_by(username=username).first_or_404()

    return render_template("user/profile.html", user=user)
Esempio n. 26
0
def reports():
    page = request.args.get("page", 1, type=int)
    reports = Report.query.order_by(Report.id.asc()).paginate(page, flask_config["USERS_PER_PAGE"], False)

    return render_template("management/reports.html", reports=reports)
Esempio n. 27
0
def janitoo_constants_js():
    return render_template('janitoo_constants.js', capabilities=CAPABILITY_DESC, genres=GENRE_DESC, values=VALUE_DESC, commands=COMMAND_DESC)
Esempio n. 28
0
def index():
    """
    """
    return render_template("portal/index.html", user=current_user)
Esempio n. 29
0
def forums():
    categories = jnt_models.Category.query.order_by(jnt_models.Category.position.asc()).all()
    return render_template("management/forums.html", categories=categories)
Esempio n. 30
0
def plugins():
    plugins = get_all_plugins()
    return render_template("management/plugins.html", plugins=plugins)