Beispiel #1
0
    return False


def sendmsg(text: str, is_safe=False) -> bool:
    '''
    Sends a message to Slack with the given text, formatted in the
    style described at https://api.slack.com/incoming-webhooks. It
    will automatically be escaped unless is_safe is True.

    Returns True if the message was successfully sent, False otherwise.
    '''

    if not is_safe:
        text = escape(text)
    return send_payload({'text': text})


def hyperlink(href: str, text: str) -> str:
    '''
    Returns a pre-escaped hyperlink for Slack messages, e.g.:

        >>> hyperlink(text="hi", href="http://boop.com")
        '<http://boop.com|hi>'
    '''

    return f'<{escape(href)}|{escape(text)}>'


sendmsg_async = fire_and_forget_task(sendmsg)
Beispiel #2
0
from typing import List
from django.http import HttpRequest
from django.contrib.sessions.middleware import SessionMiddleware

from users.models import JustfixUser
from project.util.site_util import get_site_name
from project.util.celery_util import fire_and_forget_task
from project.util.email_attachment import email_file_response_as_attachment
from .views import render_finished_loc_pdf_for_user


def email_letter(user_id: int, recipients: List[str]) -> None:
    user = JustfixUser.objects.get(pk=user_id)
    request = HttpRequest()
    SessionMiddleware(lambda request: None).process_request(request)
    email_file_response_as_attachment(
        subject=f"{user.full_legal_name}'s letter of complaint",
        body=(
            f"{get_site_name()} here! Attached is a copy of {user.full_legal_name}'s letter of "
            f"complaint, which {user.first_name} requested we send you."
        ),
        recipients=recipients,
        attachment=render_finished_loc_pdf_for_user(request, user),
    )


email_letter_async = fire_and_forget_task(email_letter)
Beispiel #3
0
            logger.info(f"Sent Twilio message with sid {msg.sid}.")
            return SendSmsResult(sid=msg.sid)
        except Exception as e:
            result = _handle_twilio_err(e, phone_number, fail_silently,
                                        ignore_invalid_phone_number)
            if result is not None:
                return result
            raise
    else:
        logger.info(f"SMS sending is disabled. If it were enabled, "
                    f"{phone_number} would receive a text message "
                    f"with the body {repr(body)}.")
        return SendSmsResult(err_code=TWILIO_INTEGRATION_DISABLED_ERR)


send_sms_async = fire_and_forget_task(send_sms)


def chain_sms_async(phone_number: str,
                    bodies: List[str],
                    seconds_between_messages: int = 10) -> None:
    """
    Sends multiple SMS messages, waiting the given number
    of seconds between them, to ensure that the recipient
    doesn't receive them out of order.
    """

    import celery

    task = get_task_for_function(send_sms)
    tasks: List[Any] = []
Beispiel #4
0
from typing import List

from users.models import JustfixUser
from project.util.site_util import get_site_name
from project.util.celery_util import fire_and_forget_task
from project.util.email_attachment import email_file_response_as_attachment
from .views import get_latest_pdf_for_user
from .models import HP_ACTION_CHOICES


def email_packet(user_id: int, recipients: List[str]) -> None:
    user = JustfixUser.objects.get(pk=user_id)
    email_file_response_as_attachment(
        subject=f"{user.full_legal_name}'s HP Action packet",
        body=
        (f"{get_site_name()} here! Attached is a copy of {user.full_legal_name}'s HP Action "
         f"packet, which {user.first_name} requested we send you."),
        recipients=recipients,
        attachment=get_latest_pdf_for_user(user, HP_ACTION_CHOICES.NORMAL),
    )


email_packet_async = fire_and_forget_task(email_packet)
Beispiel #5
0
    code = signing.dumps(SigningPayload.from_user(user).serialize(), salt=VERIFICATION_SALT)
    qs = urllib.parse.urlencode({"code": code})
    url = f"{absolute_reverse('verify_email')}?{qs}"
    subject = f"Welcome to JustFix.nyc! Please verify your email"
    body = render_to_string(
        "users/verification_email_body.txt",
        {
            "user": user,
            "url": url,
        },
    )
    from_email = settings.DEFAULT_FROM_EMAIL
    send_mail(subject, body, from_email, [user.email])


send_verification_email_async = fire_and_forget_task(send_verification_email)


def verify_code(code: str) -> Tuple[str, Optional[JustfixUser]]:
    """
    Attempt to verify the given verification code and mark
    the user's account as having a verified email address.

    Returns a tuple containing the response code string and
    the relevant user object, if applicable.

    Note that if the user object is included, the verification
    can be considered a success.
    """

    try: