Class: User
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- User
- Defined in:
- app/models/user.rb
Class Method Summary collapse
Instance Method Summary collapse
- #active_for_authentication? ⇒ Boolean
- #email=(value) ⇒ Object
- #first_name ⇒ Object
- #full_name ⇒ Object
- #last_name ⇒ Object
- #queue_reminder_email ⇒ Object
- #send_devise_notification(notification, *args) ⇒ Object
- #set_default_role ⇒ Object
Class Method Details
.from_omniauth(auth) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'app/models/user.rb', line 56 def self.from_omniauth(auth) matching_provider = where(provider: auth.provider, uid: auth.uid) matching_email = where(email: auth.info.email) matching_provider.or(matching_email).first_or_create do |user| user.uid = auth.uid user.email = auth.info.email user.password = Devise.friendly_token[0, 20] end end |
.non_admins ⇒ Object
66 67 68 |
# File 'app/models/user.rb', line 66 def self.non_admins User.where.not(role: :admin).where.not(role: :admin_limited_access) end |
.without_questionnaire ⇒ Object
70 71 72 |
# File 'app/models/user.rb', line 70 def self.without_questionnaire non_admins.left_outer_joins(:questionnaire).where(questionnaires: { id: nil }) end |
Instance Method Details
#active_for_authentication? ⇒ Boolean
23 24 25 |
# File 'app/models/user.rb', line 23 def active_for_authentication? true end |
#email=(value) ⇒ Object
37 38 39 |
# File 'app/models/user.rb', line 37 def email=(value) super value.try(:downcase) end |
#first_name ⇒ Object
41 42 43 44 |
# File 'app/models/user.rb', line 41 def first_name return "" if questionnaire.blank? questionnaire.first_name end |
#full_name ⇒ Object
51 52 53 54 |
# File 'app/models/user.rb', line 51 def full_name return "" if questionnaire.blank? questionnaire.full_name end |
#last_name ⇒ Object
46 47 48 49 |
# File 'app/models/user.rb', line 46 def last_name return "" if questionnaire.blank? questionnaire.last_name end |
#queue_reminder_email ⇒ Object
31 32 33 34 35 |
# File 'app/models/user.rb', line 31 def queue_reminder_email return if reminder_sent_at Mailer.delay_for(1.day).incomplete_reminder_email(id) update_attribute(:reminder_sent_at, Time.now) end |
#send_devise_notification(notification, *args) ⇒ Object
27 28 29 |
# File 'app/models/user.rb', line 27 def send_devise_notification(notification, *args) devise_mailer.send(notification, self, *args).deliver_later end |
#set_default_role ⇒ Object
19 20 21 |
# File 'app/models/user.rb', line 19 def set_default_role self.role ||= :user end |