Class: User

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
lib/generators/rockstart/authorization/devise/templates/models/user.rb

Overview

User model used to represent registered User

Instance Method Summary collapse

Instance Method Details

#active_for_authentication?Boolean

devise

ensure user account is active

Returns:

  • (Boolean)


35
36
37
# File 'lib/generators/rockstart/authorization/devise/templates/models/user.rb', line 35

def active_for_authentication?
  super && !deleted_at?
end

#first_nameObject

Short display name for user



16
17
18
# File 'lib/generators/rockstart/authorization/devise/templates/models/user.rb', line 16

def first_name
  namae.given
end

#imageObject

Display image for user



21
22
23
24
25
26
27
# File 'lib/generators/rockstart/authorization/devise/templates/models/user.rb', line 21

def image
  return unless email?

  require "digest/md5"
  hash = Digest::MD5.hexdigest(email.downcase)
  "https://s.gravatar.com/avatar/#{hash}?s=480"
end

#inactive_messageObject

devise

provide a custom message for a soft-deleted account



40
41
42
# File 'lib/generators/rockstart/authorization/devise/templates/models/user.rb', line 40

def inactive_message
  !deleted_at? ? super : :deleted_account
end

#soft_deleteObject

instead of deleting users, mark them as soft deleted



30
31
32
# File 'lib/generators/rockstart/authorization/devise/templates/models/user.rb', line 30

def soft_delete
  update_attribute(:deleted_at, Time.current)
end

#to_sObject



44
45
46
47
# File 'lib/generators/rockstart/authorization/devise/templates/models/user.rb', line 44

def to_s
  # Use the stored name value for labels
  (name_changed? ? name_was : name) || super
end