Ejemplo n.º 1
0
    def test_get_protocol(self):
        """ Test if the correct protocol is returned """
        self.failUnlessEqual(get_protocol(), 'http')

        userena_settings.USERENA_USE_HTTPS = True
        self.failUnlessEqual(get_protocol(), 'https')
        userena_settings.USERENA_USE_HTTPS = False
Ejemplo n.º 2
0
    def test_get_protocol(self):
        """ Test if the correct protocol is returned """
        self.failUnlessEqual(get_protocol(), 'http')

        userena_settings.USERENA_USE_HTTPS = True
        self.failUnlessEqual(get_protocol(), 'https')
        userena_settings.USERENA_USE_HTTPS = False
Ejemplo n.º 3
0
    def send_activation_email(self):
        """
        Sends a activation email to the user.

        This email is send when the user wants to activate their newly created
        user.

        """
        context= {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'protocol': get_protocol(),
                  'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
                  'activation_key': self.activation_key,
                  'site': Site.objects.get_current()}

        subject = render_to_string('userena/emails/activation_email_subject.txt',
                                   context)
        subject = ''.join(subject.splitlines())

        message = render_to_string('userena/emails/activation_email_message.txt',
                                   context)
        try:
            send_mail(subject,
                      message,
                      settings.DEFAULT_FROM_EMAIL,
                      [self.user.email,])
        except:
            pass
Ejemplo n.º 4
0
    def send_confirmation_email(self):
        """
        Sends an email to confirm the new email address.

        This method sends out two emails. One to the new email address that
        contains the ``email_confirmation_key`` which is used to verify this
        this email address with :func:`UserenaUser.objects.confirm_email`.

        The other email is to the old email address to let the user know that
        a request is made to change this email address.

        """
        context = {
            "user": self.user,
            "without_usernames": userena_settings.USERENA_WITHOUT_USERNAMES,
            "new_email": self.email_unconfirmed,
            "protocol": get_protocol(),
            "confirmation_key": self.email_confirmation_key,
            "site": shortcuts.get_current_site(request=None),
        }

        mailer = UserenaConfirmationMail(context=context)
        mailer.generate_mail("confirmation", "_old")

        if self.user.email:
            mailer.send_mail(self.user.email)

        mailer.generate_mail("confirmation", "_new")
        mailer.send_mail(self.email_unconfirmed)
Ejemplo n.º 5
0
    def send_confirmation_email(self):
        # TODO !!!!!!!!!
        context = {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'new_email': self.email_unconfirmed,
                  'protocol': get_protocol(),
                  'confirmation_key': self.email_confirmation_key,
                  'site': Site.objects.get_current()}
        # Email to the old address, if present
        subject_old = render_to_string('userena/emails/confirmation_email_subject_old.txt',
                                       context)
        subject_old = ''.join(subject_old.splitlines())

        message_old = render_to_string('userena/emails/confirmation_email_message_old.txt',
                                       context)
        if self.user.email:
            send_mail(subject_old,
                      message_old,
                      settings.DEFAULT_FROM_EMAIL,
                    [self.user.email])
        # Email to the new address
        subject_new = render_to_string('userena/emails/confirmation_email_subject_new.txt',
                                       context)
        subject_new = ''.join(subject_new.splitlines())

        message_new = render_to_string('userena/emails/confirmation_email_message_new.txt',
                                       context)

        send_mail(subject_new,
                  message_new,
                  settings.DEFAULT_FROM_EMAIL,
                  [self.email_unconfirmed, ])
Ejemplo n.º 6
0
def send_message_notification(sender, instance, **kwargs):
    """
    Send email when user receives a new message. This email contains the full text
    and a link to read it online.

    We trigger this when a MessageRecipient is saved and not when a Message is
    saved because umessages first saves a message and then adds its recipients,
    so when a Message is saved, it doesn't yet have a list of recipients.
    """

    if not instance.user.email:
        # Email can be missing for users registered with Twitter
        # or LinkedIn
        return

    params = {
        'sender': instance.message.sender.username,
        'body': instance.message.body,
        }
    message_url_path = reverse('userena_umessages_detail',
                               kwargs={'username': params['sender']})
    params['message_url'] = "%s://%s%s" % (
            get_protocol(),
            Site.objects.get_current(), 
            message_url_path)

    subject = _(u'Message from %(sender)s') % params
    message = render_to_string('umessages/message_notification.txt', params)
    recipient = instance.user.email

    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [recipient])
Ejemplo n.º 7
0
    def send_activation_email(self):
        """
        Sends a activation email to the user.

        This email is send when the user wants to activate their newly created
        user.

        """
        context = {
            'user': self.user,
            'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
            'protocol': get_protocol(),
            'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
            'activation_key': self.activation_key,
            'site': Site.objects.get_current()
        }

        subject = render_to_string(
            'userena/emails/activation_email_subject.txt', context)
        subject = ''.join(subject.splitlines())

        message = render_to_string(
            'userena/emails/activation_email_message.txt', context)
        send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [
            self.user.email,
        ])
