Commit 3e536c8a authored by Jon Yu's avatar Jon Yu
Browse files

Replace login links with OIDC paths

parent c4f8cdbb
from django.contrib import admin
from django.urls import path, include
from .views import login, logout
urlpatterns = [
path('admin/', admin.site.urls),
path('login/', login, name='login'),
path('logout/', logout, name='logout'),
path('', include('um_template_ui.urls')),
path('', include('oidc_auth.urls'))
]
from django.contrib.auth import logout as auth_logout
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.shortcuts import render
def login(request):
return render(request, 'um_template_ui/index.html')
@login_required
def logout(request):
auth_logout(request)
return HttpResponseRedirect(reverse('home'))
# Create your views here.
{% load static %}
<!doctype html>
<html lang="en">
<head>
{% block head %}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" type="image/png" href="{% static 'images/favicon.png' %}"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Slab&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{% static 'css/main.css' %}" />
{% block styles %}{% endblock %}
<title>University of Michigan {% block title %}{% endblock %}</title>
{% endblock %}
</head>
<html lang="en">
<head>
{% block head %}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" type="image/png" href="{% static 'images/favicon.png' %}"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Slab&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{% static 'css/main.css' %}" />
{% block styles %}{% endblock %}
<title>University of Michigan {% block title %}{% endblock %}</title>
{% endblock %}
</head>
<body>
<nav class="navbar navbar-dark navbar-expand-md fixed-top">
<a class="navbar-brand" href="{% url 'um_template_ui:home' %}"><img class="img-fluid my-1 py-1" src="{% static 'images/its-logo.png' %}" /></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarLinks" aria-controls="navbarLinks" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<body>
<nav class="navbar navbar-dark navbar-expand-md fixed-top">
<a class="navbar-brand" href="{% url 'um_template_ui:home' %}"><img class="img-fluid my-1 py-1" src="{% static 'images/its-logo.png' %}" /></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarLinks" aria-controls="navbarLinks" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarLinks">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{% url 'um_template_ui:home' %}">Home</a>
</li>
</ul>
<div class="navbar-nav ml-auto">
{% if request.user.is_authenticated %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="userMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ request.user.username }}
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="userMenu">
<a href="{% url 'logout' %}" class="dropdown-item">Logout</a>
</div>
</li>
{% else %}
<a href="{% url 'login' %}?next={{ request.get_full_path }}" class="nav-link">Login</a>
{% endif %}
<div class="collapse navbar-collapse" id="navbarLinks">
<div class="navbar-nav ml-auto">
{% if request.user.is_authenticated %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="userMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ request.user.username }}
</a>
<div class="dropdown-menu" aria-labelledby="userMenu">
<form action="{% url 'oidc_logout' %}" method="post">
{% csrf_token %}
<input type="submit" value="logout" style="background-color: white" class="dropdown-item">
</form>
</div>
</li>
{% else %}
<a href="{% url 'oidc_authentication_init' %}" class="nav-link">Login</a>
{% endif %}
</div>
</div>
</div>
</nav>
</nav>
<main role="main" class="container-fluid pt-2">
<div>
{% block content %}
{% endblock %}
</div>
</main><!-- /.container -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
{% block scripts %}{% endblock %}
</body>
<main role="main" class="container-fluid pt-2">
<div>
{% block content %}
{% endblock %}
</div>
</main>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
{% block scripts %}{% endblock %}
</body>
</html>
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