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.contrib import admin
from django.urls import path, include from django.urls import path, include
from .views import login, logout
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('login/', login, name='login'),
path('logout/', logout, name='logout'),
path('', include('um_template_ui.urls')), path('', include('um_template_ui.urls')),
path('', include('oidc_auth.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 from django.shortcuts import render
# Create your views here.
def login(request):
return render(request, 'um_template_ui/index.html')
@login_required
def logout(request):
auth_logout(request)
return HttpResponseRedirect(reverse('home'))
{% load static %} {% load static %}
<!doctype html> <!doctype html>
<html lang="en">
<head> <html lang="en">
{% block head %} <head>
<meta charset="utf-8"> {% block head %}
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta charset="utf-8">
<link rel="shortcut icon" type="image/png" href="{% static 'images/favicon.png' %}"/> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<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 rel="shortcut icon" type="image/png" href="{% static 'images/favicon.png' %}"/>
<link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Slab&display=swap" rel="stylesheet"> <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 rel="stylesheet" href="{% static 'css/main.css' %}" /> <link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Slab&display=swap" rel="stylesheet">
{% block styles %}{% endblock %} <link rel="stylesheet" href="{% static 'css/main.css' %}" />
<title>University of Michigan {% block title %}{% endblock %}</title> {% block styles %}{% endblock %}
{% endblock %} <title>University of Michigan {% block title %}{% endblock %}</title>
</head> {% endblock %}
</head>
<body> <body>
<nav class="navbar navbar-dark navbar-expand-md fixed-top"> <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> <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"> <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> <span class="navbar-toggler-icon"></span>
</button> </button>
<div class="collapse navbar-collapse" id="navbarLinks"> <div class="collapse navbar-collapse" id="navbarLinks">
<ul class="navbar-nav mr-auto"> <div class="navbar-nav ml-auto">
<li class="nav-item"> {% if request.user.is_authenticated %}
<a class="nav-link" href="{% url 'um_template_ui:home' %}">Home</a> <li class="nav-item dropdown">
</li> <a class="nav-link dropdown-toggle" href="#" id="userMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
</ul> {{ request.user.username }}
<div class="navbar-nav ml-auto"> </a>
{% if request.user.is_authenticated %} <div class="dropdown-menu" aria-labelledby="userMenu">
<li class="nav-item dropdown"> <form action="{% url 'oidc_logout' %}" method="post">
<a class="nav-link dropdown-toggle" href="#" id="userMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> {% csrf_token %}
{{ request.user.username }} <input type="submit" value="logout" style="background-color: white" class="dropdown-item">
</a> </form>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="userMenu"> </div>
<a href="{% url 'logout' %}" class="dropdown-item">Logout</a> </li>
</div> {% else %}
</li> <a href="{% url 'oidc_authentication_init' %}" class="nav-link">Login</a>
{% else %} {% endif %}
<a href="{% url 'login' %}?next={{ request.get_full_path }}" class="nav-link">Login</a> </div>
{% endif %}
</div> </div>
</div> </nav>
</nav>
<main role="main" class="container-fluid pt-2"> <main role="main" class="container-fluid pt-2">
<div> <div>
{% block content %} {% block content %}
{% endblock %} {% endblock %}
</div> </div>
</main><!-- /.container --> </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>
<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> </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