From 5aca27f2852a6583022f566580ce47e6e0b93d53 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 31 Aug 2021 23:51:33 +0200 Subject: [PATCH] integrate email-actions into settings --- InvenTree/InvenTree/views.py | 10 ++- .../templates/InvenTree/settings/user.html | 71 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) 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:' %}

+ + + + {% 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