frumbert / wp2moodle--wordpress-

Wordpress to Moodle pass through authentication plugin (wordpress end)
27 stars 23 forks source link

syncing user accounts #25

Closed jmj5g closed 6 years ago

jmj5g commented 8 years ago

Tim,

We have 300+ existing users in a Moodle system, using local authentication in the Moodle db. We now plan to add WP2Moodle to streamline the process for new paid course enrollments. However we have many returning customers, so if I understand how your plugins work, we need to create WP accounts for all our existing Moodle users. That appears to be outside the scope of your plugins, but correct me if I'm wrong.

Edwiser makes a plugin that appears to sync user accounts between Moodle & WP: https://edwiser.org/bridge/extensions/single-sign-on/

Do you know if there is any compatibility problems between your plugins and the Edwiser plugin?

Or can you recommend any other solutions?

Thanks! John

actXc commented 8 years ago

I can't tell anything about edwiser, but using wp2moodle does not change anything in the live of your existing moodle users. They use moodle like they did before. They don't even recognize, that you sell courses some where. If they recognize it, and buy a course, and use the same user name, you should test the effect - I guess they get the course additionally enroled. If they use another user name to register, they get a second account.

jmj5g commented 8 years ago

Yes, I figured that was the case. But in our situation it is essential that we avoid duplicate accounts, for we need to keep a transcript of all courses that any individual completes.

We have many returning customers who register for new courses. We need to make sure their accounts are synced between WooCommerce and Moodle as a result.

Any suggestions are appreciated.

actXc commented 8 years ago

To sync the courses, I found this: mdwpmerchant.com.au, talk to him and ask for user sync.

frumbert commented 8 years ago

wp2moodle writes the id of the wordpress user into the moodle user record and tries to match accounts on that value. so it's entirely possible that if you have multiple sources of users that some of them might be the same. If the id matches an existing account (and update is enabled) then fields for the account might be updated, otherwise the record is left alone.

I've seen edwiser and think it's pretty reasonable for what it does - wp2moodle came about back before the moodle web services were a reliable thing. mdwpmerchant seems to be a similar thing (commercial though). My own WooCommerce stuff is just an afterthought to the plugin, not a primary feature, so you may be better served with these other plugins.

jmj5g commented 8 years ago

FYI, I've dug into this more deeply, and I have not found any way to sync existing Moodle user accounts into WP, and I've come to the conclusion that the technology involved prohibits it. There is no way to decrypt the passwords stored in the Moodle db (this is intentional) so it is not possible to create other accounts on any other system that are in sync with Moodle accounts.

Edwiser uses single sign on methods. It authenticates in WordPress, and then the user is given access to the linked Moodle account by SSO. That still leaves my 300+ user accounts in Moodle as orphans.

It is possible for WP or Moodle to authenticate against an external database. I could set it up so that WP authenticates agains the Moodle users, which effectively gives the desired sync. But, then you cannot create any new accounts in WordPress. For details see: https://wordpress.org/plugins/external-db-auth-reloaded/ Or, I could have Moodle authenticate agains the WP user database. But then I would have to reset all passwords for 300+ users (since WP & Moodle use different encryptions methods for passwords), which would not make anybody happy.

Edwiser & mdwpmerchant are limited to a single currency, which rules them out for my client's application.

sufyankhan commented 6 years ago

@jmj5g did you ever find a solution for it?

jmj5g commented 6 years ago

I did work my way through this, but it has been too long, and too many other installations since then for me to remember all the details of what I did. I do know that I determined that there is no way to transfer passwords between systems. The encryption used in the db cannot be reversed. So if you have users in two systems, you have to authenticate against two databases, which Moodle supports. You can have authentication agains the internal Moodle db and also an external db.

Sorry I cannot give you any more specifics now. Just too long ago...

sufyankhan commented 6 years ago

I am actually able to do just that without much hassle, just posting it here for other people benefit.

  1. install this plugin on wordpress: https://wordpress.org/plugins/import-users-from-csv-with-meta/
  2. Temporarily edit wp-includes/user.php line and replace this:

$user_pass = wp_hash_password( $userdata[‘user_pass’] ); with

$user_pass = $userdata[‘user_pass’];

try searching in the file, I am not giving the line number because in different wordpress version it could be different.

  1. Export users with hashed passwords via phpmyadmin in csv form and import in the wordpress, boom!
  2. edit back teh user.php file

Since wordpress and moodle both use md5 encryption at this point so it will work for now, if any of these systems use some other encryption method in future, this workaround will no longer work. Thanks.

fesaner commented 6 years ago

I've been told by WP All Import that their plugin has a checkbox you can use to import a hashed password. See screenshot https://d.pr/i/uyx23V If you export all users from Moodle, the resulting file will contain the hashed Moodle password. As mentioned by sufyankhan, Moodle and WordPress us the same hashing algorithm.