Class: User
Overview
Publify user. TODO: Should belong to a blog
Constant Summary
collapse
- ADMIN =
"admin"
- PUBLISHER =
"publisher"
- CONTRIBUTOR =
"contributor"
- STATUS =
%w(active inactive).freeze
StringLengthLimit::STRING_LIMIT
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#canonicalize, included
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
38
39
40
|
# File 'app/models/user.rb', line 38
def filename
@filename
end
|
Class Method Details
.salt ⇒ Object
61
62
63
|
# File 'app/models/user.rb', line 61
def self.salt
"20ac4d290c2293702c64b3b287ae5ea79b26a5c1"
end
|
.to_prefix ⇒ Object
102
103
104
|
# File 'app/models/user.rb', line 102
def self.to_prefix
"author"
end
|
Instance Method Details
#active_for_authentication? ⇒ Boolean
94
95
96
|
# File 'app/models/user.rb', line 94
def active_for_authentication?
super && state == "active"
end
|
#admin? ⇒ Boolean
124
125
126
|
# File 'app/models/user.rb', line 124
def admin?
profile == User::ADMIN
end
|
#article_counter ⇒ Object
106
107
108
|
# File 'app/models/user.rb', line 106
def article_counter
articles.size
end
|
#devise_valid_password? ⇒ Object
Authenticate users with old password hashes
77
|
# File 'app/models/user.rb', line 77
alias devise_valid_password? valid_password?
|
#display_name ⇒ Object
110
111
112
113
114
115
116
117
118
|
# File 'app/models/user.rb', line 110
def display_name
if nickname.present?
nickname
elsif name.present?
name
else
login
end
end
|
#display_names ⇒ Object
71
72
73
74
|
# File 'app/models/user.rb', line 71
def display_names
[:login, :nickname, :firstname, :lastname, :first_and_last_name]
.map { |f| send(f) }.delete_if(&:empty?)
end
|
#first_and_last_name ⇒ Object
65
66
67
68
69
|
# File 'app/models/user.rb', line 65
def first_and_last_name
return "" unless firstname.present? && lastname.present?
"#{firstname} #{lastname}"
end
|
135
136
137
|
# File 'app/models/user.rb', line 135
def
.present? && .present?
end
|
#permalink ⇒ Object
120
121
122
|
# File 'app/models/user.rb', line 120
def permalink
login
end
|
#text_filter ⇒ Object
98
99
100
|
# File 'app/models/user.rb', line 98
def text_filter
TextFilter.make_filter(text_filter_name)
end
|
128
129
130
131
132
133
|
# File 'app/models/user.rb', line 128
def (img)
return if == img
self. = img
save
end
|
#valid_password?(password) ⇒ Boolean
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'app/models/user.rb', line 79
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
|