Пример #1
0
def settings_view():
    settings = AccountService.get_settings(current_user.get_id())
    form = make_settings_form(settings)

    def render_form():
        return render_template("settings.tpl", settings=settings, form=form)

    if form.is_submitted():
        if not form.validate():
            flash_update_error()
            return render_form()

        new_password = form.new_password.data
        if new_password:
            if current_user["password"] == new_password:
                flash_update_error(form.new_password,
                                   "Same as current password")
                return render_form()
            AccountService.update(current_user.get_id(),
                                  AccountInterface(password=new_password))

        # Use the UserSettings class in order to update/set settings
        user_settings.set(current_user.get_id(), form.data)
        flash("Success! Your settings have been saved.")
    return render_form()
Пример #2
0
    def link(user_id: int, subject: Optional[str]):
        """
        Link the given account to the given openid subject

        :param user_id: user ID to link
        :param subject: openid subject to link to the account
        :return:
        """
        AccountService.update(user_id, AccountInterface(hash=subject))