adding missing files
This commit is contained in:
16
app/blueprints/ajax.py
Normal file
16
app/blueprints/ajax.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from flask import Blueprint, request, url_for, render_template, session,flash
|
||||
from app.services.appwrite_client import AppWriteClient
|
||||
|
||||
|
||||
ajax_bp = Blueprint("ajax", __name__, url_prefix="/ajax")
|
||||
|
||||
|
||||
@ajax_bp.route("/races", methods=["GET", "POST"])
|
||||
def races():
|
||||
race = request.args.get("race")
|
||||
return render_template(f"ajax/race_{race}.html")
|
||||
|
||||
@ajax_bp.route("/prof", methods=["GET", "POST"])
|
||||
def professions():
|
||||
prof = request.args.get("prof")
|
||||
return render_template(f"ajax/prof_{prof}.html")
|
||||
112
app/blueprints/auth.py
Normal file
112
app/blueprints/auth.py
Normal file
@@ -0,0 +1,112 @@
|
||||
# app/auth/routes.py
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, flash, session,make_response
|
||||
|
||||
from app.services.appwrite_client import AppWriteClient
|
||||
|
||||
|
||||
auth_bp = Blueprint("auth", __name__, url_prefix="/auth")
|
||||
|
||||
|
||||
@auth_bp.route("/register", methods=["GET", "POST"])
|
||||
def register():
|
||||
if request.method == "POST":
|
||||
email = request.form.get("email", "").strip()
|
||||
password = request.form.get("password", "")
|
||||
name = (request.form.get("name") or "").strip() or None
|
||||
|
||||
if not email or not password:
|
||||
flash("Email and password are required.", "error")
|
||||
return redirect(url_for("auth.register"))
|
||||
|
||||
try:
|
||||
aw = AppWriteClient()
|
||||
aw.create_new_user(email,password,name)
|
||||
|
||||
login_valid, error = aw.log_user_in(email,password)
|
||||
if login_valid:
|
||||
flash("Account created and you are now logged in.", "success")
|
||||
return redirect(url_for("main.dashboard"))
|
||||
else:
|
||||
flash(str(error), "error")
|
||||
except Exception as e:
|
||||
flash(str(e), "error")
|
||||
return redirect(url_for("auth.register"))
|
||||
|
||||
return render_template("auth/register.html")
|
||||
|
||||
@auth_bp.route("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
if request.method == "POST":
|
||||
email = request.form.get("email", "").strip()
|
||||
password = request.form.get("password", "")
|
||||
if not email or not password:
|
||||
flash("Email and password are required.", "error")
|
||||
return redirect(url_for("auth.login"))
|
||||
|
||||
aw = AppWriteClient()
|
||||
login_valid, error = aw.log_user_in(email,password)
|
||||
try:
|
||||
if login_valid:
|
||||
username = session.get("user",{}).get("name","User")
|
||||
flash(f"Welcome Back {username}", "success")
|
||||
return redirect(url_for("main.dashboard"))
|
||||
else:
|
||||
flash(str(error), "error")
|
||||
except Exception as e:
|
||||
flash(str(e), "error")
|
||||
return redirect(url_for("auth.login"))
|
||||
|
||||
# Get method
|
||||
|
||||
return render_template("auth/login.html")
|
||||
|
||||
@auth_bp.route("/logout", methods=["GET", "POST"])
|
||||
def logout():
|
||||
aw = AppWriteClient()
|
||||
aw.log_user_out()
|
||||
session.clear()
|
||||
flash("Signed out.", "success")
|
||||
return redirect(url_for("auth.login"))
|
||||
|
||||
@auth_bp.route("/send", methods=["POST"])
|
||||
def send():
|
||||
"""
|
||||
Sends a verification email to the currently logged-in user.
|
||||
Appwrite will redirect the user back to /verify/callback with userId & secret.
|
||||
"""
|
||||
try:
|
||||
aw = AppWriteClient()
|
||||
aw.send_email_verification()
|
||||
flash("Verification email sent. Please check your inbox.", "info")
|
||||
except Exception as e:
|
||||
flash(f"Could not send verification email: {e}", "error")
|
||||
# Go back to where the user came from, or your dashboard
|
||||
return redirect(request.referrer or url_for("main.dashboard"))
|
||||
|
||||
@auth_bp.route("/callback", methods=["GET"])
|
||||
def callback():
|
||||
"""
|
||||
Completes verification after user clicks the email link.
|
||||
Requires the user to be logged in (Appwrite Account endpoints need a session).
|
||||
If not logged in, we stash the link params and send them to log in first.
|
||||
"""
|
||||
aw = AppWriteClient()
|
||||
user_id = request.args.get("userId")
|
||||
secret = request.args.get("secret")
|
||||
if not user_id or not secret:
|
||||
flash("Invalid verification link.", "error")
|
||||
return redirect(url_for("auth.login"))
|
||||
|
||||
try:
|
||||
# If we don't currently have an Appwrite session, ask them to log in, then resume.
|
||||
if not aw.verify_email(user_id,secret):
|
||||
session["pending_verification"] = {"userId": user_id, "secret": secret}
|
||||
flash("Please log in to complete email verification.", "warning")
|
||||
return redirect(url_for("auth.login"))
|
||||
|
||||
# We have a session; complete verification
|
||||
flash("Email verified! You're all set.", "success")
|
||||
return redirect(url_for("main.dashboard"))
|
||||
except Exception as e:
|
||||
flash(f"Verification failed: {e}", "error")
|
||||
return redirect(url_for("auth.login"))
|
||||
46
app/blueprints/char.py
Normal file
46
app/blueprints/char.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import os
|
||||
import json
|
||||
import random
|
||||
from flask import Blueprint, redirect, url_for, render_template, g, request, flash
|
||||
from typing import cast
|
||||
|
||||
from app.utils.session_user import SessionUser
|
||||
from app.services.appwrite_client import AppWriteClient
|
||||
from app.services.appwrite_db import AppwriteTables, Env
|
||||
from app.services.coc_api import CoCApi
|
||||
|
||||
char_bp = Blueprint("char", __name__, url_prefix="/char")
|
||||
|
||||
cocapi = CoCApi()
|
||||
|
||||
|
||||
def get_current_user() -> SessionUser:
|
||||
return cast(SessionUser, g.current_user)
|
||||
|
||||
|
||||
@char_bp.route("/create", methods=["GET", "POST"])
|
||||
def create_char():
|
||||
if request.method == "POST":
|
||||
name = request.form.get("character_name")
|
||||
race_id = request.form.get("race_dropdown")
|
||||
profession_id = request.form.get("profession_dropdown")
|
||||
origin_story = request.form.get("origin_story")
|
||||
uuid = cocapi.create_char(name=name,origin_story=origin_story,race_id=race_id,profession_id=profession_id)
|
||||
redirect(url_for("main.dashboard"))
|
||||
|
||||
ai_dumps_path = os.path.join("app","game_data","ai_dumps.json")
|
||||
with open(ai_dumps_path,"r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
origin_stories = data.get("origin_stories",[])
|
||||
if len(origin_stories) > 0:
|
||||
starter_text = random.choice(origin_stories)
|
||||
else:
|
||||
starter_text = "I was born in a small, secluded village on the edge of a vast and mysterious forest, where whispers of ancient magic still lingered in the air."
|
||||
|
||||
template_data = {
|
||||
"starter_text":starter_text
|
||||
}
|
||||
|
||||
return render_template("char/create_char.html", data=template_data)
|
||||
|
||||
27
app/blueprints/main.py
Normal file
27
app/blueprints/main.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
from flask import Blueprint, redirect, url_for, render_template, g, session,flash
|
||||
from typing import cast
|
||||
|
||||
from app.utils.session_user import SessionUser
|
||||
from app.services.appwrite_client import AppWriteClient
|
||||
from app.services.appwrite_db import AppwriteTables
|
||||
from app.services.coc_api import CoCApi
|
||||
|
||||
main_bp = Blueprint("main", __name__, url_prefix="/main")
|
||||
cocapi = CoCApi()
|
||||
|
||||
|
||||
def get_current_user() -> SessionUser:
|
||||
return cast(SessionUser, g.current_user)
|
||||
|
||||
|
||||
@main_bp.route("/dashboard")
|
||||
def dashboard():
|
||||
db_tables = AppwriteTables()
|
||||
user = get_current_user()
|
||||
results = db_tables.get_characters_for_user_id(user.id)
|
||||
if len(results) == 0:
|
||||
return redirect(url_for("char.create_char"))
|
||||
else:
|
||||
char=results
|
||||
return render_template("main/dashboard.html", profile=g.current_user, jwt_info=char)
|
||||
10
app/blueprints/public.py
Normal file
10
app/blueprints/public.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from flask import Blueprint, redirect, url_for, render_template, session,flash
|
||||
from app.services.appwrite_client import AppWriteClient
|
||||
|
||||
|
||||
public_bp = Blueprint("public", __name__, url_prefix="/")
|
||||
|
||||
|
||||
@public_bp.route("/")
|
||||
def home():
|
||||
return render_template("public/home.html")
|
||||
Reference in New Issue
Block a user