Class: User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- User
- Defined in:
- app/models/user.rb
Constant Summary collapse
- @@per_page =
25
Instance Attribute Summary collapse
-
#password ⇒ Object
Virtual attribute for the unencrypted password.
Class Method Summary collapse
Instance Method Summary collapse
- #change_password(pass, pass_confirm) ⇒ Object
- #create_hash(s) ⇒ Object
- #crypt_password ⇒ Object protected
- #date ⇒ Object
- #delete_taggings ⇒ Object protected
- #destroy_dependencies ⇒ Object protected
- #display_name ⇒ Object
- #forget_me ⇒ Object
- #generate_token ⇒ Object
- #password_matches?(pass) ⇒ Boolean
- #password_required? ⇒ Boolean protected
-
#remember_me ⇒ Object
These create and unset the fields required for remembering users between browser closes.
- #remember_token? ⇒ Boolean
- #to_param ⇒ Object
- #validate_auth_type ⇒ Object
Instance Attribute Details
#password ⇒ Object
Virtual attribute for the unencrypted password
6 7 8 |
# File 'app/models/user.rb', line 6 def password @password end |
Class Method Details
.authenticate(login, pass) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/models/user.rb', line 132 def self.authenticate(login, pass) return nil if login.blank? candidate = where("login = ?", login).first return nil if candidate.nil? if Tracks::Config.auth_schemes.include?('database') return candidate if (candidate.auth_type == 'database' && candidate.password_matches?(pass)) end return nil end |
.find_admin ⇒ Object
149 150 151 |
# File 'app/models/user.rb', line 149 def self.find_admin where(:is_admin => true).first end |
.no_users_yet? ⇒ Boolean
145 146 147 |
# File 'app/models/user.rb', line 145 def self.no_users_yet? count == 0 end |
Instance Method Details
#change_password(pass, pass_confirm) ⇒ Object
168 169 170 171 172 |
# File 'app/models/user.rb', line 168 def change_password(pass, pass_confirm) self.password = pass self.password_confirmation = pass_confirm save! end |
#create_hash(s) ⇒ Object
203 204 205 |
# File 'app/models/user.rb', line 203 def create_hash(s) BCrypt::Password.create(s) end |
#crypt_password ⇒ Object (protected)
209 210 211 212 |
# File 'app/models/user.rb', line 209 def crypt_password return if password.blank? write_attribute("crypted_password", create_hash(password)) if password == password_confirmation end |
#date ⇒ Object
174 175 176 |
# File 'app/models/user.rb', line 174 def date Date.current end |
#delete_taggings ⇒ Object (protected)
224 225 226 227 228 |
# File 'app/models/user.rb', line 224 def delete_taggings ids = todos.pluck(:id) taggings = Tagging.where(taggable_id: ids).pluck(:id) Tagging.where(id: taggings).delete_all end |
#destroy_dependencies ⇒ Object (protected)
218 219 220 221 222 |
# File 'app/models/user.rb', line 218 def destroy_dependencies ids = todos.pluck(:id) pred_deps = Dependency.where(predecessor_id: ids).destroy_all succ_deps = Dependency.where(predecessor_id: ids).destroy_all end |
#display_name ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'app/models/user.rb', line 157 def display_name if first_name.blank? && last_name.blank? return login elsif first_name.blank? return last_name elsif last_name.blank? return first_name end "#{first_name} #{last_name}" end |
#forget_me ⇒ Object
193 194 195 196 197 |
# File 'app/models/user.rb', line 193 def forget_me self.remember_token_expires_at = nil self.remember_token = nil save end |
#generate_token ⇒ Object
178 179 180 |
# File 'app/models/user.rb', line 178 def generate_token self.token = Digest::SHA1.hexdigest "#{Time.zone.now.to_i}#{rand}" end |
#password_matches?(pass) ⇒ Boolean
199 200 201 |
# File 'app/models/user.rb', line 199 def password_matches?(pass) BCrypt::Password.new(crypted_password) == pass end |
#password_required? ⇒ Boolean (protected)
214 215 216 |
# File 'app/models/user.rb', line 214 def password_required? auth_type == 'database' && crypted_password.blank? || password.present? end |
#remember_me ⇒ Object
These create and unset the fields required for remembering users between browser closes
187 188 189 190 191 |
# File 'app/models/user.rb', line 187 def remember_me self.remember_token_expires_at = 2.weeks.from_now.utc self.remember_token ||= Digest::SHA1.hexdigest("#{login}--#{remember_token_expires_at}") save end |
#remember_token? ⇒ Boolean
182 183 184 |
# File 'app/models/user.rb', line 182 def remember_token? remember_token_expires_at && Time.zone.now.utc < remember_token_expires_at end |
#to_param ⇒ Object
153 154 155 |
# File 'app/models/user.rb', line 153 def to_param login end |
#validate_auth_type ⇒ Object
124 125 126 127 128 |
# File 'app/models/user.rb', line 124 def validate_auth_type unless Tracks::Config.auth_schemes.include?(auth_type) errors.add("auth_type", "not a valid authentication type (#{auth_type})") end end |