-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DF-DOCKER: User Auth Implemented. Auth reset using django key file. S…
…tyled login ui.
- Loading branch information
Showing
12 changed files
with
463 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.shortcuts import redirect | ||
from django.urls import reverse | ||
from DiscoFlixClient.models import Configuration | ||
|
||
|
||
class LoginRequiredMiddleware: | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
if request.path.startswith(reverse("login")) or request.path.startswith(reverse("disable_login_requirement")): | ||
return self.get_response(request) | ||
|
||
config = Configuration.objects.first() | ||
if config and config.is_login_required and not request.user.is_authenticated: | ||
return redirect(reverse("login")) | ||
|
||
return self.get_response(request) |
23 changes: 23 additions & 0 deletions
23
DiscoFlixClient/migrations/0007_configuration_is_login_required_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 5.1.2 on 2024-12-01 04:35 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('DiscoFlixClient', '0006_configuration_openai_model_name'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='configuration', | ||
name='is_login_required', | ||
field=models.BooleanField(default=False, verbose_name='Enable/Require User Login For WebUI'), | ||
), | ||
migrations.AlterField( | ||
model_name='configuration', | ||
name='is_verbose_logging', | ||
field=models.BooleanField(default=False, verbose_name='Verbose Logging In Console'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from rest_framework import permissions | ||
from DiscoFlixClient.models import Configuration | ||
|
||
class AllowGETUnauthenticated(permissions.BasePermission): | ||
|
||
def has_permission(self, request, view): | ||
if request.method == 'GET': | ||
return True | ||
return request.user and request.user.is_authenticated | ||
config = Configuration.objects.first() | ||
if config and config.is_login_required: | ||
return request.user and request.user.is_authenticated | ||
return request.method in ['GET'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.