示例#1
0
 def send_if_not_subscriber(self, relay, mlist, target, address, template, host='postosaurus.com'):
     
     name, addr = parseaddr(address)
     user = mailinglist.find_user(addr)
     if user:
         if not mailinglist.find_subscription(addr, mlist.name):
             return self.send(relay, mlist, target, address, template, host)
     else:
         return self.send(relay, mlist, target, address, template, host)
示例#2
0
def create_user(request, template='postosaurus/create-user.html', next=settings.LOGIN_URL):
    
    """
    Creates an account for the web application.
    """

    if request.method == 'POST':
        form = UserAccountForm(request.POST)
        next = form.data['next']
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            repassword = form.cleaned_data['repassword']
            email = form.cleaned_data['email']

            #never populate the email address of the django model. This is duplicated
            #in the postosaurus user model.
            djangouser = DjangoUser.objects.create_user(username, '', password)
            djangouser.save()
            user = mailinglist.find_user(email)
            if not user:
                user = User(email=email)
                user.save()

            user.user = djangouser
            user.save()
            
            djangouser = authenticate(username=djangouser.username, password=password)
            login(request, djangouser)

            return HttpResponseRedirect(next)
        else:
            return render_to_response(template, {
                    'form' : form,
                    'next' : next
                    }, context_instance = RequestContext(request))
    else:

        # override next if there is a value in the query string.
        if request.GET.has_key('next'):
            if request.GET['next']:
                next = request.GET['next']

        return render_to_response(template, {
                'form' : UserAccountForm(),
                'next' : next
                }, context_instance = RequestContext(request))
示例#3
0
def store_file(list_name, message, filename, dbmessage):

    """
    Given a list name and a filename store the attached file
    in the filesystem and create a db record to track relationships,
    (like this file was sent with this message, etc).
    """

    mlist = mailinglist.find_list(list_name)
    name, addr = parseaddr(message['from'])
    user = mailinglist.find_user(addr)
    sha = create_hash_from_msg(message, filename)
    dbfile = File(mlist = mlist,
                  message = dbmessage,
                  user = user,
                  sha = sha,
                  name = filename,
                  ext = os.path.splitext(filename)[1])
    dbfile.save()

    try:
        # try to just open the file and create it, assumes the directories already
        # exist, which they may not.
        pfile = open(dbfile.local_path(), 'w')
        pfile.write(file_text(message, filename))
        pfile.close()
    except IOError:
        # The directories haven't been created yet, go
        # through and make 'em.

        path = ""
        for part in dbfile.local_path().split("/")[:-1]:
            path = os.path.join(path, part)
            if not os.path.isdir(path):
                os.mkdir(path)

        #try again. Code duplicated to avoid performance hit checking to see if directory exists every
        #single time. This only needs to be done once per group.
        pfile = open(dbfile.local_path(), 'w')
        pfile.write(file_text(message, filename))
        pfile.close()
        
        if os.path.islink(dbfile.recent_local_path()):
            os.remove(dbfile.recent_local_path())
        os.symlink(os.path.join(dbfile.sha, dbfile.name), dbfile.recent_local_path())

    return dbfile
示例#4
0
def START(message, list_name=None, id_number=None, host=None):
    
    """
    The start state looks for confirmation emails and move users with valid
    confirmation emails into a posting state. We also create the user's
    postosaurus account (if needed) and subscription here.

    This prevents users from being added to a list if they
    don't want to be.
    """

    mlist = mailinglist.find_list(list_name)
    if mlist:
        if CONFIRM.verify(mlist, 'confirm', message['from'], id_number):
            # Let them know they've been added.
            name, address = parseaddr(message['from'])
            CONFIRM.notify(relay, mlist, 'confirm', address)
            user = mailinglist.find_user(address)
            if not user:
                user = mailinglist.create_user(address)
            mailinglist.add_if_not_subscriber(address, list_name)
            return POSTING
    return START