Ejemplo n.º 8
0
    def send_invite_email(self, promoter):
        """
        Sends a invitation email to the user.

        This email is sent when a user invites another user to to join.

        """
        context = {'user': self.user,
                   'promoter': promoter,
                   'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                   'protocol': get_protocol(),
                   'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
                   'activation_key': self.activation_key,
                   'site': Site.objects.get_current()}

        subject = render_to_string('userena/emails/invitation_email_subject.txt',
                                   context)
        subject = ''.join(subject.splitlines())

        message = render_to_string('userena/emails/invitation_email_message.txt',
                                   context)
        send_mail(subject,
                  message,
                  settings.DEFAULT_FROM_EMAIL,
                  [self.user.email,])
Ejemplo n.º 9
0
    def send_confirmation_email(self):
        """
        Sends an email to confirm the new email address.

        This method sends out two emails. One to the new email address that
        contains the ``email_confirmation_key`` which is used to verify this
        this email address with :func:`UserenaUser.objects.confirm_email`.

        The other email is to the old email address to let the user know that
        a request is made to change this email address.

        """
        context = {
            "user": self.user,
            "new_email": self.email_unconfirmed,
            "protocol": get_protocol(),
            "confirmation_key": self.email_confirmation_key,
            "site": Site.objects.get_current(),
        }

        # Email to the old address
        subject_old = render_to_string("userena/emails/confirmation_email_subject_old.txt", context)
        subject_old = "".join(subject_old.splitlines())

        message_old = render_to_string("userena/emails/confirmation_email_message_old.txt", context)

        send_mail(subject_old, message_old, settings.DEFAULT_FROM_EMAIL, [self.user.email])

        # Email to the new address
        subject_new = render_to_string("userena/emails/confirmation_email_subject_new.txt", context)
        subject_new = "".join(subject_new.splitlines())

        message_new = render_to_string("userena/emails/confirmation_email_message_new.txt", context)

        send_mail(subject_new, message_new, settings.DEFAULT_FROM_EMAIL, [self.email_unconfirmed])
Ejemplo n.º 10
0
    def send_confirmation_email(self):
        # TODO !!!!!!!!!
        context = {
            'user': self.user,
            'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
            'new_email': self.email_unconfirmed,
            'protocol': get_protocol(),
            'confirmation_key': self.email_confirmation_key,
            'site': Site.objects.get_current()
        }
        # Email to the old address, if present
        subject_old = render_to_string(
            'userena/emails/confirmation_email_subject_old.txt', context)
        subject_old = ''.join(subject_old.splitlines())

        message_old = render_to_string(
            'userena/emails/confirmation_email_message_old.txt', context)
        if self.user.email:
            send_mail(subject_old, message_old, settings.DEFAULT_FROM_EMAIL,
                      [self.user.email])
        # Email to the new address
        subject_new = render_to_string(
            'userena/emails/confirmation_email_subject_new.txt', context)
        subject_new = ''.join(subject_new.splitlines())

        message_new = render_to_string(
            'userena/emails/confirmation_email_message_new.txt', context)

        send_mail(subject_new, message_new, settings.DEFAULT_FROM_EMAIL, [
            self.email_unconfirmed,
        ])
Ejemplo n.º 11
0
    def send_confirmation_email(self):
        """
        Sends an email to confirm the new email address.

        This method sends out two emails. One to the new email address that
        contains the ``email_confirmation_key`` which is used to verify this
        this email address with :func:`UserenaUser.objects.confirm_email`.

        The other email is to the old email address to let the user know that
        a request is made to change this email address.

        """
        context = {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'new_email': self.email_unconfirmed,
                  'protocol': get_protocol(),
                  'confirmation_key': self.email_confirmation_key,
                  'site': Site.objects.get_current()}

        mailer = UserenaConfirmationMail(context=context)
        mailer.generate_mail("confirmation", "_old")

        if self.user.email:
            mailer.send_mail(self.user.email)

        mailer.generate_mail("confirmation", "_new")
        mailer.send_mail(self.email_unconfirmed)
Ejemplo n.º 12
0
    def send_activation_email(self, first_name = '', last_name = ''):
        """
        Sends a activation email to the user.

        This email is send when the user wants to activate their newly created
        user.

        """
        context = {'user': self.user,
                   'first_name': first_name,
                   'last_name': last_name,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'protocol': get_protocol(),
                  'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
                  'activation_key': self.activation_key,
                  'site': Site.objects.get_current()}

        subject = render_to_string('userena/emails/activation_email_subject.txt',
                                   context)
        subject = ''.join(subject.splitlines())

        text_content = render_to_string('userena/emails/activation_email_message.txt',
                                   context)
        html_content = render_to_string('userena/emails/activation_email_message.html',
                                   context)
        email = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [self.user.email, ])
        email.attach_alternative(html_content, "text/html")
        email.send()
Ejemplo n.º 13
0
    def versende_activation(self):
        """ Autogeneriere pw und versende activation mail incl. pw """
        # activation Mail mit pw versenden
        from userena.mail import UserenaConfirmationMail
        import userena.settings as userena_settings
        from django.contrib.sites.models import Site
        from userena.utils import get_protocol

        signup = self.userena_signup
        password = self.erzeuge_pw()

        context = {
            'user': signup.user,
            'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
            'protocol': get_protocol(),
            'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
            'activation_key': signup.activation_key,
            'site': Site.objects.get_current(),
            'passwort': password
        }

        mailer = UserenaConfirmationMail(context=context)
        mailer.generate_mail("activation")
        mailer.send_mail(signup.user.email)

        self.set_password(password)
        self.save()
Ejemplo n.º 14
0
    def send_approval_email(self):
        """
        Sends an approval email to the user.

        This email is sent when USERENA_MODERATE_REGISTRATION, after an admin
        has approved the registration.

        """
        context = {
            'user': self.user,
            'protocol': get_protocol(),
            'site': Site.objects.get_current()
        }

        subject = render_to_string('userena/emails/approval_email_subject.txt',
                                   context)
        subject = ''.join(subject.splitlines())

        message = render_to_string('userena/emails/approval_email_message.txt',
                                   context)

        if userena_settings.USERENA_HTML_EMAIL:
            message_html = render_to_string(
                'userena/emails/approval_email_message.html', context)
        else:
            message_html = None

        send_mail(subject, message, message_html, settings.DEFAULT_FROM_EMAIL,
                  [
                      self.user.email,
                  ])
Ejemplo n.º 15
0
    def send_approval_email(self):
        """
        Sends an approval email to the user.

        This email is sent when USERENA_MODERATE_REGISTRATION, after an admin
        has approved the registration.

        """
        context= {'user': self.user,
                  'protocol': get_protocol(),
                  'site': Site.objects.get_current()}

        subject = render_to_string('userena/emails/approval_email_subject.txt',
                                   context)
        subject = ''.join(subject.splitlines())

        message = render_to_string('userena/emails/approval_email_message.txt',
                                   context)

        if userena_settings.USERENA_HTML_EMAIL:
            message_html = render_to_string('userena/emails/approval_email_message.html',
                                                context)
        else:
            message_html = None


        send_mail(subject,
                  message,
                  message_html,
                  settings.DEFAULT_FROM_EMAIL,
                  [self.user.email,])
Ejemplo n.º 16
0
def send_message_notification(sender, instance, **kwargs):
    """
    Send email when user receives a new message. This email contains the full text
    and a link to read it online.

    We trigger this when a MessageRecipient is saved and not when a Message is
    saved because umessages first saves a message and then adds its recipients,
    so when a Message is saved, it doesn't yet have a list of recipients.
    """

    if not instance.user.email:
        # Email can be missing for users registered with Twitter
        # or LinkedIn
        return

    params = {"sender": instance.message.sender.username, "body": instance.message.body}
    message_url_path = reverse("userena_umessages_detail", kwargs={"username": params["sender"]})
    params["message_url"] = "%s://%s%s" % (get_protocol(), Site.objects.get_current(), message_url_path)

    subject = _(u"New message from %(sender)s on Imagination For People") % params
    message = render_to_string("umessages/message_notification.txt", params)
    recipient = instance.user.email

    # XXX Resets the Content-Transfer-Encoding in email header
    # Avoids bad encoding of UTF-8 body
    # See https://code.djangoproject.com/ticket/3472
    from email import Charset

    Charset.add_charset("utf-8", Charset.SHORTEST, "utf-8", "utf-8")

    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [recipient])
Ejemplo n.º 17
0
    def send_activation_email(self):
        """
        Sends a activation email to the user.

        This email is sent_activation_email when the user wants to activate their newly created
        user.

        """
        context = {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'protocol': get_protocol(),
                  'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
                  'activation_key': self.activation_key,
                  'site': Site.objects.get_current()}

        mailer = UserenaConfirmationMail(context=context)
        mailer.generate_mail("activation")
        mailer.send_mail(self.user.email)

        #Send email to admins with the same message
        emaillist = []
        if settings.USERENA_ADMIN_MODERATION:
          for k, v in settings.ADMINS:
              emaillist.append(v)

          send_mail(settings.SITE_NAME + " - Activation done",
                    message,
                    message_html,
                    settings.DEFAULT_FROM_EMAIL,
                    emaillist)
Ejemplo n.º 18
0
    def send_confirmation_email(self):
        """
        Sends an email to confirm the new email address.

        This method sends out two emails. One to the new email address that
        contains the ``email_confirmation_key`` which is used to verify this
        this email address with :func:`UserenaUser.objects.confirm_email`.

        The other email is to the old email address to let the user know that
        a request is made to change this email address.

        """
        context = {
            'user': self.user,
            'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
            'new_email': self.email_unconfirmed,
            'protocol': get_protocol(),
            'confirmation_key': self.email_confirmation_key,
            'site': Site.objects.get_current()
        }

        mailer = UserenaConfirmationMail(context=context)
        mailer.generate_mail("confirmation", "_old")

        if self.user.email:
            mailer.send_mail(self.user.email)

        mailer.generate_mail("confirmation", "_new")
        mailer.send_mail(self.email_unconfirmed)
Ejemplo n.º 19
0
    def send_activation_email(self):
        """
        Sends a activation email to the user.

        This email is send when the user wants to activate their newly created
        user.

        """
        context= {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'protocol': get_protocol(),
                  'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
                  'activation_key': self.activation_key,
                  'site': Site.objects.get_current()}

        subject = render_to_string('userena/emails/activation_email_subject.txt',
                                   context)
        subject = ''.join(subject.splitlines())

        message = render_to_string('userena/emails/activation_email_message.txt',
                                   context)
        # EMRE Modified this to use smtplib. This method doesn't work.
        send_mail(subject,
                  message,
                  settings.DEFAULT_FROM_EMAIL,
                  [self.user.email,])

        """msg = ("From: %s\r\nTo: %s\r\nSubject:%s\r\n\r\n%s\r\n"
Ejemplo n.º 20
0
    def send_activation_email(
        self, template="userena/emails/activation_email_message.txt", headers=None, attach_list=[]
    ):
        """
        Sends a activation email to the user.

        This email is send when the user wants to activate their newly created
        user.

        """
        context = {
            "user": self.user,
            "without_usernames": userena_settings.USERENA_WITHOUT_USERNAMES,
            "protocol": get_protocol(),
            "activation_days": userena_settings.USERENA_ACTIVATION_DAYS,
            "activation_key": self.activation_key,
            "site": Site.objects.get_current(),
        }

        subject = render_to_string("userena/emails/activation_email_subject.txt", context)
        subject = "".join(subject.splitlines())

        body = render_to_string(template, context)

        message = EmailMessage(subject, body, settings.DEFAULT_FROM_EMAIL, [self.user.email], headers=headers)

        if template.split(".")[-1] == "html":
            message.content_subtype = "html"

        for attachment in attach_list:
            message.attach(attachment)

        message.send()
Ejemplo n.º 21
0
    def send_activation_email(self):
        """
        Sends a activation email to the user.

        This email is send when the user wants to activate their newly created
        user.

        """
        context = {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'protocol': get_protocol(),
                  'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
                  'activation_key': self.activation_key,
                  'site': Site.objects.get_current(),
                  'settings': settings}

        subject = render_to_string(userena_settings.USERENA_ACTIVATION_EMAIL_SUBJECT_TEMPLATE,
                                   context)
        subject = ''.join(subject.splitlines())

        message = render_to_string(userena_settings.USERENA_ACTIVATION_EMAIL_MESSAGE_TEMPLATE,
                                   context)
        send_mail_module = importlib.import_module(userena_settings.USERENA_SEND_EMAIL_MODULE)
        send_mail_module.send_mail(subject,
                  message,
                  settings.DEFAULT_FROM_EMAIL,
                  [self.user.email, ])
Ejemplo n.º 22
0
def send_activation_email_with_password(userena_signup_obj, password):
    """
    Sends a activation email to the user, along with an
    automatically generated password that they need to log in.

    This function only exists because userena/models.py's
    UserenaSignup.send_activation_email() doesn't have a way to
    add custom context.
    """
    context= {'user': userena_signup_obj.user,
              'protocol': get_protocol(),
              'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
              'activation_key': userena_signup_obj.activation_key,
              'site': Site.objects.get_current(),
              'password': password}

    subject = render_to_string('userena/emails/activation_email_subject.txt',
        context)
    subject = ''.join(subject.splitlines())

    message = render_to_string('userena/emails/activation_email_message.txt',
        context)
    send_mail(subject,
        message,
        settings.DEFAULT_FROM_EMAIL,
        [userena_signup_obj.user.email,])
Ejemplo n.º 23
0
    def send_confirmation_email(self):
        """
        Sends an email to confirm the new email address.

        This method sends out two emails. One to the new email address that
        contains the ``email_confirmation_key`` which is used to verify this
        this email address with :func:`UserenaUser.objects.confirm_email`.

        The other email is to the old email address to let the user know that
        a request is made to change this email address.

        """
        context = {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'new_email': self.email_unconfirmed,
                  'protocol': get_protocol(),
                  'confirmation_key': self.email_confirmation_key,
                  'site': Site.objects.get_current()}

        # Email to the old address, if present
        subject_old = render_to_string('userena/emails/confirmation_email_subject_old.txt',
                                       context)
        subject_old = ''.join(subject_old.splitlines())

        message_old_text = render_to_string('userena/emails/confirmation_email_message_old.txt',
                                       context)
        message_old_html = render_to_string('userena/emails/confirmation_email_message_old.html',
                                       context)

        if self.user.email:
            subject, from_email, to = subject_old, settings.DEFAULT_FROM_EMAIL, self.user.email
            text_content = message_old_text
            html_content = message_old_html
            msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
            msg.attach_alternative(html_content, "text/html")
            msg.send()

            # send_mail(subject_old,
            #           message_old,
            #           settings.DEFAULT_FROM_EMAIL,
            #         [self.user.email])

        # Email to the new address
        subject_new = render_to_string('userena/emails/confirmation_email_subject_new.txt',
                                       context)
        subject_new = ''.join(subject_new.splitlines())

        message_new_text = render_to_string('userena/emails/confirmation_email_message_new.txt',
                                       context)
        message_new_html = render_to_string('userena/emails/confirmation_email_message_new.html',
                                       context)

        subject, from_email, to = subject_new, settings.DEFAULT_FROM_EMAIL, self.user.email
        text_content = message_new_text
        html_content = message_new_html
        msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
        msg.attach_alternative(html_content, "text/html")
        msg.send()
Ejemplo n.º 24
0
    def send_pending_activation_email(self, organization=""):
        """
        Sends a email to the user after signup.

        This email is sent_pending_activation_email when the user created a new user.

        """
        context = {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'organization': organization,
                  'protocol': get_protocol(),
                  'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
                  'activation_key': self.activation_key,
                  'site': Site.objects.get_current()}

        subject = render_to_string('userena/emails/pending_activation_email_subject.txt',
                                   context)
        subject = ''.join(subject.splitlines())

        message = render_to_string('userena/emails/pending_activation_email_message.txt',
                                   context)

        if userena_settings.USERENA_HTML_EMAIL:
            message_html = render_to_string('userena/emails/pending_activation_email_message.html',
                                                context)
        else:
            message_html = None

        #Send email to admins with the link activation of new user
        emaillist = []

        if settings.USERENA_ADMIN_MODERATION:

            send_mail(subject,
                  message,
                  message_html,
                  settings.DEFAULT_FROM_EMAIL,
                  [self.user.email, ])

            for k, v in settings.ADMINS:
                emaillist.append(v)
        else:
            emaillist.append(self.user.email)


        if userena_settings.USERENA_HTML_EMAIL:
            message = render_to_string('userena/emails/admin_activation_email_message.html',
                                   context)
        else:
            message = render_to_string('userena/emails/admin_activation_email_message.txt',
                                       context)

        send_mail(settings.SITE_NAME + "- Pending activation",
                  message,
                  settings.DEFAULT_FROM_EMAIL,
                  emaillist)
Ejemplo n.º 25
0
    def send_pending_activation_email(self, organization=""):
        """
        Sends a email to the user after signup.

        This email is sent_pending_activation_email when the user created a new user.

        """
        context = {
            'user': self.user,
            'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
            'organization': organization,
            'protocol': get_protocol(),
            'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
            'activation_key': self.activation_key,
            'site': Site.objects.get_current()
        }

        subject = render_to_string(
            'userena/emails/pending_activation_email_subject.txt', context)
        subject = ''.join(subject.splitlines())

        message = render_to_string(
            'userena/emails/pending_activation_email_message.txt', context)

        if userena_settings.USERENA_HTML_EMAIL:
            message_html = render_to_string(
                'userena/emails/pending_activation_email_message.html',
                context)
        else:
            message_html = None

        #Send email to admins with the link activation of new user
        emaillist = []

        if settings.USERENA_ADMIN_MODERATION:

            send_mail(subject, message, message_html,
                      settings.DEFAULT_FROM_EMAIL, [
                          self.user.email,
                      ])

            for k, v in settings.ADMINS:
                emaillist.append(v)
        else:
            emaillist.append(self.user.email)

        message = render_to_string(
            'userena/emails/admin_activation_email_message.txt', context)
        if userena_settings.USERENA_HTML_EMAIL:
            message_html = render_to_string(
                'userena/emails/admin_activation_email_message.html', context)

        send_mail("EMIF Catalogue - Pending activation", message, message_html,
                  settings.DEFAULT_FROM_EMAIL, emaillist)
Ejemplo n.º 26
0
    def send_activation_email(self):
        """
        Sends a activation email to the user.

        This email is sent_activation_email when the user wants to activate their newly created
        user.

        """
        context = {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'protocol': get_protocol(),
                  'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
                  'activation_key': self.activation_key,
                  'site': Site.objects.get_current()}

        subject = render_to_string('userena/emails/activation_email_subject.txt',
                                   context)
        subject = ''.join(subject.splitlines())


        if userena_settings.USERENA_HTML_EMAIL:
            message_html = render_to_string('userena/emails/activation_email_message.html',
                                            context)
        else:
            message_html = None

        if (not userena_settings.USERENA_HTML_EMAIL or not message_html or
            userena_settings.USERENA_USE_PLAIN_TEMPLATE):
            message = render_to_string('userena/emails/activation_email_message.txt',
                                   context)
        else:
            message = None

        send_mail(subject,
                  message,
                  message_html,
                  settings.DEFAULT_FROM_EMAIL,
                  [self.user.email, ])

        #Send email to admins with the message that the new user is active
        if settings.USERENA_ADMIN_MODERATION:
          for k, v in settings.ADMINS:
              emaillist.append(v)
        else:
          emaillist.append(self.user.email)

        send_mail("EMIF Catalogue - Activation done",
                  message,
                  settings.DEFAULT_FROM_EMAIL,
                  emaillist)
Ejemplo n.º 27
0
    def send_activation_email(self):
        """
        Sends a activation email to the user.

        This email is sent_activation_email when the user wants to activate their newly created
        user.

        """
        context = {
            'user': self.user,
            'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
            'protocol': get_protocol(),
            'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
            'activation_key': self.activation_key,
            'site': Site.objects.get_current()
        }

        subject = render_to_string(
            'userena/emails/activation_email_subject.txt', context)
        subject = ''.join(subject.splitlines())

        if userena_settings.USERENA_HTML_EMAIL:
            message_html = render_to_string(
                'userena/emails/activation_email_message.html', context)
        else:
            message_html = None

        if (not userena_settings.USERENA_HTML_EMAIL or not message_html
                or userena_settings.USERENA_USE_PLAIN_TEMPLATE):
            message = render_to_string(
                'userena/emails/activation_email_message.txt', context)
        else:
            message = None

        send_mail(subject, message, message_html, settings.DEFAULT_FROM_EMAIL,
                  [
                      self.user.email,
                  ])

        #Send email to admins with the message that the new user is active
        if settings.USERENA_ADMIN_MODERATION:
            for k, v in settings.ADMINS:
                emaillist.append(v)
        else:
            emaillist.append(self.user.email)

        send_mail("EMIF Catalogue - Activation done", message,
                  settings.DEFAULT_FROM_EMAIL, emaillist)
Ejemplo n.º 28
0
    def send_activation_email(self):
        """
        Sends a activation email to the user.

        This email is send when the user wants to activate their newly created
        user.
        Override default userena mechanism, to send beautiful HTML email
        """
        email_context = {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'protocol': get_protocol(),
                  'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
                  'activation_key': self.activation_key, 'to': self.user.email}

        msg = UserSignIn(email_context, self.user.email)
        msg.send()
Ejemplo n.º 29
0
    def send_email(self, email=None, site=None, request=None):
        """
        Send invitation email.

        Both ``email`` and ``site`` parameters are optional. If not supplied
        instance's ``email`` field and current site will be used.

        **Templates:**

        :studytribe/invitation/invitation_email_subject.txt:
            Template used to render the email subject.

            **Context:**

            :invitation: ``Invitation`` instance ``send_email`` is called on.
            :site: ``Site`` instance to be used.

        :studytribe/invitation/invitation_email_message.txt:
            Template used to render the email body.

            **Context:**

            :invitation: ``Invitation`` instance ``send_email`` is called on.
            :expiration_days: ``INVITATION_EXPIRE_DAYS`` setting.
            :site: ``Site`` instance to be used.

        **Signals:**

        ``invitation.signals.invitation_sent`` is sent on completion.
        """
        email = email or self.email
        if site is None:
            if Site._meta.installed:
                site = Site.objects.get_current()
            elif request is not None:
                site = RequestSite(request)
        subject = render_to_string('studytribe/invitation/invitation_email_subject.txt',
                                   {'invitation': self, 'site': site})
        # Email subject *must not* contain newlines
        subject = ''.join(subject.splitlines())
        message = render_to_string('studytribe/invitation/invitation_email_message.txt', 
                                  {'invitation': self,
                                  'expiration_days': settings.INVITATION_EXPIRE_DAYS,
                                  'site': site,
                                  'protocol':get_protocol()})
        send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email])
        signals.invitation_sent.send(sender=self)
Ejemplo n.º 30
0
    def send_confirmation_email(self):
        """
        Sends an email to confirm the new email address.

        This method sends out two emails. One to the new email address that
        contains the ``email_confirmation_key`` which is used to verify this
        this email address with :func:`UserenaUser.objects.confirm_email`.

        The other email is to the old email address to let the user know that
        a request is made to change this email address.

        """
        context= {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'new_email': self.email_unconfirmed,
                  'protocol': get_protocol(),
                  'confirmation_key': self.email_confirmation_key,
                  'site': Site.objects.get_current()}


        # Email to the old address
        subject_old = render_to_string('userena/emails/confirmation_email_subject_old.txt',
                                       context)
        subject_old = ''.join(subject_old.splitlines())

        message_old = render_to_string('userena/emails/confirmation_email_message_old.txt',
                                       context)
        try:
            send_mail(subject_old,
                      message_old,
                      settings.DEFAULT_FROM_EMAIL,
                      [self.user.email])
        except:
            pass

        # Email to the new address
        subject_new = render_to_string('userena/emails/confirmation_email_subject_new.txt',
                                       context)
        subject_new = ''.join(subject_new.splitlines())

        message_new = render_to_string('userena/emails/confirmation_email_message_new.txt',
                                       context)

        send_mail(subject_new,
                  message_new,
                  settings.DEFAULT_FROM_EMAIL,
                  [self.email_unconfirmed,])
Ejemplo n.º 31
0
    def send_confirmation_email(self):
        """
        Sends an email to confirm the new email address.

        This method sends out two emails. One to the new email address that
        contains the ``email_confirmation_key`` which is used to verify this
        this email address with :func:`UserenaUser.objects.confirm_email`.

        The other email is to the old email address to let the user know that
        a request is made to change this email address.

        """
        context= {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'new_email': self.email_unconfirmed,
                  'protocol': get_protocol(),
                  'confirmation_key': self.email_confirmation_key,
                  'site': Site.objects.get_current()}


        # Email to the old address
        subject_old = render_to_string('userena/emails/confirmation_email_subject_old.txt',
                                       context)
        subject_old = ''.join(subject_old.splitlines())

        message_old = render_to_string('userena/emails/confirmation_email_message_old.txt',
                                       context)

        send_mail(subject_old,
                  message_old,
                  settings.DEFAULT_FROM_EMAIL,
                  [self.user.email])

        # Email to the new address
        subject_new = render_to_string('userena/emails/confirmation_email_subject_new.txt',
                                       context)
        subject_new = ''.join(subject_new.splitlines())

        message_new = render_to_string('userena/emails/confirmation_email_message_new.txt',
                                       context)

        send_mail(subject_new,
                  message_new,
                  settings.DEFAULT_FROM_EMAIL,
                  [self.email_unconfirmed,])
Ejemplo n.º 32
0
    def send_activation_email(self):
        """
        Sends a activation email to the user.

        This email is send when the user wants to activate their newly created
        user.

        """
        context = {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'protocol': get_protocol(),
                  'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
                  'activation_key': self.activation_key,
                  'site': Site.objects.get_current()}

        mailer = UserenaConfirmationMail(context=context)
        mailer.generate_mail("activation")
        mailer.send_mail(self.user.email)
Ejemplo n.º 33
0
    def send_activation_email(self):
        """
        Sends a activation email to the user.

        This email is send when the user wants to activate their newly created
        user.
        Override default userena mechanism, to send beautiful HTML email
        """
        email_context = {
            'user': self.user,
            'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
            'protocol': get_protocol(),
            'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
            'activation_key': self.activation_key,
            'to': self.user.email
        }

        msg = UserSignIn(email_context, self.user.email)
        msg.send()
Ejemplo n.º 34
0
    def handle(self, *args, **options):
        for email in args:
            if User.objects.filter(email__iexact=email):
                sys.stderr.write(
                    "User with email %s already exists. Skipping.\n" % email)
                continue

            while True:
                username = hashlib.sha1(email).hexdigest()[:16]
                try:
                    User.objects.get(username__iexact=username)
                except User.DoesNotExist:
                    break

            # create user
            new_user = UserenaSignup.objects.create_user(username,
                                                         email,
                                                         None,
                                                         active=False,
                                                         send_email=False)

            # send activation email
            context = {
                'user': new_user,
                'without_usernames':
                userena_settings.USERENA_WITHOUT_USERNAMES,
                'protocol': get_protocol(),
                'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
                'activation_key': new_user.userena_signup.activation_key,
                'site': Site.objects.get_current()
            }

            subject = render_to_string('emails/activation_subject.txt',
                                       context)
            subject = ''.join(subject.splitlines())

            body = render_to_string('emails/activation_body.txt', context)

            send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [
                new_user.email,
            ])

            self.stdout.write("Created user for %s\n" % email)
Ejemplo n.º 35
0
    def send_activation_email(self):
        """
        Sends a activation email to the user.

        This email is send when the user wants to activate their newly created
        user.

        """
        context = {
            "user": self.user,
            "without_usernames": userena_settings.USERENA_WITHOUT_USERNAMES,
            "protocol": get_protocol(),
            "activation_days": userena_settings.USERENA_ACTIVATION_DAYS,
            "activation_key": self.activation_key,
            "site": shortcuts.get_current_site(request=None),
        }

        mailer = UserenaConfirmationMail(context=context)
        mailer.generate_mail("activation")
        mailer.send_mail(self.user.email)
Ejemplo n.º 36
0
    def send_activation_email(self):
        """
        Sends a activation email to the user.

        This email is send when the user wants to activate their newly created
        user.

        """
        context = {
            "user": self.user,
            "protocol": get_protocol(),
            "activation_days": userena_settings.USERENA_ACTIVATION_DAYS,
            "activation_key": self.activation_key,
            "site": Site.objects.get_current(),
        }

        subject = render_to_string("userena/emails/activation_email_subject.txt", context)
        subject = "".join(subject.splitlines())

        message = render_to_string("userena/emails/activation_email_message.txt", context)
        send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.user.email])
Ejemplo n.º 37
0
    def send_registration_confirmation_email(self):
        context = {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'protocol': get_protocol(),
                  'site': Site.objects.get_current()}

        subject = render_to_string('profiles/emails/registration_confirm_subject.txt',
                                       context)
        subject = ''.join(subject.splitlines())

        if (not userena_settings.USERENA_HTML_EMAIL or not message_old_html or
            userena_settings.USERENA_USE_PLAIN_TEMPLATE):
            message = render_to_string('profiles/emails/registration_confirm_message.txt',
                                       context)

        if self.user.email:
            send_mail(subject,
                      message,
                      None,
                      settings.DEFAULT_FROM_EMAIL,
                    [self.user.email])
Ejemplo n.º 38
0
    def send_activated_email(self):
        """
        Sends a activated email to the user.

        This email is send when a new user has been created and activated.

        """
        context= {'user': self.user,
                  'protocol': get_protocol(),
                  'site': Site.objects.get_current()}

        subject = render_to_string('userena/emails/activated_email_subject.txt',
                                   context)
        subject = ''.join(subject.splitlines())

        message = render_to_string('userena/emails/activated_email_message.txt',
                                   context)
        send_mail(subject,
                  message,
                  settings.DEFAULT_FROM_EMAIL,
                  [self.user.email,])
Ejemplo n.º 39
0
    def send_activation_email(self, **extra_context):
        """
        Sends a activation email to the user.

        This email is send when the user wants to activate their newly created
        user.

        """
        context = {'user': self.user,
                  'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
                  'protocol': get_protocol(),
                  'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
                  'activation_key': self.activation_key,
                  'site': Site.objects.get_current()}

        context.update(extra_context)

        subject = render_to_string('userena/emails/activation_email_subject.txt',
                                   context)
        subject = ''.join(subject.splitlines())


        if userena_settings.USERENA_HTML_EMAIL:
            message_html = render_to_string('userena/emails/activation_email_message.html',
                                            context)
        else:
            message_html = None

        if (not userena_settings.USERENA_HTML_EMAIL or not message_html or
            userena_settings.USERENA_USE_PLAIN_TEMPLATE):
            message = render_to_string('userena/emails/activation_email_message.txt',
                                   context)
        else:
            message = None

        send_mail(subject,
                  message,
                  message_html,
                  settings.DEFAULT_FROM_EMAIL,
                  [self.user.email, ])
Ejemplo n.º 40
0
    def send_approval_email(self):
        """
        Sends an approval email to the user.

        This email is sent when USERENA_MODERATE_SIGNUP, after an admin
        has approved the signup.

        """
        context= {'user': self.user,
                  'protocol': get_protocol(),
                  'site': Site.objects.get_current()}

        subject = render_to_string('userena/emails/approval_email_subject.txt',
            context)
        subject = ''.join(subject.splitlines())

        message = render_to_string('userena/emails/approval_email_message.txt',
            context)
        send_mail(subject,
            message,
            settings.DEFAULT_FROM_EMAIL,
            [self.user.email,])
Ejemplo n.º 41
0
def send_message_notification(sender, instance, **kwargs):
    """
    Send email when user receives a new message. This email contains the full text
    and a link to read it online.

    We trigger this when a MessageRecipient is saved and not when a Message is
    saved because umessages first saves a message and then adds its recipients,
    so when a Message is saved, it doesn't yet have a list of recipients.
    """

    if not instance.user.email:
        # Email can be missing for users registered with Twitter
        # or LinkedIn
        return

    params = {
        'sender': instance.message.sender.username,
        'body': instance.message.body,
    }
    message_url_path = reverse('userena_umessages_detail',
                               kwargs={'username': params['sender']})
    params['message_url'] = "%s://%s%s" % (
        get_protocol(), Site.objects.get_current(), message_url_path)

    subject = _(
        u'New message from %(sender)s on Imagination For People') % params
    message = render_to_string('umessages/message_notification.txt', params)
    recipient = instance.user.email

    # XXX Resets the Content-Transfer-Encoding in email header
    # Avoids bad encoding of UTF-8 body
    # See https://code.djangoproject.com/ticket/3472
    from email import Charset
    Charset.add_charset('utf-8', Charset.SHORTEST, 'utf-8', 'utf-8')

    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [recipient])
Ejemplo n.º 42
0
    def test_get_protocol(self):
        """ Test if the correct protocol is returned """
        self.assertEqual(get_protocol(), "http")

        with self.settings(USERENA_USE_HTTPS=True):
            self.assertEqual(get_protocol(), "https")
Ejemplo n.º 43
0
    def test_get_protocol(self):
        """ Test if the correct protocol is returned """
        self.failUnlessEqual(get_protocol(), 'http')

        with self.settings(USERENA_USE_HTTPS=True):
            self.failUnlessEqual(get_protocol(), 'https')
Ejemplo n.º 44
0
    def test_get_protocol(self):
        """ Test if the correct protocol is returned """
        self.failUnlessEqual(get_protocol(), 'http')

        with self.settings(USERENA_USE_HTTPS=True):
            self.failUnlessEqual(get_protocol(), 'https')