Module: EffectiveDeviseUser
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_devise_user.rb
Overview
EffectiveDeviseUsr
Mark your user model with devise_for then effective_devise_user
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary collapse
- #active_for_authentication? ⇒ Boolean
-
#allow_sign_up_from_invitation? ⇒ Boolean
This allows the Sign Up form to work for existing users with a pending invitation It assigns the attributes from the sign_up_params, saves the user, accepts the invitation Note that this action skips the invitation_token validation and is therefore insecure.
- #alternate_email=(value) ⇒ Object
-
#block_from_invitation? ⇒ Boolean
Allow users to sign in even if they have a pending invitation.
-
#destroyable? ⇒ Boolean
You cannot delete a user if they have any memberships, applicants, orders, or event registrations.
-
#email_to_s ⇒ Object
The user's to_s when in an email.
- #full_name ⇒ Object
- #inactive_message ⇒ Object
-
#invite!(invited_by = nil, options = {}) ⇒ Object
Devise invitable ignores model validations, so we manually check for duplicate email addresses.
- #reinvite! ⇒ Object
-
#send_devise_notification(notification, *args) ⇒ Object
Send devise & devise_invitable emails via active job.
- #to_select2 ⇒ Object
- #to_select2_search_columns ⇒ Object
-
#valid_password?(password) ⇒ Boolean
Any password will work in development mode.
Instance Method Details
#active_for_authentication? ⇒ Boolean
259 260 261 |
# File 'app/models/concerns/effective_devise_user.rb', line 259 def active_for_authentication? super && (respond_to?(:archived?) ? !archived? : true) end |
#allow_sign_up_from_invitation? ⇒ Boolean
This allows the Sign Up form to work for existing users with a pending invitation It assigns the attributes from the sign_up_params, saves the user, accepts the invitation Note that this action skips the invitation_token validation and is therefore insecure.
271 272 273 |
# File 'app/models/concerns/effective_devise_user.rb', line 271 def allow_sign_up_from_invitation? true end |
#alternate_email=(value) ⇒ Object
227 228 229 |
# File 'app/models/concerns/effective_devise_user.rb', line 227 def alternate_email=(value) super(value.to_s.strip.downcase.presence) end |
#block_from_invitation? ⇒ Boolean
Allow users to sign in even if they have a pending invitation
264 265 266 |
# File 'app/models/concerns/effective_devise_user.rb', line 264 def block_from_invitation? false end |
#destroyable? ⇒ Boolean
You cannot delete a user if they have any memberships, applicants, orders, or event registrations
305 306 307 308 309 310 311 312 |
# File 'app/models/concerns/effective_devise_user.rb', line 305 def destroyable? return false if respond_to?(:archived?) && !archived? return false if self.class.respond_to?(:effective_memberships_owner?) && (membership.present? || membership_histories.present?) return false if self.class.respond_to?(:effective_memberships_user?) && (applicants.present? || fee_payments.present?) return false if Effective::Order.where(user: self).present? return false if Effective::EventRegistrant.where(owner: self).or(Effective::EventRegistrant.where(user: self)).present? true end |
#email_to_s ⇒ Object
The user's to_s when in an email
219 220 221 |
# File 'app/models/concerns/effective_devise_user.rb', line 219 def email_to_s to_s end |
#full_name ⇒ Object
223 224 225 |
# File 'app/models/concerns/effective_devise_user.rb', line 223 def full_name [first_name.presence, last_name.presence].compact.join(' ') end |
#inactive_message ⇒ Object
275 276 277 |
# File 'app/models/concerns/effective_devise_user.rb', line 275 def (respond_to?(:archived?) && archived?) ? :archived : super end |
#invite!(invited_by = nil, options = {}) ⇒ Object
Devise invitable ignores model validations, so we manually check for duplicate email addresses.
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'app/models/concerns/effective_devise_user.rb', line 232 def invite!(invited_by = nil, = {}) if new_record? value = email.to_s.strip.downcase if value.blank? errors.add(:email, "can't be blank") return false end if self.class.where(email: value).present? errors.add(:email, 'has already been taken') return false end if respond_to?(:alternate_email) && self.class.where(alternate_email: value).present? errors.add(:email, 'has already been taken') return false end end super end |
#reinvite! ⇒ Object
255 256 257 |
# File 'app/models/concerns/effective_devise_user.rb', line 255 def reinvite! invite! end |
#send_devise_notification(notification, *args) ⇒ Object
Send devise & devise_invitable emails via active job
285 286 287 288 289 290 291 292 293 294 |
# File 'app/models/concerns/effective_devise_user.rb', line 285 def send_devise_notification(notification, *args) raise('expected args Hash') unless args.respond_to?(:last) && args.last.kind_of?(Hash) if defined?(Tenant) tenant = Tenant.current || raise('expected a current tenant') args.last[:tenant] ||= tenant end devise_mailer.send(notification, self, *args).deliver_now end |
#to_select2 ⇒ Object
300 301 302 |
# File 'app/models/concerns/effective_devise_user.rb', line 300 def to_select2 "<span>#{email_to_s}</span> <small><#{try(:public_email).presence || email}></small>" end |
#to_select2_search_columns ⇒ Object
296 297 298 |
# File 'app/models/concerns/effective_devise_user.rb', line 296 def to_select2_search_columns [:email, :public_email, :alternate_email, :first_name, :last_name, :name] end |
#valid_password?(password) ⇒ Boolean
Any password will work in development mode
280 281 282 |
# File 'app/models/concerns/effective_devise_user.rb', line 280 def valid_password?(password) Rails.env.development? || super end |