Class: User
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#role?, #role_names, #role_names=
Instance Attribute Details
#confirm_password ⇒ Object
Returns the value of attribute confirm_password.
6
7
8
|
# File 'app/models/user.rb', line 6
def confirm_password
@confirm_password
end
|
#password ⇒ Object
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.login_name(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 login_name(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
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 last_login_at && last_login_at > 10.minutes.ago
update(last_login_at: Time.now.utc)
end
|
#name_and_email ⇒ Object
81
82
83
|
# File 'app/models/user.rb', line 81
def name_and_email
"#{name} <#{email}>"
end
|
#online? ⇒ Boolean
85
86
87
|
# File 'app/models/user.rb', line 85
def online?
last_login_at && last_login_at > 15.minutes.ago ? true : false
end
|
#realname ⇒ Object
89
90
91
|
# File 'app/models/user.rb', line 89
def realname
name
end
|