Skip to content

Commit

Permalink
meta tag description changes (#1712)
Browse files Browse the repository at this point in the history
  • Loading branch information
vimugdhabatra authored Nov 6, 2024
2 parents bf82116 + 058feb4 commit edc9735
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 2 deletions.
Empty file added email_service/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions email_service/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions email_service/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class EmailServiceConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'email_service'
Empty file.
3 changes: 3 additions & 0 deletions email_service/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions email_service/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions email_service/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
2 changes: 1 addition & 1 deletion iogt/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</title>
{% image settings.home.SiteSettings.favicon width-60 as favicon_img %}
<link rel="shortcut icon" type="image/jpg" href="{{ favicon_img.url }}"/>
<meta name="description" content=""/>
<meta name="description" content="{% firstof page.search_description site_name %}"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="theme-color" content="#493174">
{% social_meta_tags %}
Expand Down
157 changes: 157 additions & 0 deletions iogt_users/templates/wagtailusers/users/index.html
Original file line number Diff line number Diff line change
@@ -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" %}

{# <div class="nice-padding">#}
{# <div class="action-buttons">#}
{# <button id="invite-admin-button" class="button button--icon" style="margin-left: 10px;">#}
{# {% icon name="plus" wrapped=1 %} Invite Admin User#}
{# </button>#}
{# </div>#}
{# </div>#}

<!-- Modal for Inviting Admin User -->
<div id="invite-admin-modal" class="modal">
<div class="modal-content">
<span class="close-button" id="close-modal">&times;</span>
<h2>Invite Admin User</h2>
<form id="invite-admin-form">
<label for="first_name">First Name:</label>
<input type="text" id="first_name" name="first_name" placeholder="Enter First Name">
<span class="error-message" id="first_name_error" style="color: red; display: none;"></span>

<label for="last_name">Last Name:</label>
<input type="text" id="last_name" name="last_name" placeholder="Enter Last Name">
<span class="error-message" id="last_name_error" style="color: red; display: none;"></span>

<label for="email">Email Address:</label>
<input type="text" id="email" name="email" placeholder="Enter Email" title="Please enter a valid email address">
<span class="error-message" id="email_error" style="color: red; display: none;"></span>

<button type="submit" class="button button--icon" style="margin-left: 10px;">Send Invite</button>
</form>
</div>
</div>

<style>
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.close-button {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close-button:hover,
.close-button:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
.error-message {
display: block;
color: red;
}
</style>

{% endblock %}

{% block extra_js %}
{{ block.super }}
<script>
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('invite-admin-button').onclick = function() {
document.getElementById('invite-admin-modal').style.display = 'block';
resetErrorMessages();
};

document.getElementById('close-modal').onclick = function() {
document.getElementById('invite-admin-modal').style.display = 'none';
};

document.getElementById('invite-admin-form').onsubmit = function(event) {
event.preventDefault();
resetErrorMessages();

const firstName = document.getElementById('first_name').value;
const lastName = document.getElementById('last_name').value;
const email = document.getElementById('email').value;

let isValid = true;

if (firstName.trim() === "") {
document.getElementById('first_name_error').textContent = "First Name is required.";
document.getElementById('first_name_error').style.display = 'block';
isValid = false;
}
if (lastName.trim() === "") {
document.getElementById('last_name_error').textContent = "Last Name is required.";
document.getElementById('last_name_error').style.display = 'block';
isValid = false;
}
if (!validateEmail(email)) {
document.getElementById('email_error').textContent = "Please enter a valid email address.";
document.getElementById('email_error').style.display = 'block';
isValid = false;
}

if (isValid) {
const formData = new FormData(this);

fetch("{% url 'invite_admin_user' %}", {
method: 'POST',
body: formData,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
document.getElementById('invite-admin-modal').style.display = 'none';
this.reset();
} else {
for (const [key, value] of Object.entries(data.errors)) {
document.getElementById(key + '_error').textContent = value;
document.getElementById(key + '_error').style.display = 'block';
}
}
})
.catch(error => console.error('Error:', error));
}
};

function validateEmail(email) {
const re = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
return re.test(String(email).toLowerCase());
}

function resetErrorMessages() {
document.getElementById('first_name_error').textContent = '';
document.getElementById('last_name_error').textContent = '';
document.getElementById('email_error').textContent = '';
}
});
</script>
{% endblock %}
3 changes: 2 additions & 1 deletion iogt_users/urls.py
Original file line number Diff line number Diff line change
@@ -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'),
]
56 changes: 56 additions & 0 deletions iogt_users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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})

0 comments on commit edc9735

Please sign in to comment.