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
263 264 265 |
# File 'app/models/concerns/effective_devise_user.rb', line 263 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.
275 276 277 |
# File 'app/models/concerns/effective_devise_user.rb', line 275 def allow_sign_up_from_invitation? true end |
#alternate_email=(value) ⇒ Object
231 232 233 |
# File 'app/models/concerns/effective_devise_user.rb', line 231 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
268 269 270 |
# File 'app/models/concerns/effective_devise_user.rb', line 268 def block_from_invitation? false end |
#destroyable? ⇒ Boolean
You cannot delete a user if they have any memberships, applicants, orders, or event registrations
309 310 311 312 313 314 315 316 |
# File 'app/models/concerns/effective_devise_user.rb', line 309 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
223 224 225 |
# File 'app/models/concerns/effective_devise_user.rb', line 223 def email_to_s to_s end |
#full_name ⇒ Object
227 228 229 |
# File 'app/models/concerns/effective_devise_user.rb', line 227 def full_name [first_name.presence, last_name.presence].compact.join(' ') end |
#inactive_message ⇒ Object
279 280 281 |
# File 'app/models/concerns/effective_devise_user.rb', line 279 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.
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'app/models/concerns/effective_devise_user.rb', line 236 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
259 260 261 |
# File 'app/models/concerns/effective_devise_user.rb', line 259 def reinvite! invite! end |
#send_devise_notification(notification, *args) ⇒ Object
Send devise & devise_invitable emails via active job
289 290 291 292 293 294 295 296 297 298 |
# File 'app/models/concerns/effective_devise_user.rb', line 289 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
304 305 306 |
# File 'app/models/concerns/effective_devise_user.rb', line 304 def to_select2 "<span>#{email_to_s}</span> <small><#{try(:public_email) || email}></small>" end |
#to_select2_search_columns ⇒ Object
300 301 302 |
# File 'app/models/concerns/effective_devise_user.rb', line 300 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
284 285 286 |
# File 'app/models/concerns/effective_devise_user.rb', line 284 def valid_password?(password) Rails.env.development? || super end |