Class: User
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- User
show all
- Includes:
- ConfigManager
- Defined in:
- app/models/user.rb
Overview
Publify user. TODO: Should belong to a blog
Constant Summary
collapse
- ADMIN =
"admin"
- PUBLISHER =
"publisher"
- CONTRIBUTOR =
"contributor"
- STATUS =
%w(active inactive).freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
append_features, #canonicalize
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
36
37
38
|
# File 'app/models/user.rb', line 36
def filename
@filename
end
|
Class Method Details
.salt ⇒ Object
59
60
61
|
# File 'app/models/user.rb', line 59
def self.salt
"20ac4d290c2293702c64b3b287ae5ea79b26a5c1"
end
|
.to_prefix ⇒ Object
100
101
102
|
# File 'app/models/user.rb', line 100
def self.to_prefix
"author"
end
|
Instance Method Details
#active_for_authentication? ⇒ Boolean
92
93
94
|
# File 'app/models/user.rb', line 92
def active_for_authentication?
super && state == "active"
end
|
#admin? ⇒ Boolean
122
123
124
|
# File 'app/models/user.rb', line 122
def admin?
profile == User::ADMIN
end
|
#article_counter ⇒ Object
104
105
106
|
# File 'app/models/user.rb', line 104
def article_counter
articles.size
end
|
#devise_valid_password? ⇒ Object
Authenticate users with old password hashes
75
|
# File 'app/models/user.rb', line 75
alias devise_valid_password? valid_password?
|
#display_name ⇒ Object
108
109
110
111
112
113
114
115
116
|
# File 'app/models/user.rb', line 108
def display_name
if nickname.present?
nickname
elsif name.present?
name
else
login
end
end
|
#display_names ⇒ Object
69
70
71
72
|
# File 'app/models/user.rb', line 69
def display_names
[:login, :nickname, :firstname, :lastname, :first_and_last_name].
map { |f| send(f) }.delete_if(&:empty?)
end
|
#first_and_last_name ⇒ Object
63
64
65
66
67
|
# File 'app/models/user.rb', line 63
def first_and_last_name
return "" unless firstname.present? && lastname.present?
"#{firstname} #{lastname}"
end
|
133
134
135
|
# File 'app/models/user.rb', line 133
def
.present? && .present?
end
|
#permalink ⇒ Object
118
119
120
|
# File 'app/models/user.rb', line 118
def permalink
login
end
|
#text_filter ⇒ Object
96
97
98
|
# File 'app/models/user.rb', line 96
def text_filter
TextFilter.make_filter(text_filter_name)
end
|
126
127
128
129
130
131
|
# File 'app/models/user.rb', line 126
def (img)
return if == img
self. = img
save
end
|
#valid_password?(password) ⇒ Boolean
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/models/user.rb', line 77
def valid_password?(password)
devise_valid_password?(password)
rescue BCrypt::Errors::InvalidHash
digest = Digest::SHA1.hexdigest("#{self.class.salt}--#{password}--")
if digest == encrypted_password
self.encrypted_password = password_digest(password)
save
true
else
false
end
end
|