mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-05 23:08:48 +00:00
Redirect if not authed
If user not logged in, redirect any requests to login page
This commit is contained in:
parent
57713556d1
commit
7b478fed4e
26
InvenTree/InvenTree/middleware.py
Normal file
26
InvenTree/InvenTree/middleware.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
from django.shortcuts import HttpResponseRedirect
|
||||||
|
from django.urls import reverse_lazy
|
||||||
|
|
||||||
|
|
||||||
|
class AuthRequiredMiddleware(object):
|
||||||
|
def __init__(self, get_response):
|
||||||
|
self.get_response = get_response
|
||||||
|
|
||||||
|
def __call__(self, request):
|
||||||
|
# Code to be executed for each request before
|
||||||
|
# the view (and later middleware) are called.
|
||||||
|
|
||||||
|
assert hasattr(request, 'user')
|
||||||
|
|
||||||
|
response = self.get_response(request)
|
||||||
|
|
||||||
|
if not request.user.is_authenticated():
|
||||||
|
print(request.path_info)
|
||||||
|
|
||||||
|
if not request.path_info == reverse_lazy('login'):
|
||||||
|
return HttpResponseRedirect(reverse_lazy('login'))
|
||||||
|
|
||||||
|
# Code to be executed for each request/response after
|
||||||
|
# the view is called.
|
||||||
|
|
||||||
|
return response
|
@ -71,6 +71,7 @@ MIDDLEWARE = [
|
|||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
'simple_history.middleware.HistoryRequestMiddleware',
|
'simple_history.middleware.HistoryRequestMiddleware',
|
||||||
|
'InvenTree.middleware.AuthRequiredMiddleware'
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'InvenTree.urls'
|
ROOT_URLCONF = 'InvenTree.urls'
|
||||||
|
@ -129,3 +129,10 @@
|
|||||||
.warning-msg {
|
.warning-msg {
|
||||||
color: #e00;
|
color: #e00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.login {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<nav class="navbar navbar-default navbar-fixed-top">
|
<nav class="navbar navbar-default navbar-fixed-top">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="navbar-header">
|
<div class="navbar-header clearfix content-heading">
|
||||||
<a class="navbar-brand" id='logo' href="{% url 'index' %}"><img src="{% static 'img/inventree.png' %}" width="40" height="40"/></a>
|
<a class="navbar-brand" id='logo' href="{% url 'index' %}"><img src="{% static 'img/inventree.png' %}" width="40" height="40"/></a>
|
||||||
</div>
|
</div>
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
|
@ -1,10 +1,49 @@
|
|||||||
{% extends "base.html" %}
|
{% load static %}
|
||||||
|
|
||||||
{% block content %}
|
<!DOCTYPE html>
|
||||||
<h2>Login</h2>
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<!-- Required meta tags -->
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
|
||||||
|
<!-- CSS -->
|
||||||
|
<link rel="stylesheet" href="{% static 'css/bootstrap_3.3.7_css_bootstrap.min.css' %}">
|
||||||
|
<link rel="stylesheet" href="{% static 'css/select2.css' %}">
|
||||||
|
<link rel="stylesheet" href="{% static 'css/bootstrap-table.css' %}">
|
||||||
|
<link rel="stylesheet" href="{% static 'css/inventree.css' %}">
|
||||||
|
|
||||||
|
<title>
|
||||||
|
InvenTree
|
||||||
|
</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class='main body-wrapper'>
|
||||||
|
|
||||||
|
|
||||||
|
<div class='login'>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-2 col-md-offset-5">
|
||||||
|
<div class='clearfix content-heading'>
|
||||||
|
<img class="pull-left" src="{% static 'img/inventree.png' %}" width="60" height="60"/> <h3>InvenTree</h3>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<div class='container-fluid'>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
<button type="submit">Login</button>
|
<button class='pull-right btn btn-primary' type="submit">Login</button>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user