mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-12-07 13:21:41 +01:00
Compare commits
1 Commits
23dd987892
...
b321ebabf2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b321ebabf2 |
@ -3,7 +3,7 @@
|
|||||||
{% load menu_menu_items %}
|
{% load menu_menu_items %}
|
||||||
|
|
||||||
<div class="col-auto px-0">
|
<div class="col-auto px-0">
|
||||||
<div class="collapse collapse-horizontal {% if user.is_authenticated and not request.is_mobile_device and not request.session.MINIMIZE_SIDEBAR %}show{% endif %}" tabindex="-1" id="sidebar">
|
<div class="collapse collapse-horizontal" tabindex="-1" id="sidebar">
|
||||||
<div>
|
<div>
|
||||||
<div class="nav-padding navbar-dark text-bg-dark px-0 d-flex flex-column overflow-hidden vh-100 {% if not user.is_authenticated %}position-relative{% endif %}">
|
<div class="nav-padding navbar-dark text-bg-dark px-0 d-flex flex-column overflow-hidden vh-100 {% if not user.is_authenticated %}position-relative{% endif %}">
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
|
|||||||
@ -1,65 +0,0 @@
|
|||||||
"""
|
|
||||||
Alliance Auth Middleware
|
|
||||||
"""
|
|
||||||
|
|
||||||
from user_agents import parse
|
|
||||||
|
|
||||||
|
|
||||||
class DeviceDetectionMiddleware:
|
|
||||||
"""
|
|
||||||
Middleware to detect the type of device making the request.
|
|
||||||
Sets flags on the request object for easy access in views and templates.
|
|
||||||
|
|
||||||
Flags include:
|
|
||||||
- is_mobile: True if the device is a mobile phone.
|
|
||||||
- is_tablet: True if the device is a tablet.
|
|
||||||
- is_mobile_device: True if the device is either a mobile phone or a tablet.
|
|
||||||
- is_touch_capable: True if the device has touch capabilities.
|
|
||||||
- is_pc: True if the device is a desktop or laptop computer.
|
|
||||||
- is_bot: True if the device is identified as a bot or crawler.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, get_response):
|
|
||||||
"""
|
|
||||||
Initialize the middleware with the get_response callable.
|
|
||||||
|
|
||||||
:param get_response:
|
|
||||||
:type get_response:
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.get_response = get_response
|
|
||||||
|
|
||||||
def __call__(self, request):
|
|
||||||
"""
|
|
||||||
Process the incoming request to determine if it's from a mobile device.
|
|
||||||
|
|
||||||
This method is called when the middleware is invoked. It inspects the
|
|
||||||
`user-agent` header of the incoming HTTP request to determine the type
|
|
||||||
of client making the request (e.g., mobile, tablet, PC, bot, etc.).
|
|
||||||
Flags are set on the `request` object to indicate the client type.
|
|
||||||
|
|
||||||
:param request: The HTTP request object.
|
|
||||||
:type request: HttpRequest
|
|
||||||
:return: The HTTP response object after processing the request.
|
|
||||||
:rtype: HttpResponse
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Retrieve the user-agent string from the request headers
|
|
||||||
user_agent_string = request.headers.get("user-agent", "")
|
|
||||||
|
|
||||||
# Parse the user-agent string to extract client information
|
|
||||||
user_agent = parse(user_agent_string)
|
|
||||||
|
|
||||||
# Set flags on the request object based on the client type
|
|
||||||
request.is_mobile = user_agent.is_mobile # True if the client is a mobile phone
|
|
||||||
request.is_tablet = user_agent.is_tablet # True if the client is a tablet
|
|
||||||
request.is_mobile_device = user_agent.is_mobile or user_agent.is_tablet # True if mobile phone or tablet
|
|
||||||
request.is_touch_capable = user_agent.is_touch_capable # True if the client supports touch input
|
|
||||||
request.is_pc = user_agent.is_pc # True if the client is a PC
|
|
||||||
request.is_bot = user_agent.is_bot # True if the client is a bot
|
|
||||||
|
|
||||||
# Pass the request to the next middleware or view and get the response
|
|
||||||
response = self.get_response(request)
|
|
||||||
|
|
||||||
# Return the processed response
|
|
||||||
return response
|
|
||||||
@ -88,7 +88,6 @@ MIDDLEWARE = [
|
|||||||
"django.middleware.security.SecurityMiddleware",
|
"django.middleware.security.SecurityMiddleware",
|
||||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
"allianceauth.authentication.middleware.UserSettingsMiddleware",
|
"allianceauth.authentication.middleware.UserSettingsMiddleware",
|
||||||
"allianceauth.middleware.DeviceDetectionMiddleware",
|
|
||||||
"django.middleware.locale.LocaleMiddleware",
|
"django.middleware.locale.LocaleMiddleware",
|
||||||
"django.middleware.common.CommonMiddleware",
|
"django.middleware.common.CommonMiddleware",
|
||||||
"django.middleware.csrf.CsrfViewMiddleware",
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
|
|||||||
@ -1,6 +1,27 @@
|
|||||||
|
/* global sidebarSettings */
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const sidebar = document.getElementById('sidebar');
|
||||||
|
const sidebarKey = `sidebar_${sidebar.id}`;
|
||||||
|
|
||||||
|
sidebar.addEventListener('shown.bs.collapse', (event) => {
|
||||||
|
if (event.target.id === sidebar.id) {
|
||||||
|
localStorage.removeItem(sidebarKey);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sidebar.addEventListener('hidden.bs.collapse', (event) => {
|
||||||
|
if (event.target.id === sidebar.id) {
|
||||||
|
localStorage.setItem(sidebarKey, 'closed');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!sidebarSettings.minimizeSidebar) {
|
||||||
|
sidebar.classList.toggle('show', localStorage.getItem(sidebarKey) !== 'closed');
|
||||||
|
}
|
||||||
|
|
||||||
const activeChildMenuItem = document.querySelector('ul#sidebar-menu ul.collapse a.active');
|
const activeChildMenuItem = document.querySelector('ul#sidebar-menu ul.collapse a.active');
|
||||||
|
|
||||||
if (activeChildMenuItem) {
|
if (activeChildMenuItem) {
|
||||||
|
|||||||
@ -102,6 +102,11 @@
|
|||||||
</main>
|
</main>
|
||||||
<!-- End Body -->
|
<!-- End Body -->
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const sidebarSettings = {
|
||||||
|
minimizeSidebar: {% if request.session.MINIMIZE_SIDEBAR %}true{% else %}false{% endif %}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
{% include "bundles/auth-sidebar-collapse-js.html" %}
|
{% include "bundles/auth-sidebar-collapse-js.html" %}
|
||||||
|
|
||||||
{% theme_js %}
|
{% theme_js %}
|
||||||
|
|||||||
@ -61,14 +61,11 @@ dependencies = [
|
|||||||
"passlib",
|
"passlib",
|
||||||
"pydiscourse",
|
"pydiscourse",
|
||||||
"python-slugify>=1.2",
|
"python-slugify>=1.2",
|
||||||
"pyyaml",
|
|
||||||
"redis>=4",
|
"redis>=4",
|
||||||
"requests>=2.9.1",
|
"requests>=2.9.1",
|
||||||
"requests-oauthlib",
|
"requests-oauthlib",
|
||||||
"semantic-version",
|
"semantic-version",
|
||||||
"slixmpp<1.9",
|
"slixmpp<1.9",
|
||||||
"ua-parser",
|
|
||||||
"user-agents",
|
|
||||||
]
|
]
|
||||||
optional-dependencies.docs = [
|
optional-dependencies.docs = [
|
||||||
"myst-parser",
|
"myst-parser",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user