Automate Plone5.2 login user account creation

Hi,

I'm looking for the effective way to create more than 200 login users account for Plone5.2 intranet project.
Is there any add-on that can convert CSV user list to Plone account?
I appreciate any advice.

Thank you,
Shigeo Honda

Use plone.api.user.create() and the csv module of Python for writing an importer...nothing more than a few lines of code. Zero need for an add-on.

You could (re-)use the @@import_members view from collective.exportimport and provide a JSON with the following format:

{
    "groups": [
        {
            "description": "",
            "email": "",
            "groupid": "Reviewers",
            "groups": [],
            "roles": [
                "Reviewer"
            ],
            "title": "Reviewers"
        },
        {
            "description": "",
            "email": "",
            "groupid": "Site Administrators",
            "groups": [],
            "roles": [
                "Site Administrator"
            ],
            "title": "Site Administrators"
        },
        {
            "description": "Extranet Editors",
            "email": "",
            "groupid": "extranet",
            "groups": [],
            "roles": [
                "Reader"
            ],
            "title": "Extranet Editors"
        },
    ],
    "members": [
        {
            "description": "",
            "email": "example@gmail.com",
            "fullname": "Example Example",
            "groups": [],
            "home_page": "",
            "last_login_time": "2016-06-25T00:03:04+00:00",
            "listed": true,
            "location": "",
            "login_time": "2016-06-25T19:45:04+00:00",
            "password": "{SSHA}W1YSVUajeCSgTYN1B1JxFzNZUa9n/rV+Ddvc",
            "roles": [
                "Reader"
            ],
            "username": "example1"
        },
        {
            "description": "",
            "email": "example2@example.com",
            "fullname": "Example Example (Foo)",
            "groups": [],
            "home_page": "",
            "last_login_time": "2016-04-19T08:56:06+00:00",
            "listed": true,
            "location": "",
            "login_time": "2016-04-19T09:36:51+00:00",
            "password": "{SSHA}q/ZTEW9yQJT7XxIbwASAv5dqctel/tlgQaKi",
            "roles": [
                "Member",
                "Reader"
            ],
            "username": "example2"
        },
        {
            "description": "",
            "email": "example3@example.com",
            "fullname": "Rest Test",
            "groups": [],
            "home_page": "",
            "last_login_time": "2017-09-27T09:51:30+00:00",
            "listed": true,
            "location": "",
            "login_time": "2017-09-27T09:51:30+00:00",
            "password": "{SSHA}yU1PnlcM6NPd7054yPYgwnIWU4Z/f8WzHq8t",
            "roles": [
                "Member",
                "Reader",
                "Manager"
            ],
            "username": "example3"
        }
    ]
}

Thank you for using API advice.
I'll try to write python code.

Thank you.
Shigeo Honda

Thank you, Peter.
It's very helpful. I'll try collective.exportimport add-on.

Thank you.
Shigeo Honda

I agree with zopyx here

Slightly off topic, but if you have excel files you can use it like this (and then add plone.users.create() with the keys as userproperties.

#python 3
# Not sure if you need all below for your case

import pandas as pd
import openpyxl
#from zope.lifecycleevent import modified
import plone.api
from zope.component.hooks import setSite
import transaction

setSite(app['Plonee'])
excelfile = 'myexelfile.xlsx'

from pandas import *

df = pd.read_excel('27april.xlsx')
#just check what we got
print(df)

my_dict = df.to_dict(orient='index')

def add_metadata(brain):
    # I use this in a script to update items
    # obj = brain.getObject()
    for key, value in my_dict[i].items():

        #print(key)
        if key=='type':
            key = 'skipstype'

I made JSON format account file and imported with collective.exportimport. It worked well and new accounts are add to plone site.

However, passwords don't work and can't login. I tried both password text and SSHA hashed passwords like these,

        "password": "plain-text-password",

        "password": "{SSHA}e0ohOSFzJxkKS5KjarvuOCwWjDKoIwZEvr7d",

        # Use Python to hash the salted password using SHA-1
ssha_hash=$(python -c "import hashlib, base64; salted_password = '$salted_password'.encode('utf-8'); sha1_hash = hashlib.sha1(salted_password).digest(); print('{SSHA}' + base64.b64encode(sha1_hash).decode('utf-8'))")</pre>

but they both don't work.

How can I generate password for new accounts ?

I appreciate any advice.

Thank you,
Shigeo Honda

Never digged into this in deep, but the password is encrypted via AuthEncoding module. There's a method pw_encrypt which you might want to take a look at. Maybe this helps you generating a password: