diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index a8b9b792fc..6d99e12ef8 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -17,13 +17,17 @@ from django.urls import reverse_lazy from django.shortcuts import redirect from django.conf import settings -from django.contrib.auth.mixins import PermissionRequiredMixin +from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin from django.views import View from django.views.generic import ListView, DetailView, CreateView, FormView, DeleteView, UpdateView from django.views.generic.base import RedirectView, TemplateView from djmoney.contrib.exchange.models import ExchangeBackend, Rate +from allauth.account.forms import AddEmailForm +from allauth.account.models import EmailAddress +from allauth.account.views import EmailView + from common.settings import currency_code_default, currency_codes from part.models import Part, PartCategory @@ -810,6 +814,10 @@ class SettingsView(TemplateView): except: ctx["locale_stats"] = {} + # Forms and context for allauth + ctx['add_email_form'] = AddEmailForm + ctx["can_add_email"] = EmailAddress.objects.can_add_email(self.request.user) + return ctx class CustomEmailView(LoginRequiredMixin, EmailView): diff --git a/InvenTree/templates/InvenTree/settings/user.html b/InvenTree/templates/InvenTree/settings/user.html index 1acad0bb87..39309eab73 100644 --- a/InvenTree/templates/InvenTree/settings/user.html +++ b/InvenTree/templates/InvenTree/settings/user.html @@ -39,6 +39,63 @@ +
+

{% trans "E-Mail" %}

+
+ +
+ {% if user.emailaddress_set.all %} +

{% trans 'The following e-mail addresses are associated with your account:' %}

+ +
+ {% csrf_token %} +
+ + {% for emailaddress in user.emailaddress_set.all %} +
+ +
+ {% endfor %} + +
+ + + +
+ +
+
+ + {% else %} +

{% trans 'Warning:'%} + {% trans "You currently do not have any e-mail address set up. You should really add an e-mail address so you can receive notifications, reset your password, etc." %} +

+ + {% endif %} + + {% if can_add_email %} +

{% trans "Add E-mail Address" %}

+ +
+ {% csrf_token %} + {{ add_email_form.as_p }} + +
+ {% endif %} +
+
+

{% trans "Social Accounts" %}

@@ -156,4 +213,18 @@ +{% endblock %} + +{% block js_ready %} +(function() { + var message = "{% trans 'Do you really want to remove the selected e-mail address?' %}"; + var actions = document.getElementsByName('action_remove'); + if (actions.length) { + actions[0].addEventListener("click", function(e) { + if (! confirm(message)) { + e.preventDefault(); + } + }); + } +})(); {% endblock %} \ No newline at end of file