daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Oct 2nd, 2017 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top