Skip to content

Instantly share code, notes, and snippets.

@johndel
Created July 20, 2013 18:31
Show Gist options
  • Save johndel/6046002 to your computer and use it in GitHub Desktop.
Save johndel/6046002 to your computer and use it in GitHub Desktop.
Multiple providers, one solution, generate password randomly.
def self.from_omniauth(auth)
unless provider = Provider.where(auth.slice(:provider, :uid)).first # New User
provider = Provider.new(provider: auth.provider, uid: auth.uid, oauth_token: auth.credentials.token)
user = User.where(email: auth.info.email).first # If user is already a devise user
if user.nil? # New user
random_password = (0...8).map{(65+rand(26)).chr}.join
user = User.create(email: auth.info.email, password: random_password, password_confirmation: random_password, confirmed_at: Time.now)
end
provider.user = user
end
provider.save
provider
#provider.user.save!
#provider.user.name = auth.info.name
#provider.user.avatar = auth.info.image.gsub("type=square", "width=160&height=160")
# end
end
def password_required?
return true if reset_password_token.present? && reset_password_period_valid?
unless encrypted_password.blank?
password.present? || password_confirmation.present?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment