Commit ca763814
Changed files (1)
app
models
app/models/user.rb
@@ -1,18 +1,13 @@
require 'bcrypt'
class User < ActiveRecord::Base
- #include BCrypt
has_secure_password
- #has_secure_password validations: false
before_save :ensure_authentication_token
after_create :send_welcome_email unless Rails.env.test?
validates :name, presence: true
validates :email, presence: true, uniqueness: true, email: true
validates :website, :format => URI::regexp(%w(http https)), :allow_blank => true
-
- #validates_presence_of :password, :if => :password_required?
- #validates_confirmation_of :password, :if => :password_required?
validates_length_of :password, :within => 6..20, :allow_blank => true
has_many :creations, :dependent => :destroy
@@ -51,15 +46,6 @@ class User < ActiveRecord::Base
self.encrypted_password = value
end
- #def password
- #@password
- #end
-
- #def password=(new_password)
- #@password = new_password
- #self.encrypted_password = Password.create(new_password)
- #end
-
def has_avatar?
self.avatar && self.avatar.image.present?
end
@@ -89,13 +75,6 @@ class User < ActiveRecord::Base
creations.create(name: name, category_id: category.id)
end
- #def valid_password?(password)
- #return false if encrypted_password.blank?
- #bcrypt = ::BCrypt::Password.new(encrypted_password)
- #password = ::BCrypt::Engine.hash_secret(password, bcrypt.salt)
- #secure_compare(password, encrypted_password)
- #end
-
class << self
def ordered
User.order(:creations_count => :desc)
@@ -115,26 +94,11 @@ class User < ActiveRecord::Base
false
end
end
-
end
private
- # constant-time comparison algorithm to prevent timing attacks
- #def secure_compare(a, b)
- #return false if a.blank? || b.blank? || a.bytesize != b.bytesize
- #l = a.unpack "C#{a.bytesize}"
-
- #res = 0
- #b.each_byte { |byte| res |= byte ^ l.shift }
- #res == 0
- #end
-
def ensure_authentication_token
self.authentication_token = SecureRandom.hex(32) if self.authentication_token.blank?
end
-
- #def password_required?
- #!persisted? || !password.nil? || !password_confirmation.nil?
- #end
end