mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Email fix (#5396)
* Construct absolute URL when sending email confirmation * Implement required changes to auth URLs * Fix unit test
This commit is contained in:
parent
131442b6c7
commit
e468227fbe
@ -292,6 +292,15 @@ class CustomAccountAdapter(CustomUrlMixin, RegistratonMixin, OTPAdapter, Default
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_email_confirmation_url(self, request, emailconfirmation):
|
||||||
|
"""Construct the email confirmation url"""
|
||||||
|
|
||||||
|
from InvenTree.helpers_model import construct_absolute_url
|
||||||
|
|
||||||
|
url = super().get_email_confirmation_url(request, emailconfirmation)
|
||||||
|
url = construct_absolute_url(url)
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
class CustomSocialAccountAdapter(CustomUrlMixin, RegistratonMixin, DefaultSocialAccountAdapter):
|
class CustomSocialAccountAdapter(CustomUrlMixin, RegistratonMixin, DefaultSocialAccountAdapter):
|
||||||
"""Override of adapter to use dynamic settings."""
|
"""Override of adapter to use dynamic settings."""
|
||||||
|
@ -50,9 +50,7 @@ def construct_absolute_url(*arg, **kwargs):
|
|||||||
# Otherwise, try to use the InvenTree setting
|
# Otherwise, try to use the InvenTree setting
|
||||||
try:
|
try:
|
||||||
site_url = common.models.InvenTreeSetting.get_setting('INVENTREE_BASE_URL', create=False, cache=False)
|
site_url = common.models.InvenTreeSetting.get_setting('INVENTREE_BASE_URL', create=False, cache=False)
|
||||||
except ProgrammingError:
|
except (ProgrammingError, OperationalError):
|
||||||
pass
|
|
||||||
except OperationalError:
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not site_url:
|
if not site_url:
|
||||||
|
@ -608,7 +608,8 @@ REMOTE_LOGIN_HEADER = get_setting('INVENTREE_REMOTE_LOGIN_HEADER', 'remote_login
|
|||||||
|
|
||||||
# Magic login django-sesame
|
# Magic login django-sesame
|
||||||
SESAME_MAX_AGE = 300
|
SESAME_MAX_AGE = 300
|
||||||
LOGIN_REDIRECT_URL = "/platform/logged-in/"
|
# LOGIN_REDIRECT_URL = "/platform/logged-in/"
|
||||||
|
LOGIN_REDIRECT_URL = "/index/"
|
||||||
|
|
||||||
# sentry.io integration for error reporting
|
# sentry.io integration for error reporting
|
||||||
SENTRY_ENABLED = get_boolean_setting('INVENTREE_SENTRY_ENABLED', 'sentry_enabled', False)
|
SENTRY_ENABLED = get_boolean_setting('INVENTREE_SENTRY_ENABLED', 'sentry_enabled', False)
|
||||||
|
@ -1180,6 +1180,9 @@ class MagicLoginTest(InvenTreeTestCase):
|
|||||||
# Check that the login works
|
# Check that the login works
|
||||||
resp = self.client.get(reverse('sesame-login') + '?sesame=' + token)
|
resp = self.client.get(reverse('sesame-login') + '?sesame=' + token)
|
||||||
self.assertEqual(resp.status_code, 302)
|
self.assertEqual(resp.status_code, 302)
|
||||||
self.assertEqual(resp.url, '/platform/logged-in/')
|
self.assertEqual(resp.url, '/index/')
|
||||||
|
# Note: 2023-08-08 - This test has been changed because "platform UI" is not generally available yet
|
||||||
|
# TODO: In the future, the URL comparison will need to be reverted
|
||||||
|
# self.assertEqual(resp.url, '/platform/logged-in/')
|
||||||
# And we should be logged in again
|
# And we should be logged in again
|
||||||
self.assertEqual(resp.wsgi_request.user, self.user)
|
self.assertEqual(resp.wsgi_request.user, self.user)
|
||||||
|
@ -10,7 +10,8 @@ from django.urls import include, path, re_path
|
|||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.views.generic.base import RedirectView
|
from django.views.generic.base import RedirectView
|
||||||
|
|
||||||
from dj_rest_auth.registration.views import (SocialAccountDisconnectView,
|
from dj_rest_auth.registration.views import (ConfirmEmailView,
|
||||||
|
SocialAccountDisconnectView,
|
||||||
SocialAccountListView)
|
SocialAccountListView)
|
||||||
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView
|
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView
|
||||||
from sesame.views import LoginView
|
from sesame.views import LoginView
|
||||||
@ -79,13 +80,16 @@ apipatterns = [
|
|||||||
# InvenTree information endpoint
|
# InvenTree information endpoint
|
||||||
path('', InfoView.as_view(), name='api-inventree-info'),
|
path('', InfoView.as_view(), name='api-inventree-info'),
|
||||||
|
|
||||||
# Third party API endpoints
|
# Auth API endpoints
|
||||||
path('auth/', include('dj_rest_auth.urls')),
|
path('auth/', include([
|
||||||
path('auth/registration/', include('dj_rest_auth.registration.urls')),
|
re_path(r'^registration/account-confirm-email/(?P<key>[-:\w]+)/$', ConfirmEmailView.as_view(), name='account_confirm_email'),
|
||||||
path('auth/providers/', SocialProvierListView.as_view(), name='social_providers'),
|
path('registration/', include('dj_rest_auth.registration.urls')),
|
||||||
path('auth/social/', include(social_auth_urlpatterns)),
|
path('providers/', SocialProvierListView.as_view(), name='social_providers'),
|
||||||
path('auth/social/', SocialAccountListView.as_view(), name='social_account_list'),
|
path('social/', include(social_auth_urlpatterns)),
|
||||||
path('auth/social/<int:pk>/disconnect/', SocialAccountDisconnectView.as_view(), name='social_account_disconnect'),
|
path('social/', SocialAccountListView.as_view(), name='social_account_list'),
|
||||||
|
path('social/<int:pk>/disconnect/', SocialAccountDisconnectView.as_view(), name='social_account_disconnect'),
|
||||||
|
path('', include('dj_rest_auth.urls')),
|
||||||
|
])),
|
||||||
|
|
||||||
# Magic login URLs
|
# Magic login URLs
|
||||||
path("email/generate/", csrf_exempt(GetSimpleLoginView().as_view()), name="sesame-generate",),
|
path("email/generate/", csrf_exempt(GetSimpleLoginView().as_view()), name="sesame-generate",),
|
||||||
|
Loading…
Reference in New Issue
Block a user