Пример #1
0
def send_welcome_mail(user=None):
    subject = _("Welcome to %(site_name)s") % {'site_name': tenant_name()}
    if user and user.primary_language:
        with TenantLanguage(user.primary_language):
            subject = _("Welcome to %(site_name)s") % {
                'site_name': tenant_name()
            }

    data = {
        'email': user.email,
        'site': tenant_url(),
        'site_name': tenant_name(),
        'user': user,
        'first_name': user.first_name,
        'contact_email': properties.CONTACT_EMAIL,
        'token': default_token_generator.make_token(user),
        'uid': int_to_base36(user.pk),
        'LANGUAGE_CODE': user.primary_language,
    }

    # If there is no password and no remote_id (SSO) then use the
    # welcome + password template, and then set a random password
    if not user.password and not user.remote_id:
        send_mail(template_name='bb_accounts/activation_email_no_password',
                  subject=subject,
                  to=user,
                  **data)
    else:
        send_mail(template_name='bb_accounts/activation_email',
                  subject=subject,
                  to=user,
                  **data)
Пример #2
0
def send_welcome_mail(user=None):

    from bluebottle.members.models import MemberPlatformSettings
    settings = MemberPlatformSettings.objects.get()

    context = {
        'email': user.email,
        'site': tenant_url(),
        'site_name': tenant_name(),
        'user': user,
        'first_name': user.first_name,
        'contact_email': properties.CONTACT_EMAIL,
        'closed_site': settings.closed,
        'LANGUAGE_CODE': user.primary_language,
    }

    # If there is no password and no remote_id (SSO) then use the
    # welcome + password template, and then set a random password
    if not user.password and not user.remote_id:
        context.update({
            'token': default_token_generator.make_token(user),
            'uid': int_to_base36(user.pk),
        })

    msg = AccountActivationMessage(user, context=context)
    msg.compose_and_send()

    user.welcome_email_is_sent = True
    user.save()
Пример #3
0
def send_welcome_mail(user=None):
    cur_language = translation.get_language()

    if user and user.primary_language:
        translation.activate(user.primary_language)
    else:
        translation.activate(properties.LANGUAGE_CODE)

    c = {
        'email': user.email,
        'site': tenant_url(),
        'site_name': tenant_name(),
        'user': user,
        'first_name': user.first_name,
        'LANGUAGE_CODE': user.primary_language,
    }

    subject_template_name = 'bb_accounts/activation_email_subject.txt'
    subject = loader.render_to_string(subject_template_name, c)

    # Email subject *must not* contain newlines
    subject = ''.join(subject.splitlines())

    send_mail(
        template_name='bb_accounts/activation_email',
        subject=subject,
        to=user,
        **c
    )

    translation.activate(cur_language)
Пример #4
0
    def save(self, password_reset_form, domain_override=None,
             subject_template_name='bb_accounts/password_reset_subject.txt',
             email_template_name='bb_accounts/password_reset_email',
             use_https=True,
             token_generator=default_token_generator, from_email=None,
             request=None):
        """
        Generates a one-use only link for resetting password and sends to the
        user. This has been ported from the
        Django PasswordResetForm to allow HTML emails instead of plaint text
        emails.
        """
        # TODO: Create a patch to Django to use user.email_user instead of
        # send_email.
        user_model = get_user_model()
        email = password_reset_form.cleaned_data["email"]

        active_users = user_model._default_manager.filter(
            email__iexact=email, is_active=True)
        for user in active_users:
            if not domain_override:
                site_name = tenant_name()
                domain = tenant_url()
            else:
                site_name = domain = domain_override

            c = {
                'email': user.email,
                'site': domain,
                'site_name': site_name,
                'uid': int_to_base36(user.pk),
                'user': user,
                'token': token_generator.make_token(user),
                'LANGUAGE_CODE': self.request.LANGUAGE_CODE[:2]
            }

            cur_language = translation.get_language()

            if user.primary_language:
                translation.activate(user.primary_language)
            else:
                translation.activate(properties.LANGUAGE_CODE)

            subject = loader.render_to_string(subject_template_name, c)
            # Email subject *must not* contain newlines
            subject = ''.join(subject.splitlines())

            translation.activate(cur_language)

            send_mail(
                template_name=email_template_name,
                to=user,
                subject=subject,
                **c
            )
Пример #5
0
def send_welcome_mail(user=None):
    subject = _("Welcome to %(site_name)s") % {'site_name': tenant_name()}
    if user and user.primary_language:
        with TenantLanguage(user.primary_language):
            subject = _("Welcome to %(site_name)s") % {'site_name': tenant_name()}

    c = {
        'email': user.email,
        'site': tenant_url(),
        'site_name': tenant_name(),
        'user': user,
        'first_name': user.first_name,
        'LANGUAGE_CODE': user.primary_language,
    }

    send_mail(
        template_name='bb_accounts/activation_email',
        subject=subject,
        to=user,
        **c
    )
Пример #6
0
    def get_context(self, recipient):
        from bluebottle.clients.utils import tenant_url, tenant_name
        context = {
            'site': tenant_url(),
            'site_name': tenant_name(),
            'language': recipient.primary_language,
            'contact_email': properties.CONTACT_EMAIL,
            'first_name': recipient.first_name
        }
        for key, item in list(self.context.items()):
            context[key] = attrgetter(item)(self.obj)

        if 'context' in self.options:
            context.update(self.options['context'])

        return context
Пример #7
0
    def get_generic_context(self):
        from bluebottle.clients.utils import tenant_url, tenant_name
        language = get_current_language()
        context = {
            'site': tenant_url(),
            'site_name': tenant_name(),
            'language': language,
            'contact_email': properties.CONTACT_EMAIL,
            'first_name': _('Name')
        }
        for key, item in list(self.context.items()):
            context[key] = attrgetter(item)(self.obj)

        if 'context' in self.options:
            context.update(self.options['context'])
        return context