- Cleaned up the Nginx configuration for the Coolify deployment, ensuring proper formatting and organization. - Updated the `pyproject.toml` file to maintain consistent formatting. - Reformatted the `requirements.txt` file for better readability while keeping the dependencies unchanged.
33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
"""Profile blueprint."""
|
|
from flask import Blueprint, flash, redirect, render_template, request, session, url_for
|
|
|
|
from ..helpers import _api, login_required
|
|
|
|
profile_bp = Blueprint("profile", __name__)
|
|
|
|
|
|
@profile_bp.route("/users/profile", methods=["GET", "POST"])
|
|
@login_required
|
|
def index():
|
|
token = session["access_token"]
|
|
if request.method == "POST":
|
|
payload: dict = {}
|
|
new_email = request.form.get("email", "").strip()
|
|
new_password = request.form.get("password", "").strip()
|
|
if new_email:
|
|
payload["email"] = new_email
|
|
if new_password:
|
|
payload["password"] = new_password
|
|
if payload:
|
|
resp = _api("PUT", "/users/me", token=token, json=payload)
|
|
if resp.status_code == 200:
|
|
updated = resp.json()
|
|
session["user_email"] = updated.get(
|
|
"email", session.get("user_email", ""))
|
|
flash("Profile updated.", "success")
|
|
else:
|
|
flash(resp.json().get("detail", "Update failed."), "error")
|
|
return redirect(url_for("profile.index"))
|
|
resp = _api("GET", "/users/me", token=token)
|
|
user = resp.json() if resp.status_code == 200 else {}
|
|
return render_template("profile.html", user=user) |