passing data around
parent
5ec20ae358
commit
7417222ee9
37
app.py
37
app.py
|
@ -1,7 +1,9 @@
|
||||||
|
from collections import UserList
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from auth import bp
|
from auth import login_required, bp as auth_bp
|
||||||
from flask import Flask
|
from deck import deck, bp as deck_bp
|
||||||
|
from flask import Flask, render_template, session
|
||||||
|
|
||||||
|
|
||||||
def create_app(test_config=None):
|
def create_app(test_config=None):
|
||||||
|
@ -26,12 +28,33 @@ def create_app(test_config=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# a simple page that says hello
|
# 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
|
return app
|
||||||
|
|
||||||
|
|
6
auth.py
6
auth.py
|
@ -1,6 +1,4 @@
|
||||||
import functools
|
import functools
|
||||||
from pickle import NONE
|
|
||||||
from shutil import ExecError
|
|
||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
Blueprint, flash, g, redirect, render_template, request, session, url_for
|
Blueprint, flash, g, redirect, render_template, request, session, url_for
|
||||||
|
@ -11,7 +9,6 @@ from sqlalchemy.orm import sessionmaker
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
|
|
||||||
from config import CONFIG
|
from config import CONFIG
|
||||||
|
|
||||||
from create_db import User
|
from create_db import User
|
||||||
|
|
||||||
bp = Blueprint('auth', __name__, url_prefix='/auth')
|
bp = Blueprint('auth', __name__, url_prefix='/auth')
|
||||||
|
@ -67,7 +64,8 @@ def login():
|
||||||
if error is None:
|
if error is None:
|
||||||
session.clear()
|
session.clear()
|
||||||
session['user_id'] = user.id
|
session['user_id'] = user.id
|
||||||
return redirect(url_for('index'))
|
session['username'] = user.username
|
||||||
|
return redirect(url_for('deck'))
|
||||||
|
|
||||||
flash(error)
|
flash(error)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue