Class: Ums::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/ums/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authenticate(account, password) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/ums/user.rb', line 10

def self.authenticate(,password)
	user = self.()
	if user
  	expected_password = encrypted_password(password,user.salt)
    #logger.debug("user.hashed_password:" + user.hashed_password + ",expected_password:" + expected_password)
  	if user.hashed_password != expected_password || !user.is_enabled
  		user = nil    		
  	end
  end
  user
end

Instance Method Details

#as_json(options = nil) ⇒ Object



43
44
45
46
47
# File 'app/models/ums/user.rb', line 43

def as_json options=nil
  options ||= {}
  options[:except] = [:hashed_password,:salt]
  super options
end

#passwordObject



32
33
34
# File 'app/models/ums/user.rb', line 32

def password
	@password
end

#password=(pwd) ⇒ Object



36
37
38
39
40
41
# File 'app/models/ums/user.rb', line 36

def password=(pwd)
	@password = pwd
	return if pwd.blank?
	create_salt
	self.hashed_password = Ums::User.encrypted_password(pwd,self.salt)
end

#verify_password(password) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'app/models/ums/user.rb', line 22

def verify_password(password)
  expected_password = Ums::User.encrypted_password(password,self.salt)
  logger.debug("expected_password:"+expected_password+",hashed_password:"+self.hashed_password)
  if self.hashed_password == expected_password
    true       
  else
    false
  end
end