Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. User.all.no_timeout.each_with_index do |user, i|
  2. next if user.authorizations.any? { |auth| %w[auth0 google-oauth2].include?(auth.provider) }
  3.  
  4. puts "Processed #{(i + 1)} User records" if ((i + 1) % 100).zero?
  5.  
  6. # Create in Auth0 via API
  7. begin
  8. record = Apptentive::Application.auth0.create_user(user, password: SecureRandom.hex + %w[! @ # $ % ^ & *].sample)
  9. provider, uid = record["user_id"].split("|")
  10.  
  11. # add an Authorization with the provider/id data
  12. user.authorizations.find_or_initialize_by(provider: provider, uid: uid)
  13. user.save!
  14. rescue => ex
  15. Rails.logger.info("Failed to create either Auth0 account or Authorization record for user: #{user.id}, auth0_id: #{record.try!(:[], 'user_id')} \n #{ex}")
  16. end
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement