Class: User

Inherits:
ActiveRecord::Base
  • 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.



4
5
6
# File 'app/models/user.rb', line 4

def confirm_password
  @confirm_password
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'app/models/user.rb', line 4

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
# 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)


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

def can_login?
  activated?
end

#mark_active!Object



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

def mark_active!
  return if  &&  > 10.minutes.ago
  update(last_login_at: Time.now.utc)
end

#name_and_emailObject



79
80
81
# File 'app/models/user.rb', line 79

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

#online?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/user.rb', line 83

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

#realnameObject



87
88
89
# File 'app/models/user.rb', line 87

def realname
  name
end