Hello: Just an update and review on a previous thread and some progress.
I'm trying to write a Python script to do the following:
- Dump all the members from a email list within mailman instance A. This includes the display name, email, password hash, and all the preferences. The output is a json file.
- Then we read this json file and create the user, membership to the email list, and the preferences into mailman instance B.
The problem is that we are trying to insert the members with the password hash and NOT a new plain text password.
A simple json dump example:
{ "password":"$6$rounds=656000$QhEAT7XCQ9tyUmJV$cj2xv3GKd8UXdSSasMZdqe0NjUL4T751nBEkdubog55jzIY1iZ5AQ4aRVeJIi1jnS1CKHHJn6nVnW.Hz91Xvk.",
"list_fqdn": "helpme@confused.com", "display_name": "Bob Nobody", "email": "nobody@nowhere.com", "preferences": { "receive_list_copy": false, "hide_address": false, "preferred_language": "en", "delivery_mode": "regular", "receive_own_postings": true, "acknowledge_posts": false, "delivery_status": "enabled" } }
The code for this within the mailman client API is pretty straight forward. However, the method for create_member will not work for our situation because the argument requires the password to be in plain text to be encrypted later. The rest of the tasks (subscribing, preferences) can be done with the mailman client with this single exception.
Now my question is irf someone can send a single piece of code example or where to look to accomplish this.
I see two options:
Using the mainman core. I believe the modified code would be something like this:
user_manager = getUtility(IUserManager) #with transaction(): new_user = user_manager.create_user( 'nobody@where.com', 'Bob Nobody') new_user.password = config.password_context.encrypt('abc123') #replace with hash new_user.password = '$6$rounds=656000$tS8sTX'
So the password is set with the hash instead of the encryption method.
Original code: new_user.password = config.password_context.encrypt('abc123')
The other possible method is through django. However, I'm not really sure where to being on this on as I've been looking over the django-mailman3 and this is the only example I can find in test_delete_account.py:
def setUp(self): self.mm_user = Mock() self.mm_user.user_id = "dummy" self.mailman_client.get_user.side_effect = lambda e: self.mm_user self.user = User.objects.create_user( 'testuser', 'test@example.com', 'testPass', first_name="firstname", last_name="lastname", )
self.client.login(username='testuser', password='testPass')
Again, it appears that the password is encrypted somewhere else before encrypted.
Any help on this is greatly appreciated.
Thanks
Conrad