FIX: Importer not handling usernames correctly
This commit is contained in:
parent
b6155889d5
commit
200ee15991
|
@ -258,9 +258,8 @@ class ImportScripts::Base
|
|||
if opts[:username].blank? ||
|
||||
opts[:username].length < User.username_length.begin ||
|
||||
opts[:username].length > User.username_length.end ||
|
||||
opts[:username] =~ /[^A-Za-z0-9_]/ ||
|
||||
opts[:username][0] =~ /[^A-Za-z0-9]/ ||
|
||||
!User.username_available?(opts[:username])
|
||||
!User.username_available?(opts[:username]) ||
|
||||
!UsernameValidator.new(opts[:username]).valid_format?
|
||||
opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name] || opts[:email])
|
||||
end
|
||||
opts[:email] = opts[:email].downcase
|
||||
|
@ -289,13 +288,18 @@ class ImportScripts::Base
|
|||
if opts[:active] && opts[:password].present?
|
||||
u.activate
|
||||
end
|
||||
rescue
|
||||
rescue => e
|
||||
# try based on email
|
||||
existing = User.find_by(email: opts[:email].downcase)
|
||||
if existing
|
||||
existing.custom_fields["import_id"] = import_id
|
||||
existing.save!
|
||||
u = existing
|
||||
if e.record.errors.messages[:email].present?
|
||||
existing = User.find_by(email: opts[:email].downcase)
|
||||
if existing
|
||||
existing.custom_fields["import_id"] = import_id
|
||||
existing.save!
|
||||
u = existing
|
||||
end
|
||||
else
|
||||
puts "Error on record: #{opts}"
|
||||
raise e
|
||||
end
|
||||
end
|
||||
post_create_action.try(:call, u) if u.persisted?
|
||||
|
|
Loading…
Reference in New Issue