mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-23 06:49:37 +02:00
better signup disable
This commit is contained in:
parent
80883202bc
commit
9f574c8505
9 changed files with 138 additions and 69 deletions
|
@ -4,7 +4,7 @@ from django.views.generic import RedirectView, TemplateView
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from adventures import urls as adventures
|
from adventures import urls as adventures
|
||||||
from users.views import ChangeEmailView
|
from users.views import ChangeEmailView, IsRegistrationDisabled
|
||||||
from .views import get_csrf_token
|
from .views import get_csrf_token
|
||||||
from drf_yasg.views import get_schema_view
|
from drf_yasg.views import get_schema_view
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ urlpatterns = [
|
||||||
path('api/', include('worldtravel.urls')),
|
path('api/', include('worldtravel.urls')),
|
||||||
|
|
||||||
path('auth/change-email/', ChangeEmailView.as_view(), name='change_email'),
|
path('auth/change-email/', ChangeEmailView.as_view(), name='change_email'),
|
||||||
|
path('auth/is-registration-disabled/', IsRegistrationDisabled.as_view(), name='is_registration_disabled'),
|
||||||
|
|
||||||
path('csrf/', get_csrf_token, name='get_csrf_token'),
|
path('csrf/', get_csrf_token, name='get_csrf_token'),
|
||||||
re_path(r'^$', TemplateView.as_view(
|
re_path(r'^$', TemplateView.as_view(
|
||||||
|
|
|
@ -5,6 +5,7 @@ from rest_framework.permissions import IsAuthenticated
|
||||||
from .serializers import ChangeEmailSerializer
|
from .serializers import ChangeEmailSerializer
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_yasg.utils import swagger_auto_schema
|
||||||
from drf_yasg import openapi
|
from drf_yasg import openapi
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
class ChangeEmailView(APIView):
|
class ChangeEmailView(APIView):
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
@ -29,3 +30,15 @@ class ChangeEmailView(APIView):
|
||||||
user.save()
|
user.save()
|
||||||
return Response({"detail": "Email successfully changed."}, status=status.HTTP_200_OK)
|
return Response({"detail": "Email successfully changed."}, status=status.HTTP_200_OK)
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
class IsRegistrationDisabled(APIView):
|
||||||
|
@swagger_auto_schema(
|
||||||
|
responses={
|
||||||
|
200: openapi.Response('Registration is disabled'),
|
||||||
|
400: 'Bad Request'
|
||||||
|
},
|
||||||
|
operation_description="Check if registration is disabled."
|
||||||
|
)
|
||||||
|
def get(self, request):
|
||||||
|
return Response({"is_disabled": settings.DISABLE_REGISTRATION}, status=status.HTTP_200_OK)
|
||||||
|
|
|
@ -48,7 +48,7 @@ services:
|
||||||
nginx:
|
nginx:
|
||||||
image: nginx:latest
|
image: nginx:latest
|
||||||
ports:
|
ports:
|
||||||
- "81:80" # Using port 81 to avoid conflict with your existing setup
|
- "81:80"
|
||||||
volumes:
|
volumes:
|
||||||
- adventurelog_media:/app/media
|
- adventurelog_media:/app/media
|
||||||
- ./proxy/nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
- ./proxy/nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||||
|
|
8
documentation/docs/Configuration/_category_.json
Normal file
8
documentation/docs/Configuration/_category_.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"label": "Configuration ⚙️",
|
||||||
|
"position": 3,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index",
|
||||||
|
"description": "Options for AdventureLog settings."
|
||||||
|
}
|
||||||
|
}
|
12
documentation/docs/Configuration/disable_registration.md
Normal file
12
documentation/docs/Configuration/disable_registration.md
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
sidebar_position: 1
|
||||||
|
---
|
||||||
|
|
||||||
|
# Disable Registration
|
||||||
|
|
||||||
|
To disable registration, you can set the following variable in your docker-compose.yml under the server service:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
environment:
|
||||||
|
- DISABLE_REGISTRATION=True
|
||||||
|
```
|
BIN
documentation/docs/Configuration/img/docsVersionDropdown.png
Normal file
BIN
documentation/docs/Configuration/img/docsVersionDropdown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
BIN
documentation/docs/Configuration/img/localeDropdown.png
Normal file
BIN
documentation/docs/Configuration/img/localeDropdown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
|
@ -2,13 +2,25 @@ import { error, fail, redirect } from '@sveltejs/kit';
|
||||||
|
|
||||||
import type { Actions, PageServerLoad } from './$types';
|
import type { Actions, PageServerLoad } from './$types';
|
||||||
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||||
|
const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
||||||
|
|
||||||
export const load: PageServerLoad = async (event) => {
|
export const load: PageServerLoad = async (event) => {
|
||||||
if (event.locals.user) {
|
if (event.locals.user) {
|
||||||
return redirect(302, '/');
|
return redirect(302, '/');
|
||||||
}
|
}
|
||||||
|
let is_disabled = await event.fetch(`${serverEndpoint}/auth/is-registration-disabled/`);
|
||||||
|
let is_disabled_json = await is_disabled.json();
|
||||||
|
console.log(is_disabled_json);
|
||||||
|
if (is_disabled_json.is_disabled) {
|
||||||
|
return {
|
||||||
|
is_disabled: true
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
is_disabled: false
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const actions: Actions = {
|
export const actions: Actions = {
|
||||||
default: async (event) => {
|
default: async (event) => {
|
||||||
const formData = await event.request.formData();
|
const formData = await event.request.formData();
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
class="min-h-screen bg-no-repeat bg-cover flex items-center justify-center"
|
class="min-h-screen bg-no-repeat bg-cover flex items-center justify-center"
|
||||||
style="background-image: url('{backgroundImageUrl}')"
|
style="background-image: url('{backgroundImageUrl}')"
|
||||||
>
|
>
|
||||||
|
{#if !data.is_disabled}
|
||||||
<div class="card card-compact w-96 bg-base-100 shadow-xl p-6 mt-4 mb-4">
|
<div class="card card-compact w-96 bg-base-100 shadow-xl p-6 mt-4 mb-4">
|
||||||
<article class="text-center text-4xl font-extrabold">
|
<article class="text-center text-4xl font-extrabold">
|
||||||
<h1>Signup</h1>
|
<h1>Signup</h1>
|
||||||
|
@ -93,6 +94,28 @@
|
||||||
</blockquote>
|
</blockquote>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="card card-compact w-96 bg-base-100 shadow-xl p-6 mt-4 mb-4">
|
||||||
|
<article class="text-center text-4xl font-extrabold">
|
||||||
|
<h1>Signup is disabled for this server.</h1>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
{#if errors.message}
|
||||||
|
<div class="text-center text-error mt-4">
|
||||||
|
{errors.message}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="flex justify-center mt-12 mr-25 ml-25">
|
||||||
|
<blockquote class="w-80 text-center text-lg break-words">
|
||||||
|
{#if quote != ''}
|
||||||
|
{quote}
|
||||||
|
{/if}
|
||||||
|
<!-- <footer class="text-sm">- Steve Jobs</footer> -->
|
||||||
|
</blockquote>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue