Пример #1
0
def send_verification_mail_for_email_update(request, user, new_email,
                                            verification_type):
    """
    Sends an email with a verification link to users when
    they update their email. The email is sent to the new email.
    The actual update of the email happens only after
    the verification link is clicked.
    The ``verification_type`` arg is both the name of the urlpattern for
    the verification link, as well as the names of the email templates
    to use.
    """
    verify_url = reverse(verification_type,
                         kwargs={
                             "uidb36": int_to_base36(user.id),
                             "token": default_token_generator.make_token(user),
                             "new_email": new_email
                         }) + "?next=" + (next_url(request) or "/")
    context = {
        "request": request,
        "user": user,
        "new_email": new_email,
        "verify_url": verify_url,
    }
    subject_template_name = "email/%s_subject.txt" % verification_type
    subject = subject_template(subject_template_name, context)
    send_mail_template(subject,
                       "email/%s" % verification_type,
                       settings.DEFAULT_FROM_EMAIL,
                       new_email,
                       context=context)
Пример #2
0
def send_verification_mail_for_email_update(request, user, new_email, verification_type):
    """
    Sends an email with a verification link to users when
    they update their email. The email is sent to the new email.
    The actual update of the email happens only after
    the verification link is clicked.
    The ``verification_type`` arg is both the name of the urlpattern for
    the verification link, as well as the names of the email templates
    to use.
    """
    verify_url = reverse(verification_type, kwargs={
        "uidb36": int_to_base36(user.id),
        "token": default_token_generator.make_token(user),
        "new_email": new_email
    }) + "?next=" + (next_url(request) or "/")
    context = {
        "request": request,
        "user": user,
        "new_email": new_email,
        "verify_url": verify_url,
    }
    subject_template_name = "email/%s_subject.txt" % verification_type
    subject = subject_template(subject_template_name, context)
    send_mail_template(subject, "email/%s" % verification_type,
                       settings.DEFAULT_FROM_EMAIL, new_email,
                       context=context)
Пример #3
0
 def send_email_to_operators_on_adding(self, request):
     template = "openhelpdesk/email/ticket/ticket_operators_creation"
     subject = subject_template(
         "{}_subject.html".format(template), {
             'ticket_name': self._meta.verbose_name.lower(),
             'username': self.requester.username
         })
     try:
         site_conf = SiteConfiguration.objects.get(site=self.site)
         addr_from = site_conf.email_addr_from
         addr_to = site_conf.email_addrs_to
     except SiteConfiguration.DoesNotExist:
         addr_from = SiteConfiguration.get_no_site_email_addr_from()
         addr_to = SiteConfiguration.get_no_site_email_addrs_to()
     change_url = reverse(admin_urlname(self._meta, 'change'),
                          args=(self.pk, ))
     context = {
         'ticket_name': self._meta.verbose_name,
         'ticket': self,
         'request': request,
         'change_url': change_url
     }
     send_mail_template(subject,
                        template,
                        addr_from,
                        addr_to,
                        context=context,
                        attachments=None)
Пример #4
0
    def send_email_to_requester(self, request):
        template = "openhelpdesk/email/report/info_to_request"
        context = {
            'report_name': self._meta.verbose_name.lower(),
            'operator': request.user.username,
            'ticket_id': self.ticket_id
        }

        subject = subject_template("{}_subject.html".format(template), context)
        addr_from = request.user.email
        addr_to = [self.ticket.requester.email]
        change_ticket_url = '{}#tab_messages'.format(
            reverse(admin_urlname(self.ticket._meta, 'change'),
                    args=(self.ticket_id, )))
        context.update({
            'report': self,
            'request': request,
            'change_ticket_url': change_ticket_url
        })
        send_mail_template(subject,
                           template,
                           addr_from,
                           addr_to,
                           context=context,
                           attachments=None)
Пример #5
0
 def handle(self, *args, **ops):
     count = 0
     verification_type = "signup_verify"
     request = {'get_host': 'aichallenge.sharif.edu:2016'}
     for user in tqdm(Member.objects.filter(is_active=False), leave=False):
         verify_url = reverse(
             verification_type,
             kwargs={
                 "uidb36": int_to_base36(user.id),
                 "token": default_token_generator.make_token(user),
             }) + "?next=" + "/"
         context = {
             "request": request,
             "user": user,
             "verify_url": verify_url,
         }
         subject_template_name = "email/%s_subject.txt" % verification_type
         subject = subject_template(subject_template_name, context)
         send_mail_template(subject,
                            "email/%s" % verification_type,
                            settings.DEFAULT_FROM_EMAIL,
                            user.email,
                            context=context)
         count += 1
     self.stdout.write("resent %d verification email" % count)
Пример #6
0
    def send_email_to_requester(self, request):
        template = "openhelpdesk/email/report/info_to_request"
        operator = request.user
        operator_name = operator.username
        if operator.last_name and operator.first_name:
            operator_name = '{} {}'.format(operator.first_name,
                                           operator.last_name)
        context = {'report_name': self._meta.verbose_name.lower(),
                   'operator': operator,
                   'operator_name': operator_name,
                   'ticket_id': self.ticket_id,
                   'email_background_color': (
                       OrganizationSetting.email_objects.get_color(
                           self.ticket.requester.email))}

        try:
            site_conf = SiteConfiguration.objects.get(site=self.ticket.site)
            addr_from = site_conf.email_addr_from
        except (SiteConfiguration.DoesNotExist, Ticket.DoesNotExist):
            addr_from = SiteConfiguration.get_no_site_email_addr_from()

        subject = subject_template("{}_subject.html".format(template), context)
        addr_to = [self.ticket.requester.email]
        change_ticket_url = '{}#tab_messages'.format(
            reverse(admin_urlname(self.ticket._meta, 'change'),
                    args=(self.ticket_id,)))
        context.update({'report': self, 'request': request,
                        'change_ticket_url': change_ticket_url})
        send_mail_template(subject, template, addr_from, addr_to,
                           context=context, attachments=None)
Пример #7
0
    def send_email_to_operators_on_adding(self, request):
        template = "openhelpdesk/email/ticket/ticket_operators_creation"
        requester_name = _('no personal info assigned')
        if self.requester.last_name and self.requester.first_name:
            requester_name = '{} {}'.format(self.requester.first_name,
                                            self.requester.last_name)
        subject = subject_template(
            "{}_subject.html".format(template),
            {'ticket_name': self._meta.verbose_name.lower(),
             'username': self.requester.email or self.requester.username})
        try:
            site_conf = SiteConfiguration.objects.get(site=self.site)
            addr_from = site_conf.email_addr_from
            addr_to = site_conf.email_addrs_to
        except SiteConfiguration.DoesNotExist:
            addr_from = SiteConfiguration.get_no_site_email_addr_from()
            addr_to = SiteConfiguration.get_no_site_email_addrs_to()
        change_url = reverse(admin_urlname(self._meta, 'change'),
                             args=(self.pk,))

        email_background_color = (
            OrganizationSetting.email_objects.get_color(
                self.requester.email))
        context = {'ticket_name': self._meta.verbose_name, 'ticket': self,
                   'request': request, 'change_url': change_url,
                   'requester_username': self.requester.username,
                   'requester_email': self.requester.email or _(
                       'no email assigned'),
                   'requester_name': requester_name,
                   'email_background_color': email_background_color}
        send_mail_template(subject, template, addr_from, addr_to,
                           context=context, attachments=None)
Пример #8
0
 def send_email_report(user, ldap_user):
     template = "openhelpdesk/email/report/ldap_backend/on_creation"
     context = {'user': user}
     subject = subject_template("{}_subject.txt".format(template), context)
     context.update(
         {'ldap_user': ldap_user,
          'groups': user.groups.order_by('name').values_list(
              'name', flat=True),
          'domains': user.sitepermissions.sites.order_by('pk').values_list(
              'domain', flat=True),
          'user_opts': user._meta},)
     message = loader.get_template("{}.txt".format(template)).render(
         Context(context))
     mail_managers(subject, message, True)
     return True
Пример #9
0
def send_action_to_take_email(request, user, action_type, **kwargs):
    """
    Sends an email with an action link to a user.
    The actual action takes place when the user clicks on the link

    The ``action_type`` arg is both the name of the urlpattern for
    the action link, as well as the names of the email templates
    to use. Additional context variable needed in the email template can be
    passed using the kwargs

    for action_type == 'group_membership', an instance of GroupMembershipRequest and
    instance of Group are expected to
    be passed into this function
    """
    email_to = kwargs.get('group_owner', user)
    context = {'request': request, 'user': user}
    if action_type == 'group_membership':
        membership_request = kwargs['membership_request']
        action_url = reverse(
            action_type,
            kwargs={
                "uidb36": int_to_base36(email_to.id),
                "token": default_token_generator.make_token(email_to),
                "membership_request_id": membership_request.id
            }) + "?next=" + (next_url(request) or "/")

        context['group'] = kwargs.pop('group')
    elif action_type == 'group_auto_membership':
        context['group'] = kwargs.pop('group')
        action_url = ''
    else:
        action_url = reverse(
            action_type,
            kwargs={
                "uidb36": int_to_base36(email_to.id),
                "token": default_token_generator.make_token(email_to)
            }) + "?next=" + (next_url(request) or "/")

    context['action_url'] = action_url
    context.update(kwargs)

    subject_template_name = "email/%s_subject.txt" % action_type
    subject = subject_template(subject_template_name, context)
    send_mail_template(subject,
                       "email/%s" % action_type,
                       settings.DEFAULT_FROM_EMAIL,
                       email_to.email,
                       context=context)
Пример #10
0
    def send_email_to_requester(self, request):
        template = "openhelpdesk/email/report/info_to_request"
        context = {'report_name': self._meta.verbose_name.lower(),
                   'operator': request.user.username,
                   'ticket_id': self.ticket_id}

        subject = subject_template("{}_subject.html".format(template), context)
        addr_from = request.user.email
        addr_to = [self.ticket.requester.email]
        change_ticket_url = '{}#tab_messages'.format(
            reverse(admin_urlname(self.ticket._meta, 'change'),
                    args=(self.ticket_id,)))
        context.update({'report': self, 'request': request,
                        'change_ticket_url': change_ticket_url})
        send_mail_template(subject, template, addr_from, addr_to,
                           context=context, attachments=None)
Пример #11
0
 def send_emails_on_creation(self, request):
     for template, addr_to in [
         ('booking_created_booker', self.booker.email),
         ('booking_created_operator',
          self.slottime.booking_type.get_notification_emails())]:
         try:
             send_mail_template(
                 subject_template(
                     'nowait/email/subject/{}.txt'.format(template), None),
                 'nowait/email/{}'.format(template), settings.SERVER_EMAIL,
                 addr_to, context={'booking': self,
                                   'request': request})
         except SMTPException as e:
             logger = logging.getLogger('django.request')
             logger.error(
                 'Internal Server Error: %s', request.path,
                 exc_info=str(e),
                 extra={'status_code': 500, 'request': request})
Пример #12
0
    def notify_to_operator(self, request):
        template = "openhelpdesk/email/message/notify_to_operator"
        context = {
            'message_verbose_name':
            self._meta.verbose_name.lower(),
            'message_from':
            '{} {}'.format(self.sender.last_name.capitalize(),
                           self.sender.first_name.capitalize()),
            'message_from_email':
            self.sender.email,
            'email_background_color':
            (OrganizationSetting.email_objects.get_color(self.sender.email))
        }

        try:
            site_conf = SiteConfiguration.objects.get(site=self.ticket.site)
            addr_from = site_conf.email_addr_from
        except (SiteConfiguration.DoesNotExist, Ticket.DoesNotExist):
            addr_from = SiteConfiguration.get_no_site_email_addr_from()

        subject = subject_template("{}_subject.html".format(template), context)
        # TODO: gestire la questione del destinatario
        addr_to = '*****@*****.**'
        if self.ticket.assignee:
            addr_to = self.ticket.assignee.email
        ticket_url = 'http://{}{}'.format(
            request.get_host(),
            reverse(admin_urlname(self.ticket._meta, 'change'),
                    args=(self.ticket_id, )))
        context.update({
            'request': request,
            'ticket_url': ticket_url,
            'message_url': ticket_url + "#tab_messages",
            'ticket_id': self.ticket.id,
            'content': self.content,
            'ticket_status': self.ticket.status
        })

        send_mail_template(subject,
                           template,
                           addr_from,
                           addr_to,
                           context=context,
                           attachments=None)
Пример #13
0
 def send_email_to_operators_on_adding(self, request):
     template = "openhelpdesk/email/ticket/ticket_operators_creation"
     subject = subject_template(
         "{}_subject.html".format(template),
         {'ticket_name': self._meta.verbose_name.lower(),
          'username': self.requester.username})
     try:
         site_conf = SiteConfiguration.objects.get(site=self.site)
         addr_from = site_conf.email_addr_from
         addr_to = site_conf.email_addrs_to
     except SiteConfiguration.DoesNotExist:
         addr_from = SiteConfiguration.get_no_site_email_addr_from()
         addr_to = SiteConfiguration.get_no_site_email_addrs_to()
     change_url = reverse(admin_urlname(self._meta, 'change'),
                          args=(self.pk,))
     context = {'ticket_name': self._meta.verbose_name, 'ticket': self,
                'request': request, 'change_url': change_url}
     send_mail_template(subject, template, addr_from, addr_to,
                        context=context, attachments=None)
Пример #14
0
 def send_email_report(user, ldap_user):
     template = "openhelpdesk/email/report/ldap_backend/on_creation"
     context = {'user': user}
     subject = subject_template("{}_subject.txt".format(template), context)
     context.update(
         {
             'ldap_user':
             ldap_user,
             'groups':
             user.groups.order_by('name').values_list('name', flat=True),
             'domains':
             user.sitepermissions.sites.order_by('pk').values_list(
                 'domain', flat=True),
             'user_opts':
             user._meta
         }, )
     message = loader.get_template("{}.txt".format(template)).render(
         Context(context))
     mail_managers(subject, message, True)
     return True
 def handle(self, *args, **ops):
     count = 0
     verification_type = "signup_verify"
     request = {'get_host': 'aichallenge.sharif.edu:2016'}
     for user in tqdm(Member.objects.filter(is_active=False), leave=False):
         verify_url = reverse(verification_type, kwargs={
             "uidb36": int_to_base36(user.id),
             "token": default_token_generator.make_token(user),
         }) + "?next=" + "/"
         context = {
             "request": request,
             "user": user,
             "verify_url": verify_url,
         }
         subject_template_name = "email/%s_subject.txt" % verification_type
         subject = subject_template(subject_template_name, context)
         send_mail_template(subject, "email/%s" % verification_type,
                            settings.DEFAULT_FROM_EMAIL, user.email,
                            context=context)
         count += 1
     self.stdout.write("resent %d verification email" % count)
Пример #16
0
def send_verification_mail_for_password_reset(request, user):
    """
    Sends an email with a verification link to users when
    they request to reset forgotten password to their email. The email is sent to the new email.
    The actual reset of of password will begin after the user clicks the link
    provided in the email.
    The ``verification_type`` arg is both the name of the urlpattern for
    the verification link, as well as the names of the email templates
    to use.
    """
    reset_url = reverse('email_verify_password_reset',
                        kwargs={
                            "uidb36": int_to_base36(user.id),
                            "token": default_token_generator.make_token(user)
                        }) + "?next=" + (next_url(request) or "/")
    context = {"request": request, "user": user, "reset_url": reset_url}
    subject_template_name = "email/reset_password_subject.txt"
    subject = subject_template(subject_template_name, context)
    send_mail_template(subject,
                       "email/reset_password",
                       settings.DEFAULT_FROM_EMAIL,
                       user.email,
                       context=context)
Пример #17
0
def send_verification_mail_for_password_reset(request, user):
    """
    Sends an email with a verification link to users when
    they request to reset forgotten password to their email. The email is sent to the new email.
    The actual reset of of password will begin after the user clicks the link
    provided in the email.
    The ``verification_type`` arg is both the name of the urlpattern for
    the verification link, as well as the names of the email templates
    to use.
    """
    reset_url = reverse('email_verify_password_reset', kwargs={
        "uidb36": int_to_base36(user.id),
        "token": default_token_generator.make_token(user)
    }) + "?next=" + (next_url(request) or "/")
    context = {
        "request": request,
        "user": user,
        "reset_url": reset_url
    }
    subject_template_name = "email/reset_password_subject.txt"
    subject = subject_template(subject_template_name, context)
    send_mail_template(subject, "email/reset_password",
                       settings.DEFAULT_FROM_EMAIL, user.email,
                       context=context)