home & auth blueprints
This commit is contained in:
4
website/home/__init__.py
Normal file
4
website/home/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from flask import Blueprint
|
||||
|
||||
home = Blueprint('home', __name__, template_folder='templates')
|
||||
from . import routes
|
25
website/home/routes.py
Normal file
25
website/home/routes.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from . import home
|
||||
from flask import Blueprint, render_template, jsonify
|
||||
from flask_login import current_user
|
||||
from authlib.integrations.flask_oauth2 import current_token
|
||||
from ..auth.oauth2 import require_oauth
|
||||
|
||||
|
||||
@home.route('/')
|
||||
def index():
|
||||
user = None
|
||||
if current_user.is_authenticated:
|
||||
clients = current_user.clients
|
||||
user = current_user.name
|
||||
else:
|
||||
clients = []
|
||||
|
||||
return render_template('home.html', user=user, clients=clients)
|
||||
|
||||
|
||||
@home.route('/api/me')
|
||||
@require_oauth('profile')
|
||||
def api_me():
|
||||
user = current_token.user
|
||||
return jsonify(id=user.id, username=user.username)
|
||||
|
32
website/home/templates/home.html
Normal file
32
website/home/templates/home.html
Normal file
@@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
{% for category, message in get_flashed_messages(with_categories=true) %}
|
||||
<spam class="{{ category }}">{{ message }}</spam>
|
||||
{% endfor %}<br/>
|
||||
|
||||
{% if user %}
|
||||
<style>pre{white-space:wrap}</style>
|
||||
<div>Logged in as <strong>{{user.name}}</strong> (<a href="{{ url_for('auth.logout') }}">Log Out</a>)</div>
|
||||
|
||||
<br/><div><h3>Clients:</h3>
|
||||
{% for client in clients %}
|
||||
<pre>
|
||||
{{ client.client_info|tojson }}
|
||||
{{ client.client_metadata|tojson }}
|
||||
</pre>
|
||||
<hr>
|
||||
{% endfor %}
|
||||
<br/></div>
|
||||
|
||||
{% else %}
|
||||
<br><p>Please, <a href="{{ url_for('auth.login') }}">Login</a></p>
|
||||
{% endif %}
|
||||
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user