Merge pull request #169 from CDC-IITDH/email_verify_manual

email verification
This commit is contained in:
karthik mv 2023-08-02 23:32:16 +05:30 committed by GitHub
commit 0269093ad6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 92 additions and 26 deletions

View File

@ -9,6 +9,7 @@ from import_export.admin import ImportExportMixin, ExportMixin
from import_export import resources from import_export import resources
from .models import * from .models import *
from .utils import send_email_for_opening
class ArrayFieldListFilter(admin.SimpleListFilter): class ArrayFieldListFilter(admin.SimpleListFilter):
@ -109,12 +110,22 @@ class PlacementResources(resources.ModelResource):
class AdminAdmin(ExportMixin, SimpleHistoryAdmin): class AdminAdmin(ExportMixin, SimpleHistoryAdmin):
resource_class = PlacementResources 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) @admin.register(Placement)
class Placement(AdminAdmin): 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', 'updated_at')
search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME) search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME)
ordering = (COMPANY_NAME, CONTACT_PERSON_NAME, 'tier', 'compensation_CTC') ordering = ('updated_at', COMPANY_NAME, CONTACT_PERSON_NAME, 'tier', 'compensation_CTC')
list_filter = ('tier',) list_filter = ('tier',)
@ -162,4 +173,29 @@ class PrePlacementOffer(PrePlacementOfferAdmin):
def Student(self, obj): def Student(self, obj):
return model_admin_url(obj.student) return model_admin_url(obj.student)
admin.site.register(Internship)
class InternshipResources(resources.ModelResource):
class Meta:
model = Internship
exclude = ('id', 'changed_by', 'is_company_details_pdf', 'is_description_pdf',
'is_compensation_details_pdf', 'is_selection_procedure_details_pdf')
class InternAdmin(ExportMixin, SimpleHistoryAdmin):
resource_class = InternshipResources
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)
super().save_model(request, obj, form, change)
@admin.register(Internship)
class Placement(InternAdmin):
list_display = (COMPANY_NAME, CONTACT_PERSON_NAME, PHONE_NUMBER, 'stipend', 'email_verified', 'updated_at')
search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME)
ordering = ('updated_at', COMPANY_NAME, CONTACT_PERSON_NAME, 'stipend')

View File

