From 4456c0a509534f72bdda54192910e336300b9d70 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 5 Nov 2024 00:59:41 -0800 Subject: [PATCH 1/2] invite admin pop up --- email_service/__init__.py | 0 email_service/admin.py | 3 + email_service/apps.py | 6 + email_service/migrations/__init__.py | 0 email_service/models.py | 3 + email_service/tests.py | 3 + email_service/views.py | 3 + .../templates/wagtailusers/users/index.html | 157 ++++++++++++++++++ iogt_users/urls.py | 3 +- iogt_users/views.py | 56 +++++++ 10 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 email_service/__init__.py create mode 100644 email_service/admin.py create mode 100644 email_service/apps.py create mode 100644 email_service/migrations/__init__.py create mode 100644 email_service/models.py create mode 100644 email_service/tests.py create mode 100644 email_service/views.py create mode 100644 iogt_users/templates/wagtailusers/users/index.html diff --git a/email_service/__init__.py b/email_service/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/email_service/admin.py b/email_service/admin.py new file mode 100644 index 000000000..8c38f3f3d --- /dev/null +++ b/email_service/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/email_service/apps.py b/email_service/apps.py new file mode 100644 index 000000000..77879de71 --- /dev/null +++ b/email_service/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class EmailServiceConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'email_service' diff --git a/email_service/migrations/__init__.py b/email_service/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/email_service/models.py b/email_service/models.py new file mode 100644 index 000000000..71a836239 --- /dev/null +++ b/email_service/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/email_service/tests.py b/email_service/tests.py new file mode 100644 index 000000000..7ce503c2d --- /dev/null +++ b/email_service/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/email_service/views.py b/email_service/views.py new file mode 100644 index 000000000..91ea44a21 --- /dev/null +++ b/email_service/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/iogt_users/templates/wagtailusers/users/index.html b/iogt_users/templates/wagtailusers/users/index.html new file mode 100644 index 000000000..7e1f0eb9f --- /dev/null +++ b/iogt_users/templates/wagtailusers/users/index.html @@ -0,0 +1,157 @@ +{% extends "wagtailusers/users/index.html" %} +{% load wagtailadmin_tags i18n %} + +{% block content %} + {% trans "Users" as users_str %} + {% url "wagtailusers_users:add" as add_link %} + + {% include "wagtailadmin/shared/header.html" with subtitle=group.name title=users_str action_url=add_link action_text="Add a user" icon="user" search_url="wagtailusers_users:index" %} + +
+
+ +
+
+ + + + + + +{% endblock %} + +{% block extra_js %} + {{ block.super }} + +{% endblock %} diff --git a/iogt_users/urls.py b/iogt_users/urls.py index 9da0f41ed..d4d62ad03 100644 --- a/iogt_users/urls.py +++ b/iogt_users/urls.py @@ -1,7 +1,8 @@ from django.urls import path -from iogt_users.views import UserDetailEditView, UserDetailView +from iogt_users.views import UserDetailEditView, UserDetailView, InviteAdminUserView urlpatterns = [ path('profile/', UserDetailView.as_view(), name='user_profile'), path('profile/edit', UserDetailEditView.as_view(), name='user_profile_edit'), + path('invite-admin-user/', InviteAdminUserView.as_view(), name='invite_admin_user'), ] \ No newline at end of file diff --git a/iogt_users/views.py b/iogt_users/views.py index 5867de39c..ad82bfe43 100644 --- a/iogt_users/views.py +++ b/iogt_users/views.py @@ -4,6 +4,11 @@ from django.urls import reverse from django.utils.decorators import method_decorator from django.views.generic import UpdateView, TemplateView +from django.utils.decorators import method_decorator +from django.views.decorators.csrf import csrf_exempt +from django.http import JsonResponse +from django.views import View +from django.core.exceptions import ValidationError @method_decorator(login_required, name='dispatch') @@ -25,3 +30,54 @@ def get_success_url(self): def get_object(self, queryset=None): return self.request.user + +@method_decorator(csrf_exempt, name='dispatch') # To allow AJAX requests without CSRF token +@method_decorator(login_required, name='dispatch') +class InviteAdminUserView(View): + def post(self, request, *args, **kwargs): + # Retrieve form data + from django.contrib.auth import get_user_model + + User = get_user_model() + + first_name = request.POST.get('first_name', '').strip() + last_name = request.POST.get('last_name', '').strip() + email = request.POST.get('email', '').strip() + + errors = {} + + # Validate form fields + if not first_name: + errors['first_name'] = "First Name is required." + + if not last_name: + errors['last_name'] = "Last Name is required." + + if not email: + errors['email'] = "Email is required." + else: + # Basic email format validation + if '@' not in email or '.' not in email.split('@')[-1]: + errors['email'] = "Please enter a valid email address." + + # If there are errors, return them as JSON + if errors: + return JsonResponse({'success': False, 'errors': errors}, status=400) + + # If no errors, proceed with sending the invitation email + # Assume `User` is your user model and email is unique + user, created = User.objects.get_or_create( + email=email, + defaults={'first_name': first_name, 'last_name': last_name} + ) + + subject = "You are invited as an Admin" + context = { + 'user_name': f"{first_name} {last_name}" + } + + # Send email using the email service function + send_standard_email(user, subject, context) + + # Return a success response + return JsonResponse({'success': True}) From 058feb4238d20170981c12ee6fbcb042cf01bf87 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 5 Nov 2024 21:26:56 -0800 Subject: [PATCH 2/2] meta description issue fixed --- iogt/templates/base.html | 2 +- iogt_users/templates/wagtailusers/users/index.html | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/iogt/templates/base.html b/iogt/templates/base.html index f259dcd28..9abc17ff5 100644 --- a/iogt/templates/base.html +++ b/iogt/templates/base.html @@ -23,7 +23,7 @@ {% image settings.home.SiteSettings.favicon width-60 as favicon_img %} - + {% social_meta_tags %} diff --git a/iogt_users/templates/wagtailusers/users/index.html b/iogt_users/templates/wagtailusers/users/index.html index 7e1f0eb9f..6e2441d58 100644 --- a/iogt_users/templates/wagtailusers/users/index.html +++ b/iogt_users/templates/wagtailusers/users/index.html @@ -7,13 +7,13 @@ {% include "wagtailadmin/shared/header.html" with subtitle=group.name title=users_str action_url=add_link action_text="Add a user" icon="user" search_url="wagtailusers_users:index" %} -
-
- -
-
+{#
#} +{#
#} +{# #} +{#
#} +{#
#}