コード例 #1
0
ファイル: user.py プロジェクト: samosky123/newspipe
def confirm_account(token=None):
    """
    Confirm the account of a user.
    """
    user_contr = UserController()
    user, nickname = None, None
    if token != "":
        nickname = confirm_token(token)
    if nickname:
        user = user_contr.read(nickname=nickname).first()
    if user is not None:
        user_contr.update({"id": user.id}, {"is_active": True})
        flash(gettext("Your account has been confirmed."), "success")
    else:
        flash(gettext("Impossible to confirm this account."), "danger")
    return redirect(url_for("login"))
コード例 #2
0
ファイル: user.py プロジェクト: samosky123/newspipe
def profile():
    """
    Edit the profile of the currently logged user.
    """
    user_contr = UserController(current_user.id)
    user = user_contr.get(id=current_user.id)
    form = ProfileForm()

    if request.method == "POST":
        if form.validate():
            try:
                user_contr.update(
                    {"id": current_user.id},
                    {
                        "nickname": form.nickname.data,
                        "password": form.password.data,
                        "automatic_crawling": form.automatic_crawling.data,
                        "is_public_profile": form.is_public_profile.data,
                        "bio": form.bio.data,
                        "webpage": form.webpage.data,
                        "twitter": form.twitter.data,
                    },
                )
            except Exception as error:
                flash(
                    gettext(
                        "Problem while updating your profile: "
                        "%(error)s",
                        error=error),
                    "danger",
                )
            else:
                flash(
                    gettext("User %(nick)s successfully updated",
                            nick=user.nickname),
                    "success",
                )
            return redirect(url_for("user.profile"))
        else:
            return render_template("profile.html", user=user, form=form)

    if request.method == "GET":
        form = ProfileForm(obj=user)
        return render_template("profile.html", user=user, form=form)
コード例 #3
0
ファイル: admin.py プロジェクト: stephengathambiri/newspipe
def process_user_form(user_id=None):
    """
    Create or edit a user.
    """
    form = UserForm()
    user_contr = UserController()

    if not form.validate():
        return render_template(
            "/admin/create_user.html",
            form=form,
            message=gettext("Some errors were found"),
        )

    if user_id is not None:
        # Edit a user
        user_contr.update(
            {"id": user_id},
            {
                "nickname": form.nickname.data,
                "password": form.password.data,
                "automatic_crawling": form.automatic_crawling.data,
            },
        )
        user = user_contr.get(id=user_id)
        flash(
            gettext("User %(nick)s successfully updated", nick=user.nickname),
            "success")
    else:
        # Create a new user (by the admin)
        user = user_contr.create(
            nickname=form.nickname.data,
            password=form.password.data,
            automatic_crawling=form.automatic_crawling.data,
            is_admin=False,
            is_active=True,
        )
        flash(
            gettext("User %(nick)s successfully created", nick=user.nickname),
            "success")
    return redirect(url_for("admin.user_form", user_id=user.id))
コード例 #4
0
ファイル: admin.py プロジェクト: stephengathambiri/newspipe
def toggle_user(user_id=None):
    """
    Enable or disable the account of a user.
    """
    ucontr = UserController()
    user = ucontr.get(id=user_id)
    user_changed = ucontr.update({"id": user_id},
                                 {"is_active": not user.is_active})

    if not user_changed:
        flash(gettext("This user does not exist."), "danger")
        return redirect(url_for("admin.dashboard"))

    else:
        act_txt = "activated" if user.is_active else "desactivated"
        message = gettext(
            "User %(nickname)s successfully %(is_active)s",
            nickname=user.nickname,
            is_active=act_txt,
        )
    flash(message, "success")
    return redirect(url_for("admin.dashboard"))