class Libis::Ingester::User

Public Class Methods

authenticate(name, password) click to toggle source
# File lib/libis/ingester/user.rb, line 42
def self.authenticate(name, password)
  user = User.find_by(name: name)
  return user if user && user.authenticate(password)
  nil
end
from_hash(hash) click to toggle source
# File lib/libis/ingester/user.rb, line 27
def self.from_hash(hash)
  # noinspection RubyResolve
  self.create_from_hash(hash, [:name]) do |item, cfg|
    item.organizations.clear
    (cfg.delete('organizations') || []).each do |org_name|
      item.organizations << Libis::Ingester::Organization.from_hash(name: org_name)
    end
  end
end
get_password_hash(password) click to toggle source
# File lib/libis/ingester/user.rb, line 57
def self.get_password_hash(password)
  md5 = Libis::Tools::Checksum.hexdigest('LibisIngesterUser' + password, :MD5)
  Libis::Tools::Checksum.hexdigest(md5 + password, :SHA256)
end

Public Instance Methods

authenticate(password) click to toggle source
# File lib/libis/ingester/user.rb, line 37
def authenticate(password)
  return true if self.password_hash.blank? && password.blank?
  self.class.get_password_hash(password) == self.password_hash
end
password() click to toggle source
# File lib/libis/ingester/user.rb, line 53
def password
  self.password_hash
end
password=(password) click to toggle source
# File lib/libis/ingester/user.rb, line 48
def password=(password)
  self.password_hash = self.class.get_password_hash(password)
  nil
end