Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- app/models/user.rb
Class Method Summary collapse
Instance Method Summary collapse
- #admin? ⇒ Boolean
- #backed_projects ⇒ Object
- #backs_text ⇒ Object
- #credits ⇒ Object
- #decorator ⇒ Object
- #facebook_id ⇒ Object
- #fix_facebook_link ⇒ Object
- #fix_twitter_user ⇒ Object
-
#gravatar_url ⇒ Object
Returns a Gravatar URL associated with the email parameter, uses local avatar if available.
- #has_facebook_authentication? ⇒ Boolean
- #password_confirmation_required? ⇒ Boolean
- #password_required? ⇒ Boolean
- #project_unsubscribes ⇒ Object
- #to_param ⇒ Object
- #total_backed_projects ⇒ Object
- #total_backs ⇒ Object
-
#trustee? ⇒ Boolean
NOTE: Checking if the user has CHANNELS If the user has some channels, this method returns TRUE Otherwise, it’s FALSE.
- #twitter_link ⇒ Object
- #updates_subscription ⇒ Object
Class Method Details
.backer_totals ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/user.rb', line 121 def self.backer_totals connection.select_one( self.scoped. joins(:user_total). select(' count(DISTINCT user_id) as users, count(*) as backers, sum(user_totals.sum) as backed, sum(user_totals.credits) as credits'). to_sql ).reduce({}){|memo,el| memo.merge({ el[0].to_sym => BigDecimal.new(el[1] || '0') }) } end |
.create_with_omniauth(auth, current_user = nil) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'app/models/user.rb', line 172 def self.create_with_omniauth(auth, current_user = nil) omniauth_email = (auth["info"]["email"] rescue nil) omniauth_email = (auth["extra"]["user_hash"]["email"] rescue nil) unless omniauth_email if current_user u = current_user elsif omniauth_email && u = User.find_by_email(omniauth_email) else u = new do |user| user.name = auth["info"]["name"] user.email = omniauth_email user.nickname = auth["info"]["nickname"] user.bio = (auth["info"]["description"][0..139] rescue nil) user.locale = I18n.locale.to_s user.image_url = "https://graph.facebook.com/#{auth['uid']}/picture?type=large" if auth["provider"] == "facebook" end end provider = OauthProvider.where(name: auth['provider']).first u..build(uid: auth['uid'], oauth_provider_id: provider.id) if provider u.save! u end |
Instance Method Details
#admin? ⇒ Boolean
143 144 145 |
# File 'app/models/user.rb', line 143 def admin? admin end |
#backed_projects ⇒ Object
208 209 210 |
# File 'app/models/user.rb', line 208 def backed_projects Project.backed_by(self.id) end |
#backs_text ⇒ Object
212 213 214 215 216 217 218 219 220 |
# File 'app/models/user.rb', line 212 def backs_text if total_backed_projects == 2 I18n.t('user.backs_text.two') elsif total_backed_projects > 1 I18n.t('user.backs_text.many', total: (total_backed_projects-1)) else I18n.t('user.backs_text.one') end end |
#credits ⇒ Object
154 155 156 |
# File 'app/models/user.rb', line 154 def credits user_total ? user_total.credits : 0.0 end |
#decorator ⇒ Object
139 140 141 |
# File 'app/models/user.rb', line 139 def decorator @decorator ||= UserDecorator.new(self) end |
#facebook_id ⇒ Object
162 163 164 165 |
# File 'app/models/user.rb', line 162 def facebook_id auth = .joins(:oauth_provider).where("oauth_providers.name = 'facebook'").first auth.uid if auth end |
#fix_facebook_link ⇒ Object
230 231 232 233 234 |
# File 'app/models/user.rb', line 230 def fix_facebook_link if !self.facebook_link.blank? self.facebook_link = ('http://' + self.facebook_link) unless self.facebook_link[/^https?:\/\//] end end |
#fix_twitter_user ⇒ Object
226 227 228 |
# File 'app/models/user.rb', line 226 def fix_twitter_user self.twitter.gsub!(/@/, '') if self.twitter end |
#gravatar_url ⇒ Object
Returns a Gravatar URL associated with the email parameter, uses local avatar if available
237 238 239 240 |
# File 'app/models/user.rb', line 237 def gravatar_url return unless email "https://gravatar.com/avatar/#{Digest::MD5.new.update(email)}.jpg?default=#{::Configuration[:base_url]}/assets/user.png" end |
#has_facebook_authentication? ⇒ Boolean
134 135 136 137 |
# File 'app/models/user.rb', line 134 def has_facebook_authentication? oauth = OauthProvider.find_by_name 'facebook' .where(oauth_provider_id: oauth.id).present? if oauth end |
#password_confirmation_required? ⇒ Boolean
246 247 248 |
# File 'app/models/user.rb', line 246 def password_confirmation_required? !new_record? end |
#password_required? ⇒ Boolean
242 243 244 |
# File 'app/models/user.rb', line 242 def password_required? !persisted? || !password.nil? || !password_confirmation.nil? end |
#project_unsubscribes ⇒ Object
202 203 204 205 206 |
# File 'app/models/user.rb', line 202 def project_unsubscribes backed_projects.map do |p| unsubscribes.updates_unsubscribe(p.id) end end |
#to_param ⇒ Object
167 168 169 170 |
# File 'app/models/user.rb', line 167 def to_param return "#{self.id}" unless self.display_name "#{self.id}-#{self.display_name.parameterize}" end |
#total_backed_projects ⇒ Object
158 159 160 |
# File 'app/models/user.rb', line 158 def total_backed_projects user_total ? user_total.total_backed_projects : 0 end |
#total_backs ⇒ Object
194 195 196 |
# File 'app/models/user.rb', line 194 def total_backs backs.confirmed.not_anonymous.count end |
#trustee? ⇒ Boolean
NOTE: Checking if the user has CHANNELS If the user has some channels, this method returns TRUE Otherwise, it’s FALSE
150 151 152 |
# File 'app/models/user.rb', line 150 def trustee? !self.channels.size.zero? end |
#twitter_link ⇒ Object
222 223 224 |
# File 'app/models/user.rb', line 222 def twitter_link "http://twitter.com/#{self.twitter}" end |
#updates_subscription ⇒ Object
198 199 200 |
# File 'app/models/user.rb', line 198 def updates_subscription unsubscribes.updates_unsubscribe(nil) end |