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.
-
#email_to_s ⇒ Object
The user’s to_s when in an email.
- #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
257 258 259 |
# File 'app/models/concerns/effective_devise_user.rb', line 257 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.
269 270 271 |
# File 'app/models/concerns/effective_devise_user.rb', line 269 def allow_sign_up_from_invitation? true end |
#alternate_email=(value) ⇒ Object
225 226 227 |
# File 'app/models/concerns/effective_devise_user.rb', line 225 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
262 263 264 |
# File 'app/models/concerns/effective_devise_user.rb', line 262 def block_from_invitation? false end |
#email_to_s ⇒ Object
The user’s to_s when in an email
221 222 223 |
# File 'app/models/concerns/effective_devise_user.rb', line 221 def email_to_s to_s end |
#inactive_message ⇒ Object
273 274 275 |
# File 'app/models/concerns/effective_devise_user.rb', line 273 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.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'app/models/concerns/effective_devise_user.rb', line 230 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
253 254 255 |
# File 'app/models/concerns/effective_devise_user.rb', line 253 def reinvite! invite! end |
#send_devise_notification(notification, *args) ⇒ Object
Send devise & devise_invitable emails via active job
283 284 285 286 287 288 289 290 291 292 |
# File 'app/models/concerns/effective_devise_user.rb', line 283 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
298 299 300 |
# File 'app/models/concerns/effective_devise_user.rb', line 298 def to_select2 "<span>#{email_to_s}</span> <small><#{try(:public_email) || email}></small>" end |
#to_select2_search_columns ⇒ Object
294 295 296 |
# File 'app/models/concerns/effective_devise_user.rb', line 294 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
278 279 280 |
# File 'app/models/concerns/effective_devise_user.rb', line 278 def valid_password?(password) Rails.env.development? || super end |