email verification

This commit is contained in:
Jaya Surya 2023-07-29 17:39:34 +05:30
parent 4e559ca7ea
commit 67994a5429
3 changed files with 45 additions and 16 deletions

View File

@ -9,6 +9,7 @@ from import_export.admin import ImportExportMixin, ExportMixin
from import_export import resources
from .models import *
from .utils import send_email_for_opening
class ArrayFieldListFilter(admin.SimpleListFilter):
@ -109,10 +110,20 @@ class PlacementResources(resources.ModelResource):
class AdminAdmin(ExportMixin, SimpleHistoryAdmin):
resource_class = PlacementResources
def save_model(self, request, obj, form, change):
# Check if email_verified field is being changed from False to True
if change and not obj._state.adding and obj.email_verified and form.initial.get('email_verified', False) != obj.email_verified:
# Run the send_email_for_opening function
send_email_for_opening(obj)
# Save the model as usual
super().save_model(request, obj, form, change)
@admin.register(Placement)
class Placement(AdminAdmin):
list_display = (COMPANY_NAME, CONTACT_PERSON_NAME, PHONE_NUMBER, 'tier', 'compensation_CTC')
list_display = (COMPANY_NAME, CONTACT_PERSON_NAME, PHONE_NUMBER, 'tier', 'compensation_CTC', 'email_verified')
search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME)
ordering = (COMPANY_NAME, CONTACT_PERSON_NAME, 'tier', 'compensation_CTC')
list_filter = ('tier',)

View File

@ -285,20 +285,7 @@ def verifyEmail(request):
if send_email_to_company:
# Email sending part.
pdfhtml = opening_description_table_html(opening)
name = opening.company_name + '_jnf_response.pdf'
attachment_jnf_respone = {
"name": name,
"html": pdfhtml,
}
data = {
"designation": opening.designation,
"opening_type": opening_type,
"company_name": opening.company_name,
}
sendEmail([opening.email, CDC_MAIl_ADDRESS],
COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT.format(id=opening.id), data,
COMPANY_OPENING_SUBMITTED_TEMPLATE, attachment_jnf_respone)
send_email_for_opening(opening)
return Response({'action': "Verify Email", 'message': "Email Verified Successfully"},
status=status.HTTP_200_OK)

View File

@ -61,7 +61,9 @@ def get_token():
logger.warning("Get Token: " + str(sys.exc_info()))
return Response({'action': "Get Token", 'message': str(e)},
status=status.HTTP_400_BAD_REQUEST)
return wrapper_func
return decorator
@ -120,7 +122,8 @@ def isAuthorized(allowed_users=None):
user.save()
if len(set(user.user_type).intersection(set(allowed_users))) or allowed_users == '*':
if "MODIFIED" in headers:
return view_func(request, user.id, user.email, user.user_type, token_id, *args, **kwargs)
return view_func(request, user.id, user.email, user.user_type, token_id, *args,
**kwargs)
else:
return view_func(request, user.id, user.email, user.user_type, *args, **kwargs)
else:
@ -438,3 +441,31 @@ def store_all_files(request):
for file in files.getlist(DESCRIPTION_PDF):
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + "temp" + '/'
saveFile(file, file_location)
def send_email_for_opening(opening):
try:
# Prepare email data and attachment
pdfhtml = opening_description_table_html(opening)
name = opening.company_name + '_jnf_response.pdf'
attachment_jnf_respone = {
"name": name,
"html": pdfhtml,
}
data = {
"designation": opening.designation,
"opening_type": "INTERNSHIP" if isinstance(opening, Internship) else "PLACEMENT",
"company_name": opening.company_name,
}
# Send the email
sendEmail([opening.email, CDC_MAIl_ADDRESS],
COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT.format(id=opening.id), data,
COMPANY_OPENING_SUBMITTED_TEMPLATE, attachment_jnf_respone)
except Exception as e:
# Handle the exception here (e.g., log the error, send an error email, etc.)
print("An error occurred while sending the email:", e)