mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-02 19:55:18 +02:00
Refactor user serializers, update Docker configurations, and remove unused Nginx files
This commit is contained in:
parent
84566b8ec1
commit
50dc0424a9
5 changed files with 21 additions and 41 deletions
|
@ -2,23 +2,13 @@ from rest_framework import serializers
|
|||
from django.contrib.auth import get_user_model
|
||||
|
||||
from adventures.models import Collection
|
||||
from dj_rest_auth.serializers import PasswordResetSerializer
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
|
||||
try:
|
||||
from allauth.account import app_settings as allauth_account_settings
|
||||
from allauth.account.adapter import get_adapter
|
||||
from allauth.account.utils import setup_user_email
|
||||
from allauth.socialaccount.models import EmailAddress
|
||||
from allauth.utils import get_username_max_length
|
||||
except ImportError:
|
||||
raise ImportError('allauth needs to be added to INSTALLED_APPS.')
|
||||
|
||||
class ChangeEmailSerializer(serializers.Serializer):
|
||||
new_email = serializers.EmailField(required=True)
|
||||
|
@ -37,7 +27,7 @@ from django.contrib.auth import get_user_model
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
UserModel = get_user_model()
|
||||
from dj_rest_auth.serializers import UserDetailsSerializer
|
||||
# from dj_rest_auth.serializers import UserDetailsSerializer
|
||||
from .models import CustomUser
|
||||
|
||||
from rest_framework import serializers
|
||||
|
@ -77,9 +67,9 @@ class UserDetailsSerializer(serializers.ModelSerializer):
|
|||
if hasattr(UserModel, 'public_profile'):
|
||||
extra_fields.append('public_profile')
|
||||
|
||||
class Meta(UserDetailsSerializer.Meta):
|
||||
class Meta:
|
||||
model = CustomUser
|
||||
fields = UserDetailsSerializer.Meta.fields + ('profile_pic', 'uuid', 'public_profile')
|
||||
fields = ('profile_pic', 'uuid', 'public_profile', 'email', 'date_joined', 'is_staff', 'is_superuser', 'is_active', 'pk')
|
||||
|
||||
model = UserModel
|
||||
fields = ('pk', *extra_fields)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
services:
|
||||
web:
|
||||
#build: ./frontend/
|
||||
image: ghcr.io/seanmorley15/adventurelog-frontend:latest
|
||||
build: ./frontend/
|
||||
#image: ghcr.io/seanmorley15/adventurelog-frontend:latest
|
||||
container_name: adventurelog-frontend
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
|
@ -14,7 +14,7 @@ services:
|
|||
- server
|
||||
|
||||
db:
|
||||
image: postgis/postgis:15-3.3
|
||||
image: postgis/postgis:16-3.4
|
||||
container_name: adventurelog-db
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
|
@ -25,8 +25,8 @@ services:
|
|||
- postgres_data:/var/lib/postgresql/data/
|
||||
|
||||
server:
|
||||
#build: ./backend/
|
||||
image: ghcr.io/seanmorley15/adventurelog-backend:latest
|
||||
build: ./backend/
|
||||
#image: ghcr.io/seanmorley15/adventurelog-backend:latest
|
||||
container_name: adventurelog-backend
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
|
@ -39,7 +39,7 @@ services:
|
|||
- DJANGO_ADMIN_PASSWORD=admin
|
||||
- DJANGO_ADMIN_EMAIL=admin@example.com
|
||||
- PUBLIC_URL='http://localhost:8016' # Match the outward port, used for the creation of image urls
|
||||
- CSRF_TRUSTED_ORIGINS=http://localhost:8016 # Comma separated list of trusted origins for CSRF
|
||||
- CSRF_TRUSTED_ORIGINS=http://localhost:8016,http://localhost:8015 # Comma separated list of trusted origins for CSRF
|
||||
- DEBUG=False
|
||||
- FRONTEND_URL='http://localhost:8015' # Used for email generation. This should be the url of the frontend
|
||||
ports:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||
import { redirect, type Actions } from '@sveltejs/kit';
|
||||
import { themes } from '$lib';
|
||||
import { fetchCSRFToken } from '$lib/index.server';
|
||||
|
||||
const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
||||
|
||||
|
@ -16,23 +17,24 @@ export const actions: Actions = {
|
|||
});
|
||||
}
|
||||
},
|
||||
logout: async ({ cookies }: { cookies: any }) => {
|
||||
const cookie = cookies.get('auth') || null;
|
||||
logout: async (event) => {
|
||||
let sessionId = event.cookies.get('sessionid');
|
||||
let csrfToken = await fetchCSRFToken();
|
||||
|
||||
if (!cookie) {
|
||||
if (!sessionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await fetch(`${serverEndpoint}/auth/logout/`, {
|
||||
method: 'POST',
|
||||
const res = await fetch(`${serverEndpoint}/_allauth/browser/v1/auth/session`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Cookie: cookies.get('auth')
|
||||
}
|
||||
Cookie: `sessionid=${sessionId}; csrftoken=${csrfToken}`,
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
credentials: 'include'
|
||||
});
|
||||
if (res.ok) {
|
||||
cookies.delete('auth', { path: '/', secure: false });
|
||||
cookies.delete('refresh', { path: '/', secure: false });
|
||||
if (res.status == 401) {
|
||||
return redirect(302, '/login');
|
||||
} else {
|
||||
return redirect(302, '/');
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
FROM nginx:alpine
|
||||
|
||||
RUN rm /etc/nginx/conf.d/default.conf
|
||||
COPY nginx.conf /etc/nginx/conf.d
|
|
@ -1,8 +0,0 @@
|
|||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
location /media/ {
|
||||
alias /app/media/;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue