Created
July 20, 2013 18:31
-
-
Save johndel/6046002 to your computer and use it in GitHub Desktop.
Multiple providers, one solution, generate password randomly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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