Beispiel #1
0
 def reset_password(self, petitioner):
     """
     Resets the password of a node and send an email to the owners with the new password.
     petitioner: string containing the email address of who's requesting the password reset
     returns the raw password
     """
     import random
     bit1 = ''.join(
         random.choice('abcdefghilmnopqrstuvz') for i in xrange(5))
     bit2 = ''.join(random.choice('0123456789') for i in xrange(2))
     raw_password = bit1 + bit2
     self.password = raw_password
     self.set_password()
     self.save()
     # prepare context
     context = {
         'petitioner': petitioner,
         'node': self,
         'password': raw_password,
         'site': SITE
     }
     # send mail
     email_owners(self,
                  _('New password for node %(name)s') % {'name': self.name},
                  'email_notifications/password_recovery.txt', context)
     return raw_password
Beispiel #2
0
def delete_node(request, node_id, password):
    """
    Deletes a node, requires password.
    """
        
    # if request is sent with ajax
    if request.is_ajax():
        template = 'ajax/delete_node.html';
    else:
        template = 'delete_node.html';
        
    # get object or raise 404
    try:
        node = Node.objects.select_related().exclude(status='u').get(pk=node_id, password=password)
    except ObjectDoesNotExist:
        raise Http404
    
    # if form has been submitted
    if request.method == 'POST':
        # prepare context
        email_context = {
            'node': node,
            'site': SITE
        }
        email_owners(node, _('Node %(node)s deleted') % {'node':node.name}, 'email_notifications/node-deleted-owners.txt', email_context)
        messages.add_message(request, messages.INFO, _(u'The node %(node)s has been deleted successfully.') % {'node':node.name})
        node.delete()
        
        return HttpResponseRedirect(reverse('nodeshot_index'))
    
    context = {
        'node': node,
    }
    
    return render_to_response(template, context, context_instance=RequestContext(request))
Beispiel #3
0
 def send_success_mail(self, raw_password):
     ''' send success emails '''
     # prepare context
     context = {
         'node': self,
         'password': raw_password,
         'site': SITE
     }
     # send email to owners
     email_owners(self, _('Node confirmed successfully on %(site)s') % {'site':SITE['name']}, 'email_notifications/success.txt', context)
     # notify admins that want to receive notifications
     notify_admins(self, _('New node details on %(site)s') % {'site':SITE['name']}, 'email_notifications/new-node-admin.txt', context, skip=True)
Beispiel #4
0
 def send_activation_mail(self):
     """
     Sends activation link to node owners
     """
     # prepare context for email template
     context = {
         'node': self,
         'expiration_days': ACTIVATION_DAYS,
         'site': SITE,
     }
     # send mail to owners
     email_owners(self, _('Node confirmation required on %(site)s') % {'site':SITE['name']}, 'email_notifications/confirmation.txt', context)
Beispiel #5
0
 def send_activation_mail(self):
     """
     Sends activation link to node owners
     """
     # prepare context for email template
     context = {"node": self, "expiration_days": ACTIVATION_DAYS, "site": SITE}
     # send mail to owners
     email_owners(
         self,
         _("Node confirmation required on %(site)s") % {"site": SITE["name"]},
         "email_notifications/confirmation.txt",
         context,
     )
Beispiel #6
0
 def send_success_mail(self, raw_password):
     ''' send success emails '''
     # prepare context
     context = {'node': self, 'password': raw_password, 'site': SITE}
     # send email to owners
     email_owners(
         self,
         _('Node confirmed successfully on %(site)s') %
         {'site': SITE['name']}, 'email_notifications/success.txt', context)
     # notify admins that want to receive notifications
     notify_admins(self,
                   _('New node details on %(site)s') %
                   {'site': SITE['name']},
                   'email_notifications/new-node-admin.txt',
                   context,
                   skip=True)
Beispiel #7
0
 def send_activation_mail(self):
     """
     Sends activation link to node owners
     """
     # prepare context for email template
     context = {
         'node': self,
         'expiration_days': ACTIVATION_DAYS,
         'site': SITE,
     }
     # send mail to owners
     email_owners(
         self,
         _('Node confirmation required on %(site)s') %
         {'site': SITE['name']}, 'email_notifications/confirmation.txt',
         context)
Beispiel #8
0
 def send_success_mail(self, raw_password):
     """ send success emails """
     # prepare context
     context = {"node": self, "password": raw_password, "site": SITE}
     # send email to owners
     email_owners(
         self,
         _("Node confirmed successfully on %(site)s") % {"site": SITE["name"]},
         "email_notifications/success.txt",
         context,
     )
     # notify admins that want to receive notifications
     notify_admins(
         self,
         _("New node details on %(site)s") % {"site": SITE["name"]},
         "email_notifications/new-node-admin.txt",
         context,
         skip=True,
     )
Beispiel #9
0
def delete_node(request, node_id, password):
    """
    Deletes a node, requires password.
    """

    # if request is sent with ajax
    if request.is_ajax():
        template = 'ajax/delete_node.html'
    else:
        template = 'delete_node.html'

    # get object or raise 404
    try:
        node = Node.objects.select_related().exclude(status='u').get(
            pk=node_id, password=password)
    except ObjectDoesNotExist:
        raise Http404

    # if form has been submitted
    if request.method == 'POST':
        # prepare context
        email_context = {'node': node, 'site': SITE}
        email_owners(node,
                     _('Node %(node)s deleted') % {'node': node.name},
                     'email_notifications/node-deleted-owners.txt',
                     email_context)
        messages.add_message(
            request, messages.INFO,
            _(u'The node %(node)s has been deleted successfully.') %
            {'node': node.name})
        node.delete()

        return HttpResponseRedirect(reverse('nodeshot_index'))

    context = {
        'node': node,
    }

    return render_to_response(template,
                              context,
                              context_instance=RequestContext(request))
Beispiel #10
0
 def reset_password(self, petitioner):
     """
     Resets the password of a node and send an email to the owners with the new password.
     petitioner: string containing the email address of who's requesting the password reset
     returns the raw password
     """
     import random
     bit1 = ''.join(random.choice('abcdefghilmnopqrstuvz') for i in xrange(5))
     bit2 = ''.join(random.choice('0123456789') for i in xrange(2))
     raw_password = bit1 + bit2
     self.password = raw_password
     self.set_password()
     self.save()
     # prepare context
     context = {
         'petitioner': petitioner,
         'node': self,
         'password': raw_password,
         'site': SITE
     }
     # send mail
     email_owners(self, _('New password for node %(name)s') % {'name':self.name}, 'email_notifications/password_recovery.txt', context)
     return raw_password
Beispiel #11
0
    def reset_password(self, petitioner):
        """
        Resets the password of a node and send an email to the owners with the new password.
        petitioner: string containing the email address of who's requesting the password reset
        returns the raw password
        """
        import random

        bit1 = "".join(random.choice("abcdefghilmnopqrstuvz") for i in xrange(5))
        bit2 = "".join(random.choice("0123456789") for i in xrange(2))
        raw_password = bit1 + bit2
        self.password = raw_password
        self.set_password()
        self.save()
        # prepare context
        context = {"petitioner": petitioner, "node": self, "password": raw_password, "site": SITE}
        # send mail
        email_owners(
            self,
            _("New password for node %(name)s") % {"name": self.name},
            "email_notifications/password_recovery.txt",
            context,
        )
        return raw_password
Beispiel #12
0
def contact(request, node_id):
    """
    Displays a form to contact node owners
    """
    # if request is sent with ajax
    if request.is_ajax():
        # just load the fragment
        template = 'ajax/contact.html'
    # otherwise if request is sent normally and DEBUG is true
    elif DEBUG:
        # debuggin template
        template = 'contact.html'
    else:
        raise Http404
    
    # retrieve object or return 404 error
    try:
        node = Node.objects.only('name', 'email', 'email2', 'email3', 'status').exclude(status='u').get(pk=node_id)
    except ObjectDoesNotExist:
        raise Http404

    # message has not been sent yet
    sent = False

    # if form has been submitted
    if request.method == 'POST':
        # http referer
        http_referer = request.POST.get('http_referer')
        # save extra information in a dictionary that we'll pass to the form
        extra = {
            'node': node_id,
            # add extra info about the sender
            'ip': request.META.get('REMOTE_ADDR'),
            'user_agent': request.META.get('HTTP_USER_AGENT'),
            'accept_language': request.META.get('HTTP_ACCEPT_LANGUAGE')
        }

        # init form and pass extra values to it
        form = ContactForm(extra, request.POST)
        # proceed in sending email only if form is valid
        if form.is_valid():
            # prepare context
            context = {
                'node': node,
                'sender': {
                    'from_name': request.POST.get('from_name'),
                    'from_email': request.POST.get('from_email'),
                    'message': mark_safe(request.POST.get('message')),
                },
                'site': SITE
            }
            # email owners
            email_owners(node, _('Contact request from %(sender)s - %(site)s') % {'sender':context['sender']['from_name'], 'site':SITE['name']}, 'email_notifications/contact-node-owners.txt', context, reply_to=request.POST.get('from_email'))
            # set sent to true
            sent = True
            # if enabled from settings
            if LOG_CONTACTS:
                # save log into database
                new_log = form.save()

    # if form has NOT been submitted
    else:
        form = ContactForm()
        http_referer = request.META.get('HTTP_REFERER')

    context = {
        'sent': sent,
        'node': node,
        'form': form,
        'http_referer': http_referer
    }

    return render_to_response(template, context, context_instance=RequestContext(request))
Beispiel #13
0
def contact(request, node_id):
    """
    Displays a form to contact node owners
    """
    # if request is sent with ajax
    if request.is_ajax():
        # just load the fragment
        template = 'ajax/contact.html'
    # otherwise if request is sent normally and DEBUG is true
    elif DEBUG:
        # debuggin template
        template = 'contact.html'
    else:
        raise Http404

    # retrieve object or return 404 error
    try:
        node = Node.objects.only('name', 'email', 'email2', 'email3',
                                 'status').exclude(status='u').get(pk=node_id)
    except ObjectDoesNotExist:
        raise Http404

    # message has not been sent yet
    sent = False

    # if form has been submitted
    if request.method == 'POST':
        # http referer
        http_referer = request.POST.get('http_referer')
        # save extra information in a dictionary that we'll pass to the form
        extra = {
            'node': node_id,
            # add extra info about the sender
            'ip': request.META.get('REMOTE_ADDR'),
            'user_agent': request.META.get('HTTP_USER_AGENT'),
            'accept_language': request.META.get('HTTP_ACCEPT_LANGUAGE')
        }

        # init form and pass extra values to it
        form = ContactForm(extra, request.POST)
        # proceed in sending email only if form is valid
        if form.is_valid():
            # prepare context
            context = {
                'node': node,
                'sender': {
                    'from_name': request.POST.get('from_name'),
                    'from_email': request.POST.get('from_email'),
                    'message': mark_safe(request.POST.get('message')),
                },
                'site': SITE
            }
            # email owners
            email_owners(node,
                         _('Contact request from %(sender)s - %(site)s') % {
                             'sender': context['sender']['from_name'],
                             'site': SITE['name']
                         },
                         'email_notifications/contact-node-owners.txt',
                         context,
                         reply_to=request.POST.get('from_email'))
            # set sent to true
            sent = True
            # if enabled from settings
            if LOG_CONTACTS:
                # save log into database
                new_log = form.save()

    # if form has NOT been submitted
    else:
        form = ContactForm()
        http_referer = request.META.get('HTTP_REFERER')

    context = {
        'sent': sent,
        'node': node,
        'form': form,
        'http_referer': http_referer
    }

    return render_to_response(template,
                              context,
                              context_instance=RequestContext(request))