Module: MuckAuth::Models::MuckUser
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/muck-auth/models/user.rb
Instance Method Summary collapse
- #apply_omniauth(omniauth) ⇒ Object
- #feeds_from_omniauth(omniauth) ⇒ Object
- #password_required? ⇒ Boolean
- #profile_from_omniauth(omniauth) ⇒ Object
- #set_profile_from_authentications ⇒ Object
Instance Method Details
#apply_omniauth(omniauth) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/muck-auth/models/user.rb', line 15 def apply_omniauth(omniauth) self.email = omniauth['user_info']['email'] if self.email.blank? self.first_name = omniauth['user_info']['first_name'] if self.first_name.blank? self.last_name = omniauth['user_info']['last_name'] if self.last_name.blank? # In case first and last name weren't provided: names = User.parse_name(omniauth['user_info']['name']) self.first_name = names[0] if self.first_name.blank? self.last_name = names[1] if self.last_name.blank? self.login = omniauth['user_info']['nickname'] if self.login.blank? self.login = self.first_name.downcase if Float(self.login) rescue false # If the login is a number then try the first name # Some providers don't provide a valid nickname so try the first name self.login = self.first_name if !self.valid? && self.errors[:login].any? # Remove the email if it's invalid self.email = '' if self.errors[:email].any? self.authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'], :raw_auth => omniauth.to_json, :token => omniauth['credentials']['token'], :secret => omniauth['credentials']['secret'] ) end |
#feeds_from_omniauth(omniauth) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/muck-auth/models/user.rb', line 59 def feeds_from_omniauth(omniauth) uris = omniauth['user_info']['urls'] return unless uris && defined?(Service) uris.each_pair do |name, uri| feeds = Feed.make_feeds_or_website(uri, self, name) feeds.compact! if !feeds.blank? feeds.each do |feed| self.own_feeds << feed end end end end |
#password_required? ⇒ Boolean
73 74 75 |
# File 'lib/muck-auth/models/user.rb', line 73 def password_required? (authentications.empty? || !password.blank?) && super end |
#profile_from_omniauth(omniauth) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/muck-auth/models/user.rb', line 49 def profile_from_omniauth(omniauth) if self.respond_to?(:profile) self.build_profile if self.profile.blank? # in case profile doesn't yet exist self.profile.location = omniauth['user_info']['location'] if self.profile.location.blank? self.profile.about = omniauth['user_info']['description'] if self.profile.about.blank? self.profile.photo_url = omniauth['user_info']['image'] if self.profile.photo.original_filename.blank? self.profile.save end end |
#set_profile_from_authentications ⇒ Object
42 43 44 45 46 47 |
# File 'lib/muck-auth/models/user.rb', line 42 def set_profile_from_authentications return unless self.respond_to?(:profile) if authentication = self.authentications.by_newest.first self.profile_from_omniauth(JSON.parse(authentication.raw_auth)) end end |