Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Preference page #42

Closed
Pitoche opened this issue Jun 5, 2024 · 9 comments · Fixed by #57
Closed

Add Preference page #42

Pitoche opened this issue Jun 5, 2024 · 9 comments · Fixed by #57

Comments

@Pitoche
Copy link
Collaborator

Pitoche commented Jun 5, 2024

Add Preference pages and link fields to DB

@Pitoche Pitoche changed the title Add Preference pages Add Preference page Jun 5, 2024
@quinone
Copy link
Owner

quinone commented Jun 5, 2024

What preferences do we want?

Custom time limit for auto log out

I would like to increase the time before logging out.
Maybe adding a field for that? We can set the default to 5 minutes?

Toggle light/dark mode

Using bootstrap we should be easily able to add a toggle light and dark mode.
By adding an if statement to base.html it should be as simple as swapping "dark" and "light" in the tag

<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="light">

@Pitoche
Copy link
Collaborator Author

Pitoche commented Jun 12, 2024

I added some fields back on the 4th JUNNE but now I am not getting anything

@quinone
Copy link
Owner

quinone commented Jun 12, 2024

So the blueprint for /settings needed to be added to create_app().

Yeah, are you looking to use flask-login? Was that from you or @Rachie94 ?

@Pitoche
Copy link
Collaborator Author

Pitoche commented Jun 12, 2024

Mine was just a page with 2 fields as I had little time. but right now I am getting an error

@quinone
Copy link
Owner

quinone commented Jun 12, 2024

This wasn't you?

login_manager = LoginManager()
login_manager.init_app(app)

bp = Blueprint("settings", __name__, url_prefix="/setting", template_folder="templates")


@bp.route("/", methods=["GET", "POST"])
@login_required
def settings():
    if request.method == "POST":
        vault_timeout = request.form.get("vaultTimeout", default="00:05:00")
        theme_id = request.form.get("themeId", default="light")
        settings_html = request.form.get(
            "settingsHtml", default=""
        )  # Get HTML content from the form

        try:
            conn = get_db()
            cursor = conn.cursor()
            cursor.execute(
                "REPLACE INTO preferences (user_id, vault_timeout, theme_id, settings_html) VALUES (?, ?, ?, ?)",
                (
                    current_user.id,
                    vault_timeout,
                    theme_id,
                    settings_html,
                ),  # Use current_user.id to get user_id
            )
            conn.commit()
            cursor.close()
            conn.close()
            flash("Preferences saved successfully", "success")
        except Exception as e:
            flash(f"Failed to save preferences: {str(e)}", "danger")

        return redirect(url_for("settings.settings"))

    return render_template("settings.html")```

@Pitoche
Copy link
Collaborator Author

Pitoche commented Jun 12, 2024

I think so..

@quinone
Copy link
Owner

quinone commented Jun 12, 2024

Think its fixed now. Try git fetch on development branch.
I've commented out flask-login. Its a great module but would require a large refactoring if we are going to use it fully.

@Pitoche
Copy link
Collaborator Author

Pitoche commented Jun 12, 2024

I now have 2 "settings" links and both work Not sure where the "other" is coming from

@quinone
Copy link
Owner

quinone commented Jun 12, 2024 via email

@Pitoche Pitoche linked a pull request Jul 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants