quick search:
 

portal_memberdata export usernames/passwords

Submitted by: cabbie
Last Edited: 2006-03-21

Category: Python(External Method)

Average rating is: 5.0 out of 5 (1 ratings)

Description:
Taking the other receipes and making one that exports the username and password.

It could be modified to include the other data as per the other receipes but I didn't need that.


Source (Text):
# routine to create CSV file from Plone member attributes
# filters list of member attributes and presents in nice order

import csv
import StringIO
import time

def makeRow():
    return [''] * 2

def createcsv(self):
    """ returns a csv file with member attributes """
    request = self.REQUEST
    text = StringIO.StringIO()
    memberProperties = self.portal_memberdata.propertyIds()
    acl_users = self.acl_users

    writer = csv.writer(text)

    # make heading row
    row = makeRow()
    row[0] = 'member_id'
    row[1] = 'password'

    writer.writerow(row)

    for member in self.portal_membership.listMembers():

        # make row for each member full of blank values
        row = makeRow()
        member_id = member.getId()
        user = acl_users.getUser(name=member_id)
        password = user._getPassword()
        row[0] = member_id
        row[1] = password

        writer.writerow(row)


    request.RESPONSE.setHeader('Content-Type','application/csv')
    request.RESPONSE.setHeader('Content-Length',len(text.getvalue()))
    request.RESPONSE.setHeader('Content-Disposition','inline;filename=%smembers.csv' %
                                time.strftime("%Y%m%d-%H%M%S-",time.localtime()))

    return text.getvalue()

Comments:

More details? by benr - 2006-03-10
I'm interested in extracting the data from a plone site. This looks like it might be a start.

Could you elaborate on the instructions here? I turn it into an External Method, but in which directory?

I take it this puts all the data into a csv. Where does that csv end up?

And what are the other recipes mentioned in the top of the recipe?

I realize this is plone-specific, but I'd really appreciate a pointer towards a practical application of this recipe.

Thanks!

-Ben Riddell


Awesome by hpinson - 2006-03-21
This works like a charm in Plone, and solves a huge Plone problem-- 
user changes password, forgets username, forgets password, and 
thereby cannot retrieve their lost password.

Plone users, simply create a script named something like export.py 
in the Plone Extensions directory, using the above content.  Then 
in the ZMI, create an external method with...

id: export
module name: export
function: createcsv

Click the test tab, and voila, a CSV file will be downloaded to 
your computer.  You can save or open it.

Note that this is a HUGE security hole.  Leaving such a script 
exposed is just asking for it.  You've been warned!  But created 
and deleted on the fly, it can be darned convienient.