def _send_invite(self, request, user, ticket): callback = request.build_absolute_uri(reverse('access_accept', args=(ticket.uid,))) message = _("This email is to help you recover your password. If you're not trying to recover your password, please ignore it. In order to continue, click on the following link:") # A text/html alternative is required by SendGrid. We can't send the email # with some arguments that are already defined by the template. See below, # near attach_alternatives mail = EmailMultiAlternatives( subject=_('Password recovery'), body='%s: %s' % (message, callback,), from_email=require_setting('DEFAULT_FROM_EMAIL'), to=[user.email], headers={ 'Reply-To': require_setting('DEFAULT_FROM_EMAIL') } ) mail.template_id = require_setting('COVIODFF_RECOVERY_EMAIL_TEMPLATE') mail.substitutions = { '-callback-': callback } # A text/html alternative is required to load the HTML template created on SendGrid, # but it doesn't do anything besides that. This content is not used. mail.attach_alternative("<p>%s: <a href='%s'>%s</a></p>" % (message, callback, callback,), "text/html") mail.send()
def _send_invite(self, request, user, ticket): callback = request.build_absolute_uri(reverse('access_accept', args=(ticket.uid,))) message = _("This email is to invite you to administrate the COVID|APP website. To accept the invitation, click the following link:") # A text/html alternative is required by SendGrid. We can't send the email # with some arguments that are already defined by the template. See below, # near attach_alternatives mail = EmailMultiAlternatives( subject=_('Welcome'), body='%s: %s' % (message, callback,), from_email=require_setting('DEFAULT_FROM_EMAIL'), to=[user.email], headers={ 'Reply-To': require_setting('DEFAULT_FROM_EMAIL') } ) mail.template_id = require_setting('COVIDOFF_INVITATION_EMAIL_TEMPLATE') mail.substitutions = { '-callback-': callback } # A text/html alternative is required to load the HTML template created on SendGrid, # but it doesn't do anything besides that. This content is not used. mail.attach_alternative("<p>%s: <a href='%s'>%s</a></p>" % (message, callback, callback,), "text/html") mail.send()
def post(self, request): form = SubscriptionForm(request.body) if not form.is_valid(): return JsonResponse(dict(form.errors.items()), status=422) endpoint = form.cleaned_data['endpoint'] topic = self.topic client = boto3.client('sns', region_name='sa-east-1') try: subscription = client.subscribe(Protocol='application', Endpoint=endpoint, TopicArn=self.topic) Device.objects.update_or_create( uid=form.cleaned_data['device'], defaults={ 'arn': endpoint, 'os': request.user_agent.os.family, 'os_version': request.user_agent.os.version_string }) except Exception as ex: return JsonResponse({'errors': [str(ex)]}, status=422) return JsonResponse({ 'pk': require_setting('COVIDOFF_VERIFY_KEY'), 'messages': [_build_message(message) for message in Message.objects.all()] })
def test_new_user(self): response = self.client.post( reverse('users'), {'email': require_setting('DEFAULT_FROM_EMAIL')}) self.assertEqual(response.status_code, 200)
def topic(self): return require_setting('COVIDOFF_SNS_TOPIC_ARN')
def _signing_key(): return nacl.signing.SigningKey(require_setting('COVIDOFF_SIGNING_KEY'), nacl.encoding.HexEncoder)