Class: GlobalUser

Inherits:
Redis::NativeHash
  • Object
show all
Defined in:
lib/global_user.rb

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ GlobalUser

Returns a new instance of GlobalUser.



6
7
8
9
# File 'lib/global_user.rb', line 6

def initialize(data = {})
  super(namespace)
  update(data)
end

Instance Method Details

#namespaceObject



11
# File 'lib/global_user.rb', line 11

def namespace; :global_user; end

#password=(value) ⇒ Object



17
18
19
# File 'lib/global_user.rb', line 17

def password=(value)
  self[:password_hash] = Singularity::PasswordHash.generate(value, salt)
end

#password?(value) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/global_user.rb', line 21

def password?(value)
  return false unless value.present?
  return false unless self[:password_hash].present?
  Singularity::PasswordHash.new(self[:password_hash]).matches?(value, salt)
end

#saltObject



13
14
15
# File 'lib/global_user.rb', line 13

def salt
  self[:password_salt] ||= SecureRandom.hex(32)
end

#saveObject



27
28
29
30
# File 'lib/global_user.rb', line 27

def save
  self.key =  unless .nil?
  super
end