From 8c03dd16af73dd936a1b97aa5b6cfc689d21bc9b Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Thu, 20 Aug 2015 22:15:57 +0200 Subject: [PATCH] Adds support for importing password hashes used by "migratepassword" plugin Adds setting to phpBB3 importer for importing passwords (default: off) Plugin: https://github.com/discoursehosting/discourse-migratepassword --- script/import_scripts/base.rb | 5 +++++ script/import_scripts/phpbb3/database/database_3_0.rb | 2 +- script/import_scripts/phpbb3/database/database_3_1.rb | 2 +- script/import_scripts/phpbb3/importers/user_importer.rb | 1 + script/import_scripts/phpbb3/settings.yml | 5 +++++ script/import_scripts/phpbb3/support/settings.rb | 2 ++ 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/script/import_scripts/base.rb b/script/import_scripts/base.rb index b7326e946..0bc796c73 100644 --- a/script/import_scripts/base.rb +++ b/script/import_scripts/base.rb @@ -273,6 +273,7 @@ class ImportScripts::Base u.custom_fields["import_id"] = import_id u.custom_fields["import_username"] = opts[:username] if opts[:username].present? u.custom_fields["import_avatar_url"] = avatar_url if avatar_url.present? + u.custom_fields["import_pass"] = opts[:password] if opts[:password].present? begin User.transaction do @@ -284,6 +285,10 @@ class ImportScripts::Base u.user_profile.save! end end + + if opts[:active] && opts[:password].present? + u.activate + end rescue # try based on email existing = User.find_by(email: opts[:email].downcase) diff --git a/script/import_scripts/phpbb3/database/database_3_0.rb b/script/import_scripts/phpbb3/database/database_3_0.rb index 35c5b15e5..e06d8f7ba 100644 --- a/script/import_scripts/phpbb3/database/database_3_0.rb +++ b/script/import_scripts/phpbb3/database/database_3_0.rb @@ -14,7 +14,7 @@ module ImportScripts::PhpBB3 def fetch_users(offset) query(<<-SQL) - SELECT u.user_id, u.user_email, u.username, u.user_regdate, u.user_lastvisit, u.user_ip, + SELECT u.user_id, u.user_email, u.username, u.user_password, u.user_regdate, u.user_lastvisit, u.user_ip, u.user_type, u.user_inactive_reason, g.group_name, b.ban_start, b.ban_end, b.ban_reason, u.user_posts, u.user_website, u.user_from, u.user_birthday, u.user_avatar_type, u.user_avatar FROM #{@table_prefix}_users u diff --git a/script/import_scripts/phpbb3/database/database_3_1.rb b/script/import_scripts/phpbb3/database/database_3_1.rb index bf13546e2..f51f1b5a4 100644 --- a/script/import_scripts/phpbb3/database/database_3_1.rb +++ b/script/import_scripts/phpbb3/database/database_3_1.rb @@ -5,7 +5,7 @@ module ImportScripts::PhpBB3 class Database_3_1 < Database_3_0 def fetch_users(offset) query(<<-SQL) - SELECT u.user_id, u.user_email, u.username, u.user_regdate, u.user_lastvisit, u.user_ip, + SELECT u.user_id, u.user_email, u.username, u.user_password, u.user_regdate, u.user_lastvisit, u.user_ip, u.user_type, u.user_inactive_reason, g.group_name, b.ban_start, b.ban_end, b.ban_reason, u.user_posts, f.pf_phpbb_website AS user_website, f.pf_phpbb_location AS user_from, u.user_birthday, u.user_avatar_type, u.user_avatar diff --git a/script/import_scripts/phpbb3/importers/user_importer.rb b/script/import_scripts/phpbb3/importers/user_importer.rb index 0a9ba8c45..be0321d48 100644 --- a/script/import_scripts/phpbb3/importers/user_importer.rb +++ b/script/import_scripts/phpbb3/importers/user_importer.rb @@ -16,6 +16,7 @@ module ImportScripts::PhpBB3 id: row[:user_id], email: row[:user_email], username: row[:username], + password: @settings.import_passwords ? row[:user_password] : nil, name: @settings.username_as_name ? row[:username] : '', created_at: Time.zone.at(row[:user_regdate]), last_seen_at: row[:user_lastvisit] == 0 ? Time.zone.at(row[:user_regdate]) : Time.zone.at(row[:user_lastvisit]), diff --git a/script/import_scripts/phpbb3/settings.yml b/script/import_scripts/phpbb3/settings.yml index b591d3964..d7ee6174e 100644 --- a/script/import_scripts/phpbb3/settings.yml +++ b/script/import_scripts/phpbb3/settings.yml @@ -33,6 +33,11 @@ import: # When false: The system user will be used for all anonymous users. anonymous_users: true + # Enable this, if you want import password hashes in order to use the "migratepassword" plugin. + # This will allow users to login with their current password. + # The plugin is available at: https://github.com/discoursehosting/discourse-migratepassword + passwords: false + # By default all the following things get imported. You can disable them by setting them to false. bookmarks: true attachments: true diff --git a/script/import_scripts/phpbb3/support/settings.rb b/script/import_scripts/phpbb3/support/settings.rb index 8a0c36ee1..1c68c5f8b 100644 --- a/script/import_scripts/phpbb3/support/settings.rb +++ b/script/import_scripts/phpbb3/support/settings.rb @@ -12,6 +12,7 @@ module ImportScripts::PhpBB3 attr_reader :import_private_messages attr_reader :import_polls attr_reader :import_bookmarks + attr_reader :import_passwords attr_reader :import_uploaded_avatars attr_reader :import_remote_avatars @@ -36,6 +37,7 @@ module ImportScripts::PhpBB3 @import_private_messages = import_settings['private_messages'] @import_polls = import_settings['polls'] @import_bookmarks = import_settings['bookmarks'] + @import_passwords = import_settings['passwords'] avatar_settings = import_settings['avatars'] @import_uploaded_avatars = avatar_settings['uploaded']