Add blueprints for authentication, admin, dashboard, gallery, generation, and profile routes
- Created `__init__.py` for blueprint registration. - Implemented `auth.py` for user authentication (login, register, logout). - Added `admin.py` for admin functionalities (user management, stats). - Developed `dashboard.py` for user dashboard displaying user info and generated content. - Created `gallery.py` for managing and displaying images and videos. - Implemented `generate.py` for text, image, and video generation functionalities. - Added `profile.py` for user profile management. - Updated templates to reflect new route structures and improve navigation.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""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)
|
||||
Reference in New Issue
Block a user