@ -221,7 +221,8 @@ def addPlacement(request):
raise RuntimeError("Error in generating one time verification link for placement") raise RuntimeError("Error in generating one time verification link for placement")
data = { data = {
"designation": opening.designation, "designation": opening.designation,
"one_time_link": link "one_time_link": link,
"opening_type": "Job"
} }
sendEmail(opening.email, COMPANY_EMAIl_VERIFICATION_TEMPLATE_SUBJECT, data, sendEmail(opening.email, COMPANY_EMAIl_VERIFICATION_TEMPLATE_SUBJECT, data,
@ -285,20 +286,7 @@ def verifyEmail(request):
if send_email_to_company: if send_email_to_company:
# Email sending part. # Email sending part.
pdfhtml = opening_description_table_html(opening) send_email_for_opening(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)
return Response({'action': "Verify Email", 'message': "Email Verified Successfully"}, return Response({'action': "Verify Email", 'message': "Email Verified Successfully"},
status=status.HTTP_200_OK) status=status.HTTP_200_OK)
@ -493,7 +481,8 @@ def addInternship(request):
raise RuntimeError("Error in generating one time verification link for internship") raise RuntimeError("Error in generating one time verification link for internship")
data = { data = {
"designation": internship.designation, "designation": internship.designation,
"one_time_link": link "one_time_link": link,
"opening_type": "Internship"
} }
sendEmail(internship.email, COMPANY_EMAIl_VERIFICATION_TEMPLATE_SUBJECT, data, sendEmail(internship.email, COMPANY_EMAIl_VERIFICATION_TEMPLATE_SUBJECT, data,

View File

@ -1,5 +1,7 @@
import os import os
DEBUG = os.environ.get('DEBUG')
BRANCH_CHOICES = [ BRANCH_CHOICES = [
["CSE", "CSE"], ["CSE", "CSE"],
["EE", "EE"], ["EE", "EE"],
@ -160,7 +162,7 @@ SPECIAL_FORMAT_IN_PDF = ['website', 'company_details_pdf_names', 'description_pd
'stipend_description_pdf_names'] 'stipend_description_pdf_names']
COMPANY_OPENING_ERROR_TEMPLATE = "Alert! Error submitting opening for {company_name}." COMPANY_OPENING_ERROR_TEMPLATE = "Alert! Error submitting opening for {company_name}."
COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT = "Notification Submitted - {id} - Career Development Cell, IIT Dharwad" COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT = "Notification Submitted - {id}, {company} - Career Development Cell, IIT Dharwad"
STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT = 'Application Status - {company_name} - {id}' STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT = 'Application Status - {company_name} - {id}'
STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT = 'CDC - Application Submitted - {company_name}' STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT = 'CDC - Application Submitted - {company_name}'
STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT = 'CDC - Application Updated - {company_name}' STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT = 'CDC - Application Updated - {company_name}'

View File

@ -61,7 +61,9 @@ def get_token():
logger.warning("Get Token: " + str(sys.exc_info())) logger.warning("Get Token: " + str(sys.exc_info()))
return Response({'action': "Get Token", 'message': str(e)}, return Response({'action': "Get Token", 'message': str(e)},
status=status.HTTP_400_BAD_REQUEST) status=status.HTTP_400_BAD_REQUEST)
return wrapper_func return wrapper_func
return decorator return decorator
@ -120,7 +122,8 @@ def isAuthorized(allowed_users=None):
user.save() user.save()
if len(set(user.user_type).intersection(set(allowed_users))) or allowed_users == '*': if len(set(user.user_type).intersection(set(allowed_users))) or allowed_users == '*':
if "MODIFIED" in headers: 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: else:
return view_func(request, user.id, user.email, user.user_type, *args, **kwargs) return view_func(request, user.id, user.email, user.user_type, *args, **kwargs)
else: else:
@ -438,3 +441,35 @@ def store_all_files(request):
for file in files.getlist(DESCRIPTION_PDF): for file in files.getlist(DESCRIPTION_PDF):
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + "temp" + '/' file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + "temp" + '/'
saveFile(file, file_location) 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,
}
if DEBUG:
emails = [opening.email]
else:
emails = [opening.email, CDC_MAIl_ADDRESS]
# Send the email
sendEmail(emails,
COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT.format(id=opening.designation, company=opening.company_name), 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)

View File

@ -157,10 +157,14 @@ CORS_ORIGIN_WHITELIST = [
CORS_REPLACE_HTTPS_REFERER = True CORS_REPLACE_HTTPS_REFERER = True
CSRF_TRUSTED_ORIGINS = [ "https://cdc.iitdh.ac.in", "http://cdc.iitdh.ac.in"] CSRF_TRUSTED_ORIGINS = [ "https://cdc.iitdh.ac.in", "http://cdc.iitdh.ac.in"]
# EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend' EMAIL_BACKEND = ''
EMAIL_FILE_PATH = './emails' if DEBUG:
# file based email backend for development
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = './test-emails'
else:
# SMTP backend for production
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True EMAIL_USE_TLS = True
EMAIL_PORT = 587 EMAIL_PORT = 587

View File

@ -44,7 +44,7 @@
<td style="padding:0 0 36px 0;color:#153643;"> <td style="padding:0 0 36px 0;color:#153643;">
<p style="margin:0 0 12px 0;font-size:16px;line-height:24px;font-family: 'Roboto', sans-serif;"> <p style="margin:0 0 12px 0;font-size:16px;line-height:24px;font-family: 'Roboto', sans-serif;">
We have received your Job Notification for {{ designation }}. Kindly verify your email by clicking <a We have received your {{opening_type}} Notification for {{ designation }}. Kindly verify your email by clicking <a
href="{{ one_time_link }}">here</a>. href="{{ one_time_link }}">here</a>.
</p> </p>
</td> </td>