IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Verified Commit a75f342c authored by Emi Simpson's avatar Emi Simpson
Browse files

Figured out how to pull information from SAML

parent d0a524f1
Pipeline #85 canceled with stage
......@@ -2,7 +2,7 @@ import sqlite3
import json
from flask import render_template, request, session, Blueprint, current_app
from werkzeug.wrappers.response import Response
from typing import Optional, Union
from typing import Tuple, Union
from mystic.database import User, Project
from mystic.projects import produce_project_report
from mystic.config import service_provider
......@@ -12,8 +12,7 @@ bp = Blueprint("main", __name__, url_prefix="/")
@bp.route("/")
def landing() -> str:
print(f'Created app with SAML metadata posted at {service_provider.get_metadata_url()}')
return render_template("landing.html", username=username_or_none())
return render_template("landing.html", login=_login_or_profile())
@bp.route("/login", methods=['POST'])
def login() -> Response:
......@@ -31,7 +30,7 @@ def projects() -> str:
for p
in projects
)
return render_template("projects.html", username=username_or_none(), projects=projects_with_id)
return render_template("projects.html", login=_login_or_profile(), projects=projects_with_id)
@bp.route("/projects/addsource", methods=['POST'])
def addsource() -> Response:
......@@ -83,11 +82,11 @@ def project_page(pid: str) -> Union[Response, str]:
project = Project.from_alphaid(c, pid)
if not user.check_owns(project):
return Response(status=401) # Public project pages aren't implemented yet
return render_template("project_page.html", username=username_or_none(), project=project)
return render_template("project_page.html", login=_login_or_profile(), project=project)
@bp.route("/new")
def new() -> str:
return render_template("new.html", username=username_or_none())
return render_template("new.html", login=_login_or_profile())
@bp.route("/new/create", methods=['POST'])
def create() -> Response:
......@@ -99,11 +98,12 @@ def create() -> Response:
project.add_owner(user)
return flask.redirect("../projects")
def username_or_none() -> Optional[str]:
if 'username' in session:
return session['username']
def _login_or_profile() -> Tuple[str, str]:
if service_provider.is_user_logged_in():
name = service_provider.get_auth_data_in_session().attributes['givenName']
return (name, '/account')
else:
return None
return ('Login', service_provider.get_login_url())
def _save_projects_json_and_close_cursor(c: sqlite3.Cursor, conn: sqlite3.Connection) -> None:
report = produce_project_report(c)
......
......@@ -9,15 +9,11 @@
</head>
<body>
<nav>
<a href="/" {% if selected is sameas "home" %} class='selected'{% endif %}>HOME</a>
<a href="/projects" {% if selected is sameas "projects" %}class='selected'{% endif %}>PROJECTS</a>
<a href="/new" {% if selected is sameas "new" %} class='selected'{% endif %}>NEW</a>
<a href="/stats" {% if selected is sameas "stats" %} class='selected'{% endif %}>STATS</a>
{% if username is none %}
<a href="/login" {% if selected is sameas "login" %} class='selected'{% endif %}>LOG IN</a>
{% else %}
<a href="/account" {% if selected is sameas "account" %} class='selected'{% endif %}>{{username}}</a>
{% endif %}
<a href="/" {% if selected is sameas "home" %} class='selected'{% endif %}>HOME</a>
<a href="/projects" {% if selected is sameas "projects" %}class='selected'{% endif %}>PROJECTS</a>
<a href="/new" {% if selected is sameas "new" %} class='selected'{% endif %}>NEW</a>
<a href="/stats" {% if selected is sameas "stats" %} class='selected'{% endif %}>STATS</a>
<a href="{{login[1]}}" {% if selected is sameas "login" %} class='selected'{% endif %}>{{login[0]}}</a>
</nav>
<main>
{% block main %}{% endblock %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment