Exemplo n.º 1
0
def find_my_team(request):
    # type: (HttpRequest) -> HttpResponse
    url = reverse('zerver.views.registration.find_my_team')

    emails = []  # type: List[Text]
    if request.method == 'POST':
        form = FindMyTeamForm(request.POST)
        if form.is_valid():
            emails = form.cleaned_data['emails']
            for user_profile in UserProfile.objects.filter(email__in=emails):
                send_email_to_user('zerver/emails/find_team', user_profile,
                                   context={'user_profile': user_profile})

            # Note: Show all the emails in the result otherwise this
            # feature can be used to ascertain which email addresses
            # are associated with Zulip.
            data = urllib.parse.urlencode({'emails': ','.join(emails)})
            return redirect(url + "?" + data)
    else:
        form = FindMyTeamForm()
        result = request.GET.get('emails')
        if result:
            for email in result.split(','):
                try:
                    validators.validate_email(email)
                    emails.append(email)
                except ValidationError:
                    pass

    return render(request,
                  'zerver/find_my_team.html',
                  context={'form': form, 'current_url': lambda: url,
                           'emails': emails},)
Exemplo n.º 2
0
def find_my_team(request):
    # type: (HttpRequest) -> HttpResponse
    url = reverse('zerver.views.registration.find_my_team')

    emails = []  # type: List[Text]
    if request.method == 'POST':
        form = FindMyTeamForm(request.POST)
        if form.is_valid():
            emails = form.cleaned_data['emails']
            for user_profile in UserProfile.objects.filter(email__in=emails):
                send_email_to_user('zerver/emails/find_team', user_profile,
                                   context={'user_profile': user_profile})

            # Note: Show all the emails in the result otherwise this
            # feature can be used to ascertain which email addresses
            # are associated with Zulip.
            data = urllib.parse.urlencode({'emails': ','.join(emails)})
            return redirect(url + "?" + data)
    else:
        form = FindMyTeamForm()
        result = request.GET.get('emails')
        if result:
            for email in result.split(','):
                try:
                    validators.validate_email(email)
                    emails.append(email)
                except ValidationError:
                    pass

    return render(request,
                  'zerver/find_my_team.html',
                  context={'form': form, 'current_url': lambda: url,
                           'emails': emails},)
Exemplo n.º 3
0
def email_on_new_login(sender, user, request, **kwargs):
    # type: (Any, UserProfile, Any, **Any) -> None

    # We import here to minimize the dependencies of this module,
    # since it runs as part of `manage.py` initialization
    from zerver.context_processors import common_context

    if not settings.SEND_LOGIN_EMAILS:
        return

    if request:
        # Login emails are for returning users, not new registrations.
        # Determine if login request was from new registration.
        path = request.META.get('PATH_INFO', None)

        if path:
            if path == "/accounts/register/":
                return

        login_time = timezone_now().strftime('%A, %B %d, %Y at %I:%M%p ') + \
            timezone_get_current_timezone_name()
        user_agent = request.META.get('HTTP_USER_AGENT', "").lower()
        device_browser = get_device_browser(user_agent)
        device_os = get_device_os(user_agent)
        device_ip = request.META.get('REMOTE_ADDR') or "Uknown IP address"
        device_info = {
            "device_browser": device_browser,
            "device_os": device_os,
            "device_ip": device_ip,
            "login_time": login_time
        }

        context = common_context(user)
        context['device_info'] = device_info
        context['user'] = user

        send_email_to_user('zerver/emails/notify_new_login',
                           user,
                           from_name='Zulip Account Security',
                           from_address=FromAddress.NOREPLY,
                           context=context)
Exemplo n.º 4
0
def email_on_new_login(sender, user, request, **kwargs):
    # type: (Any, UserProfile, Any, **Any) -> None

    # We import here to minimize the dependencies of this module,
    # since it runs as part of `manage.py` initialization
    from zerver.context_processors import common_context

    if not settings.SEND_LOGIN_EMAILS:
        return

    if request:
        # Login emails are for returning users, not new registrations.
        # Determine if login request was from new registration.
        path = request.META.get('PATH_INFO', None)

        if path:
            if path == "/accounts/register/":
                return

        login_time = timezone_now().strftime('%A, %B %d, %Y at %I:%M%p ') + \
            timezone_get_current_timezone_name()
        user_agent = request.META.get('HTTP_USER_AGENT', "").lower()
        device_browser = get_device_browser(user_agent)
        device_os = get_device_os(user_agent)
        device_ip = request.META.get('REMOTE_ADDR') or "Uknown IP address"
        device_info = {"device_browser": device_browser,
                       "device_os": device_os,
                       "device_ip": device_ip,
                       "login_time": login_time
                       }

        context = common_context(user)
        context['device_info'] = device_info
        context['user'] = user

        send_email_to_user('zerver/emails/notify_new_login', user,
                           from_name='Zulip Account Security', from_address=FromAddress.NOREPLY,
                           context=context)