passing data around

master
Kostanjevec 2022-05-20 00:01:56 +02:00
parent 5ec20ae358
commit 7417222ee9
2 changed files with 32 additions and 11 deletions

37
app.py
View File

@ -1,7 +1,9 @@
from collections import UserList
import os
from auth import bp
from flask import Flask
from auth import login_required, bp as auth_bp
from deck import deck, bp as deck_bp
from flask import Flask, render_template, session
def create_app(test_config=None):
@ -26,12 +28,33 @@ def create_app(test_config=None):
pass
# a simple page that says hello
@app.route('/index')
@app.route('/')
def index():
return 'Hello, Woooorld!'
app.register_blueprint(bp)
@app.route('/')
@login_required
def index():
return 'redirecting' # meče skoz nazaj na login TODO
@app.route('/deck', methods=["GET", "POST"])
#@login_required
def deck():
if 'user_id' in session:
user_id = session['user_id']
username = session['username']
return render_template("deck/index.html", username=username)
else:
return index()
@app.route('/logout')
def logout():
session.pop("user_id", None)
return index()
#app.register_blueprint(bp) # ??
app.register_blueprint(auth_bp)
app.register_blueprint(deck_bp)
app.add_url_rule('/', endpoint='index')
return app

View File

@ -1,6 +1,4 @@
import functools
from pickle import NONE
from shutil import ExecError
from flask import (
Blueprint, flash, g, redirect, render_template, request, session, url_for
@ -11,7 +9,6 @@ from sqlalchemy.orm import sessionmaker
from hashlib import md5
from config import CONFIG
from create_db import User
bp = Blueprint('auth', __name__, url_prefix='/auth')
@ -67,7 +64,8 @@ def login():
if error is None:
session.clear()
session['user_id'] = user.id
return redirect(url_for('index'))
session['username'] = user.username
return redirect(url_for('deck'))
flash(error)