def magic_link_resubmission_confirmation_email(email, application_reference, first_name, updated_tasks): """ Method to send a magic link email, using notify.py, to allow applicant to log in """ personalisation = { 'ref': application_reference, 'firstName': first_name, } all_tasks = [ 'Your sign in details', 'Type of childcare', 'Your personal details', 'First aid training', 'Criminal record (DBS) check', 'Early years training', 'Health declaration booklet', 'People in your home', 'References' ] for task in all_tasks: personalisation[task] = task in updated_tasks # Remove parentheses from 'Criminal record (DBS) check' - Notify cannot format such variables. personalisation['Criminal record DBS check'] = personalisation.pop( 'Criminal record (DBS) check') template_id = '6431f727-c49e-4f17-964e-b5595a83e958' send_email(email, personalisation, template_id)
def payment_email(email, name, application_reference, application_id): """ A function to send an email through the notify gateway with a payment template, currently used to confirm a Worldpay card order has been successful :param email: The address to send the email to, sent as a string :param name: The name to be placed on the email template to be sent to the user :param application_reference :param application_id :return: Returns the response object obtained from the PayPal gateway method, as defined in swagger """ template_id = '2cd5f1c5-4900-4922-a627-a0d1f674136b' try: conviction = CriminalRecordCheck.objects.get( application_id=application_id).cautions_convictions except CriminalRecordCheck.DoesNotExist: conviction = False if conviction is True: template_id = 'c7500574-df3c-4df1-b7f7-8755f6b61c7f' response = send_email(email, { "firstName": name, "ref": application_reference }, template_id) return response
def _childminder_expiry_warnings(self, error_context): send_reminder_cm = generate_expiring_applications_list_cm_applications( ) for cm_application in send_reminder_cm: with error_context.sub(): if cm_application.application_expiry_email_sent: log.debug('Already sent') continue log.info( str(datetime.now()) + ' - Sending reminder email: ' + str(cm_application.pk)) log.info(cm_application.application_id) template_id = 'b52414b8-afb4-4b6b-8b10-d87efa2714f4' user = UserDetails.objects.get(application_id=cm_application) try: name_model = ApplicantName.objects.get( application_id=cm_application) except ApplicantName.DoesNotExist: # applicant might not have got as far as completing personal details name_model = None if name_model and name_model.first_name: applicant_first_name = name_model.first_name else: applicant_first_name = 'applicant' base_url = settings.CHILDMINDER_EMAIL_VALIDATION_URL user.magic_link_email = ''.join([ random.choice(string.ascii_letters + string.digits) for n in range(12) ]) user.magic_link_email = user.magic_link_email.upper() # "expiry date" is actually creation time as epoch seconds user.email_expiry_date = int(time.time()) log.info((user, base_url, user.magic_link_email)) personalisation = { "link": base_url + '/validate/' + user.magic_link_email, "first_name": applicant_first_name } log.info(personalisation['link']) r = send_email(user.email, personalisation, template_id, service_name='Childminder') log.info(r) if r.status_code not in (200, 201): raise ConnectionError(r.status_code) cm_application.application_expiry_email_sent = True cm_application.save() user.save()
def magic_link_non_existent_email(email, link_id): """ Method to send a magic link email, using notify.py, to allow applicant to log in :param email: string containing the e-mail address to send the e-mail to :param link_id: string containing the magic link ID related to an application :return: :class:`Response <Response>` object containing http request response :rtype: requests.Response """ # If executing login function in test mode set env variable for later retrieval by test code if settings.EXECUTING_AS_TEST == 'True': os.environ['EMAIL_VALIDATION_URL'] = link_id else: print(link_id) personalisation = {"link": link_id} template_id = 'd2d7958a-269a-45c3-b66d-da8ec1911380' return send_email(email, personalisation, template_id)
def magic_link_update_email(email, first_name, link_id): """ Method to send a magic link email, using notify.py, to update an applicant's email :param email: string containing the e-mail address to send the e-mail to :param link_id: string containing the magic link ID related to an application :return: :class:`Response <Response>` object containing http request response :rtype: requests.Response """ # If executing login function in test mode set env variable for later retrieval by test code if settings.EXECUTING_AS_TEST == 'True': os.environ['EMAIL_VALIDATION_URL'] = link_id else: print(link_id) personalisation = {"link": link_id, "first name": first_name} template_id = 'c778438a-c3fb-47e0-ad8a-936021abb1c8' return send_email(email, personalisation, template_id)
def _nanny_expiry_warnings(self, error_context): send_reminder_nanny = generate_expiring_applications_list_nanny_applications( ) for nanny_application in send_reminder_nanny: with error_context.sub(): if nanny_application['application_expiry_email_sent']: log.debug('Already sent') continue log.info( str(datetime.now()) + ' - Sending reminder email: ' + nanny_application['application_id']) log.info(nanny_application['application_id']) template_id = '3751bbf7-fbe7-4289-a3ed-6afbd2bab8bf' response = IdentityGatewayActions().read( 'user', params={ 'application_id': nanny_application['application_id'] }) if response.status_code != 200: raise ConnectionError(response.status_code) user = response.record response = NannyGatewayActions().read( 'applicant-personal-details', params={ 'application_id': nanny_application['application_id'] }) if response.status_code == 200: personal = response.record elif response.status_code == 404: personal = None else: raise ConnectionError(response.status_code) if personal and personal['first_name']: applicant_first_name = personal['first_name'] else: applicant_first_name = 'applicant' base_url = settings.NANNY_EMAIL_VALIDATION_URL user['magic_link_email'] = ''.join([ random.choice(string.ascii_letters + string.digits) for n in range(12) ]) user['magic_link_email'] = user['magic_link_email'].upper() # "expiry date" is actually creation time as epoch seconds user['email_expiry_date'] = int(time.time()) log.info((user, base_url, user['magic_link_email'])) personalisation = { "link": base_url + '/validate/' + user['magic_link_email'], "first_name": applicant_first_name } log.info(personalisation['link']) r = send_email(user['email'], personalisation, template_id, service_name='Nannies') if r.status_code not in (200, 201): raise ConnectionError(r.status_code) log.info(r) nanny_application['application_expiry_email_sent'] = True response = NannyGatewayActions().put('application', nanny_application) if response.status_code != 200: raise ConnectionError(response.status_code) response = IdentityGatewayActions().put('user', user) if response.status_code != 200: raise ConnectionError(response.status_code)