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
This commit is contained in:
Gerhard Schlager 2015-08-20 22:15:57 +02:00
parent 676416f478
commit 8c03dd16af
6 changed files with 15 additions and 2 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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]),

View file

@ -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

View file

@ -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']