Module: Google
- Defined in:
- lib/TheresNoBox/google.rb
Defined Under Namespace
Modules: OAuth, OpenId, Profile, Recaptcha
Class Method Summary collapse
Class Method Details
.login(code) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/TheresNoBox/google.rb', line 2 def self.login(code) token = Google::OAuth.get_token(code) profile = Google::Profile.getProfile(token) user = User.where(:provider=> 'Google', :email=> profile['email']).first #User not currently in database... if user.nil? #Adding user as user. user = User.new user.email = profile['email'] user.provider = 'Google' user.uid = profile['id'] user.name = profile['name'] user.imageUrl = profile['picture'] user.sites = {mySite => 'user'} user.editable = true user.save end #Found User, but name is nil / null if user.name.nil? user.email = profile['email'] user.provider = 'Google' user.uid = profile['id'] user.name = profile['name'] user.imageUrl = profile['picture'] user.save end return user end |