diff --git a/InvenTree/InvenTree/exceptions.py b/InvenTree/InvenTree/exceptions.py index 2dfda365c5..1b7dcbb20e 100644 --- a/InvenTree/InvenTree/exceptions.py +++ b/InvenTree/InvenTree/exceptions.py @@ -3,11 +3,13 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +import logging import sys import traceback from django.conf import settings from django.core.exceptions import ValidationError as DjangoValidationError +from django.db.utils import IntegrityError, OperationalError from django.utils.translation import gettext_lazy as _ import rest_framework.views as drfviews @@ -16,6 +18,8 @@ from rest_framework import serializers from rest_framework.exceptions import ValidationError as DRFValidationError from rest_framework.response import Response +logger = logging.getLogger('inventree') + def log_error(path): """Log an error to the database. @@ -32,12 +36,19 @@ def log_error(path): if kind in settings.IGNORED_ERRORS: return - Error.objects.create( - kind=kind.__name__, - info=info, - data='\n'.join(traceback.format_exception(kind, info, data)), - path=path, - ) + # Log error to stderr + logger.error(info) + + try: + Error.objects.create( + kind=kind.__name__, + info=info, + data='\n'.join(traceback.format_exception(kind, info, data)), + path=path, + ) + except (OperationalError, IntegrityError): + # Not much we can do if logging the error throws a db exception + pass def exception_handler(exc, context): diff --git a/InvenTree/InvenTree/forms.py b/InvenTree/InvenTree/forms.py index aa1f93d0e1..24627abf78 100644 --- a/InvenTree/InvenTree/forms.py +++ b/InvenTree/InvenTree/forms.py @@ -23,6 +23,7 @@ from crispy_forms.helper import FormHelper from crispy_forms.layout import Field, Layout from common.models import InvenTreeSetting +from InvenTree.exceptions import log_error logger = logging.getLogger('inventree') @@ -239,10 +240,20 @@ class CustomUrlMixin: class CustomAccountAdapter(CustomUrlMixin, RegistratonMixin, OTPAdapter, DefaultAccountAdapter): """Override of adapter to use dynamic settings.""" + def send_mail(self, template_prefix, email, context): """Only send mail if backend configured.""" if settings.EMAIL_HOST: - return super().send_mail(template_prefix, email, context) + try: + result = super().send_mail(template_prefix, email, context) + except Exception: + # An exception ocurred while attempting to send email + # Log it (for admin users) and return silently + log_error('account email') + result = False + + return result + return False diff --git a/InvenTree/InvenTree/static/css/inventree.css b/InvenTree/InvenTree/static/css/inventree.css index c2fa1b9a75..cedc42beaf 100644 --- a/InvenTree/InvenTree/static/css/inventree.css +++ b/InvenTree/InvenTree/static/css/inventree.css @@ -1070,3 +1070,24 @@ a { margin-left: 0.25rem; margin-right: 0.25rem; } + +.sso-header { + text-align: center; + width: 100%; + padding-bottom: 10px; +} + +.sso-provider-list { + width: 100%; + list-style-type: none; + padding-left: 0px; +} + +.sso-provider-link { + width: 100%; +} + +.sso-provider-link a { + width: 100%; + text-align: left; +} \ No newline at end of file diff --git a/InvenTree/templates/InvenTree/settings/login.html b/InvenTree/templates/InvenTree/settings/login.html index a52e35fb12..edb77207e1 100644 --- a/InvenTree/templates/InvenTree/settings/login.html +++ b/InvenTree/templates/InvenTree/settings/login.html @@ -11,9 +11,14 @@ {% block content %} +{% if not email_configured %} +
+ {% trans "Outgoing email has not been configured. Some login and sign-up features may not work correctly!" %} +
+{% endif %} + - {% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_SSO" icon="fa-user-shield" %} {% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_PWD_FORGOT" icon="fa-user-lock" %} {% include "InvenTree/settings/setting.html" with key="LOGIN_MAIL_REQUIRED" icon="fa-at" %} {% include "InvenTree/settings/setting.html" with key="LOGIN_ENFORCE_MFA" icon='fa-key' %} @@ -24,8 +29,13 @@ {% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_REG" icon="fa-user-plus" %} {% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_MAIL_TWICE" icon="fa-at" %} {% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_PWD_TWICE" icon="fa-user-lock" %} - {% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_SSO_AUTO" icon="fa-key" %} {% include "InvenTree/settings/setting.html" with key="SIGNUP_GROUP" icon="fa-users" %} + + + + + {% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_SSO" icon="fa-user-shield" %} + {% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_SSO_AUTO" icon="fa-key" %}
{% trans 'Single Sign On' %}
diff --git a/InvenTree/templates/account/base.html b/InvenTree/templates/account/base.html index f71f2afcaf..fc56fbdeb4 100644 --- a/InvenTree/templates/account/base.html +++ b/InvenTree/templates/account/base.html @@ -76,6 +76,7 @@ {% endblock %} + {% block extra_body %} @@ -87,6 +88,7 @@ {% include "third_party_js.html" %} +