diff --git a/backend/LICENSE b/backend/LICENSE deleted file mode 100644 index 01c7bc7..0000000 --- a/backend/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -# Preface - -AdventureLog uses DjRestAuth, a Django REST Framework authentication backend for Django Rest Framework. DjRestAuth is licensed under the MIT License. - ---- - -## The MIT License (MIT) - -Copyright (c) 2014 iMerica https://github.com/iMerica/ - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/backend/README.md b/backend/README.md deleted file mode 100644 index 349b7be..0000000 --- a/backend/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# AdventureLog Django Backend -A demo of a possible AdventureLog 2.0 version using Django as the backend with a REST API. - -Based of django-rest-framework and dj-rest-auth. \ No newline at end of file diff --git a/backend/server/main/settings.py b/backend/server/main/settings.py index a185178..23d091f 100644 --- a/backend/server/main/settings.py +++ b/backend/server/main/settings.py @@ -11,7 +11,6 @@ https://docs.djangoproject.com/en/1.7/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os from dotenv import load_dotenv -from datetime import timedelta from os import getenv from pathlib import Path # Load environment variables from .env file @@ -35,8 +34,6 @@ DEBUG = getenv('DEBUG', 'True') == 'True' # ] ALLOWED_HOSTS = ['*'] -# Application definition - INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', @@ -50,7 +47,7 @@ INSTALLED_APPS = ( "allauth_ui", 'allauth', 'allauth.account', - 'allauth.mfa', + # 'allauth.mfa', 'allauth.headless', 'allauth.socialaccount', "widget_tweaks", @@ -108,7 +105,7 @@ DATABASES = { } } -ACCOUNT_SIGNUP_FORM_CLASS = 'users.form_overrides.CustomSignupForm' + # Internationalization # https://docs.djangoproject.com/en/1.7/topics/i18n/ @@ -123,8 +120,7 @@ USE_L10N = True USE_TZ = True -ALLAUTH_UI_THEME = "dark" -SILENCED_SYSTEM_CHECKS = ["slippers.E001"] + # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.7/howto/static-files/ @@ -138,6 +134,16 @@ MEDIA_URL = '/media/' MEDIA_ROOT = BASE_DIR / 'media' STATICFILES_DIRS = [BASE_DIR / 'static'] +STORAGES = { + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + }, + "default": { + "BACKEND": "django.core.files.storage.FileSystemStorage", + } +} + + TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', @@ -154,22 +160,22 @@ TEMPLATES = [ }, ] +# Authentication settings + DISABLE_REGISTRATION = getenv('DISABLE_REGISTRATION', 'False') == 'True' DISABLE_REGISTRATION_MESSAGE = getenv('DISABLE_REGISTRATION_MESSAGE', 'Registration is disabled. Please contact the administrator if you need an account.') -STORAGES = { - "staticfiles": { - "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", - }, - "default": { - "BACKEND": "django.core.files.storage.FileSystemStorage", - } -} +ALLAUTH_UI_THEME = "dark" +SILENCED_SYSTEM_CHECKS = ["slippers.E001"] AUTH_USER_MODEL = 'users.CustomUser' ACCOUNT_ADAPTER = 'users.adapters.NoNewUsersAccountAdapter' +ACCOUNT_SIGNUP_FORM_CLASS = 'users.form_overrides.CustomSignupForm' + +SESSION_SAVE_EVERY_REQUEST = True + FRONTEND_URL = getenv('FRONTEND_URL', 'http://localhost:3000') # HEADLESS_FRONTEND_URLS = { @@ -218,9 +224,6 @@ SWAGGER_SETTINGS = { 'LOGOUT_URL': 'logout', } -from os import getenv - - CORS_ALLOWED_ORIGINS = [origin.strip() for origin in getenv('CSRF_TRUSTED_ORIGINS', 'http://localhost').split(',') if origin.strip()] @@ -253,6 +256,4 @@ LOGGING = { }, } # https://github.com/dr5hn/countries-states-cities-database/tags -COUNTRY_REGION_JSON_VERSION = 'v2.4' - -SESSION_SAVE_EVERY_REQUEST = True \ No newline at end of file +COUNTRY_REGION_JSON_VERSION = 'v2.4' \ No newline at end of file diff --git a/backend/server/main/urls.py b/backend/server/main/urls.py index fa3456d..3e3c53f 100644 --- a/backend/server/main/urls.py +++ b/backend/server/main/urls.py @@ -3,8 +3,7 @@ from django.contrib import admin from django.views.generic import RedirectView, TemplateView from django.conf import settings from django.conf.urls.static import static -from adventures import urls as adventures -from users.views import ChangeEmailView, IsRegistrationDisabled, PublicUserListView, PublicUserDetailView, UserMetadataView +from users.views import IsRegistrationDisabled, PublicUserListView, PublicUserDetailView, UserMetadataView, UpdateUserMetadataView from .views import get_csrf_token from drf_yasg.views import get_schema_view @@ -19,56 +18,19 @@ schema_view = get_schema_view( urlpatterns = [ path('api/', include('adventures.urls')), path('api/', include('worldtravel.urls')), + path("_allauth/", include("allauth.headless.urls")), - path('auth/change-email/', ChangeEmailView.as_view(), name='change_email'), path('auth/is-registration-disabled/', IsRegistrationDisabled.as_view(), name='is_registration_disabled'), path('auth/users/', PublicUserListView.as_view(), name='public-user-list'), path('auth/user//', PublicUserDetailView.as_view(), name='public-user-detail'), + path('auth/update-user/', UpdateUserMetadataView.as_view(), name='update-user-metadata'), - path('auth/user-metadata/', UserMetadataView.as_view(), name='user-metadata'), - - + path('auth/user-metadata/', UserMetadataView.as_view(), name='user-metadata'), path('csrf/', get_csrf_token, name='get_csrf_token'), - re_path(r'^$', TemplateView.as_view( - template_name="home.html"), name='home'), - re_path(r'^signup/$', TemplateView.as_view(template_name="signup.html"), - name='signup'), - re_path(r'^email-verification/$', - TemplateView.as_view(template_name="email_verification.html"), - name='email-verification'), - re_path(r'^login/$', TemplateView.as_view(template_name="login.html"), - name='login'), - re_path(r'^logout/$', TemplateView.as_view(template_name="logout.html"), - name='logout'), - re_path(r'^password-reset/$', - TemplateView.as_view(template_name="password_reset.html"), - name='password-reset'), - re_path(r'^password-reset/confirm/$', - TemplateView.as_view(template_name="password_reset_confirm.html"), - name='password-reset-confirm'), - - re_path(r'^user-details/$', - TemplateView.as_view(template_name="user_details.html"), - name='user-details'), - re_path(r'^password-change/$', - TemplateView.as_view(template_name="password_change.html"), - name='password-change'), - re_path(r'^resend-email-verification/$', - TemplateView.as_view( - template_name="resend_email_verification.html"), - name='resend-email-verification'), - - - # this url is used to generate email content - re_path(r'^password-reset/confirm/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,32})/$', - TemplateView.as_view(template_name="password_reset_confirm.html"), - name='password_reset_confirm'), - - re_path(r'^auth/', include('dj_rest_auth.urls')), - re_path(r'^auth/registration/', - include('dj_rest_auth.registration.urls')), -# re_path(r'^account/', include('allauth.urls')), + + path('', TemplateView.as_view(template_name='home.html')), + re_path(r'^admin/', admin.site.urls), re_path(r'^accounts/profile/$', RedirectView.as_view(url='/', permanent=True), name='profile-redirect'), @@ -78,5 +40,5 @@ urlpatterns = [ path("accounts/", include("allauth.urls")), # Include the API endpoints: - path("_allauth/", include("allauth.headless.urls")), + ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/backend/server/requirements.txt b/backend/server/requirements.txt index 73b6e9a..0185310 100644 --- a/backend/server/requirements.txt +++ b/backend/server/requirements.txt @@ -1,7 +1,5 @@ Django==5.0.8 -dj-rest-auth @ git+https://github.com/iMerica/dj-rest-auth.git@master djangorestframework>=3.15.2 -djangorestframework-simplejwt==5.3.1 django-allauth==0.63.3 drf-yasg==1.21.4 django-cors-headers==4.4.0 diff --git a/backend/server/templates/base.html b/backend/server/templates/base.html index f8a7bd5..be712b7 100644 --- a/backend/server/templates/base.html +++ b/backend/server/templates/base.html @@ -4,8 +4,8 @@ - - + + AdventureLog API Server @@ -31,39 +31,6 @@