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
58 59 60 61 62 63 64 65 66 |
# File 'app/models/user.rb', line 58 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
68 69 70 |
# File 'app/models/user.rb', line 68 def self.non_admins User.where.not(role: :admin).where.not(role: :admin_limited_access) end |
.without_questionnaire ⇒ Object
72 73 74 |
# File 'app/models/user.rb', line 72 def self.without_questionnaire non_admins.left_outer_joins(:questionnaire).where(questionnaires: { id: nil }) end |
Instance Method Details
#active_for_authentication? ⇒ Boolean
25 26 27 |
# File 'app/models/user.rb', line 25 def active_for_authentication? true end |
#email=(value) ⇒ Object
39 40 41 |
# File 'app/models/user.rb', line 39 def email=(value) super value.try(:downcase) end |
#first_name ⇒ Object
43 44 45 46 |
# File 'app/models/user.rb', line 43 def first_name return "" if questionnaire.blank? questionnaire.first_name end |
#full_name ⇒ Object
53 54 55 56 |
# File 'app/models/user.rb', line 53 def full_name return "" if questionnaire.blank? questionnaire.full_name end |
#last_name ⇒ Object
48 49 50 51 |
# File 'app/models/user.rb', line 48 def last_name return "" if questionnaire.blank? questionnaire.last_name end |
#queue_reminder_email ⇒ Object
33 34 35 36 37 |
# File 'app/models/user.rb', line 33 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
29 30 31 |
# File 'app/models/user.rb', line 29 def send_devise_notification(notification, *args) devise_mailer.send(notification, self, *args).deliver_later end |
#set_default_role ⇒ Object
21 22 23 |
# File 'app/models/user.rb', line 21 def set_default_role self.role ||= :user end |