Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#remember_meObject

Returns the value of attribute remember_me


12
13
14
# File 'app/models/user.rb', line 12

def remember_me
  @remember_me
end

Instance Method Details

#formal_nameObject


29
30
31
# File 'app/models/user.rb', line 29

def formal_name
  "#{last_name}, #{first_name}".strip
end

#friendly_nameObject


33
34
35
# File 'app/models/user.rb', line 33

def friendly_name
  other_name.present? ? other_name : first_name
end

#generate_token(column) ⇒ Object


62
63
64
65
66
# File 'app/models/user.rb', line 62

def generate_token(column)
  begin
    self[column] = SecureRandom.urlsafe_base64(40)
  end while User.exists?(column => self[column])
end

#has_a_password?Boolean

def send_password_reset

generate_token(:password_reset_token)
self.password_reset_sent_at = Time.zone.now
save!
UserMailer.password_reset(self).deliver

end

Returns:

  • (Boolean)

58
59
60
# File 'app/models/user.rb', line 58

def has_a_password?
  password_digest
end

#nameObject


25
26
27
# File 'app/models/user.rb', line 25

def name
  "#{first_name} #{last_name}".strip
end

#spiritual_nameObject


37
38
39
40
41
42
43
44
45
# File 'app/models/user.rb', line 37

def spiritual_name
  if other_name.present?
    other_name
  elsif name.present?
    name
  else
    'anonymous'
  end
end

#to_paramObject

use the stringex gem to create slug | usually on the title or name attribute


21
22
23
# File 'app/models/user.rb', line 21

def to_param
  "#{id}-#{name.to_url}"
end

#visible_name_present?Boolean

used in tkh_authentication to determin whether to show name fields in login form

Returns:

  • (Boolean)

47
48
49
# File 'app/models/user.rb', line 47

def visible_name_present? # used in tkh_authentication to determin whether to show name fields in login form
  name.present? || other_name.present?
end