FIX: Importer not handling usernames correctly

This commit is contained in:
Kane York 2015-09-21 16:27:47 -07:00
parent b6155889d5
commit 200ee15991
1 changed files with 13 additions and 9 deletions

View File

@ -258,9 +258,8 @@ class ImportScripts::Base
if opts[:username].blank? || if opts[:username].blank? ||
opts[:username].length < User.username_length.begin || opts[:username].length < User.username_length.begin ||
opts[:username].length > User.username_length.end || opts[:username].length > User.username_length.end ||
opts[:username] =~ /[^A-Za-z0-9_]/ || !User.username_available?(opts[:username]) ||
opts[:username][0] =~ /[^A-Za-z0-9]/ || !UsernameValidator.new(opts[:username]).valid_format?
!User.username_available?(opts[:username])
opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name] || opts[:email]) opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name] || opts[:email])
end end
opts[:email] = opts[:email].downcase opts[:email] = opts[:email].downcase
@ -289,14 +288,19 @@ class ImportScripts::Base
if opts[:active] && opts[:password].present? if opts[:active] && opts[:password].present?
u.activate u.activate
end end
rescue rescue => e
# try based on email # try based on email
if e.record.errors.messages[:email].present?
existing = User.find_by(email: opts[:email].downcase) existing = User.find_by(email: opts[:email].downcase)
if existing if existing
existing.custom_fields["import_id"] = import_id existing.custom_fields["import_id"] = import_id
existing.save! existing.save!
u = existing u = existing
end end
else
puts "Error on record: #{opts}"
raise e
end
end end
post_create_action.try(:call, u) if u.persisted? post_create_action.try(:call, u) if u.persisted?