Class: User

Inherits:
ApplicationRecord
  • Object
show all
Includes:
PagesCore::HasRoles
Defined in:
app/models/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PagesCore::HasRoles

#role?, #role_names, #role_names=

Instance Attribute Details

#confirm_passwordObject

Returns the value of attribute confirm_password.



6
7
8
# File 'app/models/user.rb', line 6

def confirm_password
  @confirm_password
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'app/models/user.rb', line 6

def password
  @password
end

Class Method Details

.authenticate(email, password:) ⇒ Object



49
50
51
52
# File 'app/models/user.rb', line 49

def authenticate(email, password:)
  user = User.(email)
  user if user.try { |u| u.authenticate!(password) }
end

.find_by_email(str) ⇒ Object



54
55
56
# File 'app/models/user.rb', line 54

def find_by_email(str)
  find_by("LOWER(email) = ?", str.to_s.downcase)
end

.login_name(string) ⇒ Object

Finds a user by either username or email address.



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

def (string)
  find_by(username: string.to_s) || find_by_email(string)
end

Instance Method Details

#authenticate!(password) ⇒ Object



64
65
66
67
68
69
# File 'app/models/user.rb', line 64

def authenticate!(password)
  return false unless can_login? && valid_password?(password)

  rehash_password!(password) if password_needs_rehash?
  true
end

#can_login?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/user.rb', line 71

def can_login?
  activated?
end

#mark_active!Object



75
76
77
78
79
# File 'app/models/user.rb', line 75

def mark_active!
  return if  &&  > 10.minutes.ago

  update(last_login_at: Time.now.utc)
end

#name_and_emailObject



81
82
83
# File 'app/models/user.rb', line 81

def name_and_email
  "#{name} <#{email}>"
end

#online?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/user.rb', line 85

def online?
   &&  > 15.minutes.ago ? true : false
end

#realnameObject



89
90
91
# File 'app/models/user.rb', line 89

def realname
  name
end