Jump to content

Import/Export of user


chuckymendoza
 Share

Recommended Posts

Hello together,

I had a deeper look into the forum but didn’t found anything, so I like to ask the following simple question. :-)

Is there a module or a simple technique to export all users from the backend into a file?

Afterwards, it should be possible to import the users again.

I have a ProcessWire installation on a dev server and I don’t like the idea to add all users again by hand on the live server   :-)

Thanks so much for your ideas.

-Thomas 

Link to comment
Share on other sites

While it's certainly possible it's not as easy as you may think it is. Passwords are stored as hashes in the database. ProcessWire will never store the plain text password. The hashing is dependent on the salt value stored in the config.php. The salt is generated as part of the installation process and therefore your live installation may have another salt value as the dev one. If this is the case it means all the passwords of imported users would be invalid after moving them. What you can do is to copy the whole users database table and copy over the salt value, too. As long as all hashes of user passwords are generated with the same salt value you can exchange users as you wish. But if you have users in both installations, where the passwords where saved with different salt values, you can not move the passwords over from one installation to another. You would need to change/update the passwords by hand in this case. Everything besides the passwords shouldn't be a problem.

  • Like 6
Link to comment
Share on other sites

  • 8 months later...

I am trying to find a solution for having same users with same passwords in 2 different PW installs and came across this thread.

How would I export the user table? There is no such table as users are pages. So  I would need to construct a MySQL query that gets all pages with user template and also grab required fields  name, pass, email.

Then the other tricky part would be to import that into the new PW install.

Is there a PW API side solution that also tranfers the password hashes to the new install?

Link to comment
Share on other sites

@LostKobraKai

Thank you. I will look into the Lister Pro Action.

Meanwhile I decided to export the users including their hashed password to csv with

// get desired users
$array = [];
$us = $users->find("roles=frontend");
foreach ($us as $key => $u) {
	$u->of(false);
	$array[$key] = ["id" => $u->id, "name" => $u->name, "email" => $u->email, "pass" => $u->pass];
}

// write to file
$fp = fopen('./inc/users.csv', 'w');
$i = 0;
foreach ($array as $fields) {
   // Add headings to the first line.
    if($i==0) fputcsv($fp, array_keys($fields), ",");
    fputcsv($fp, $fields);
 $i++;
}
fclose($fp);

Now I am looking into a way to import the users in the new PW install via API and in that process bypassing the regular $user->pass method for setting the password. So that I can store the hashed password as is during import. Then I'd only need to copy over the salt from the original PW install and the users should be able to login.

But when looking at the ___setPass($value) method in /wire/core/Password.php, I am not sure how to hook into it and make it just save the supplied value.

Also, looking at /wire/core/User.php, I don't see how this is connected to the Password class or vice versa.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hey gebeer, I'm trying to extend your function for admin only, by adding a button to the users screen: /processwire/access/users/

Do you know where exactly I would create my hook point?
I'm a little stumped, while adding hooks to ProcessPageEdit are relativley easy, I'm yet to see an example for the users section of processwire.

Link to comment
Share on other sites

I was unable to hook to this page, so ended up creating a custom admin page to support a button to export users via CSV.
Seems overkill, and I'm sure there are other senarios which may warrant additional buttons such as: Selecting all users for another operation (copy to clipboard) or email all users etc.
It would be nice to find out the appropriate method to hook to ;)
 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By Clarity
      Hello everyone!
      I'm new here and I want to set an user avatar to my profile. However, I don't see any option in my personal cabinet that can do it. Could you please tell me if there are there some requirements for user for setting an avatar or I'm missing something?
    • By AndZyk
      Hello,
      we have many projects as pages containing images inside regular image fields and repeater matrix elements. Now we would like to organize our assets.
      ProcessWire saves assets with id as folder name and makes separate folders for repeater matrix elements.
      Is there a way to collect all assets of one page and export them in a folder with the page name/title?
      I think I could achieve this by using the command line wget for this website or maybe by a hook. But maybe someone has done this before. 😉
      Regards, Andreas
    • By theoretic
      Hi there! And thanks for Processwire!
      I've got an interesting case concerning access to current user page. It appears that PW somehow limits access to the frontend page of current user.
      I'm speaking about a specific PW configuration. We have two kind of users: 'regular' users with native user template and member users with specific member template and specific members parent page (by the way, it's so cool that PW allows to use custom user templates and custom parent for certain user pages!). So a member with name Joe has a page with member template and url like /members/joe .
      The members template has some access limitations: only member users can see pages with member template. It works like a charm in most situations. For example, user Bill (who has member template and is logged in) can browse a page with url /members/ann which also is a member page with member template.
      And now, meet the glitch! The above-mentioned Bill cannot get to his own page /members/bill ! PW generates 404 page instead.
      I see no reason for this behavior. From my point of view any member should have access to any member page in this situation. What am i doing wrong? Any advice is welcome!
    • By Vineet Sawant
      Hi,
      I'm trying to import some heavy data into Processwire, but I'm not sure what would be the best way to do it.
      Usually I use CSV to Pages plugin, but this time the data is too heavy(~40k rows with 10+ columns of excel sheet), thus this plugin can't help.
      I also tried Tasker plugin but I can't seem to go through the setup itself, it requires some template setup but I'm totally clueless about how to do it, so that plugin is not of any use either.
      I wanted to know from you guys how you do it and in future what would be the best way to migrate thousands of rows of data in to PW.
       
      Thanks.
       
       
    • By hellerdruck
      Hi all
      I need to export all the texts from a website to a translation company (as json or csv or txt...). How can this be done? Of course manually, but this website is huge and it would take me years...
      Also, as a second step, importing the translation ...
      Any ideas anyone? Tutorials? Plugins?
      Thanks for your help.
×
×
  • Create New...