Class: Ums::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ums::User
- Defined in:
- app/models/ums/user.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #password ⇒ Object
- #password=(pwd) ⇒ Object
-
#record_operator ⇒ Object
记录操作人员.
- #verify_password(password) ⇒ Object
Class Method Details
.authenticate(account, password) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/ums/user.rb', line 22 def self.authenticate(account,password) user = self.find_by_account(account) 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
55 56 57 58 59 |
# File 'app/models/ums/user.rb', line 55 def as_json =nil ||= {} [:except] = [:hashed_password,:salt] super end |
#password ⇒ Object
44 45 46 |
# File 'app/models/ums/user.rb', line 44 def password @password end |
#password=(pwd) ⇒ Object
48 49 50 51 52 53 |
# File 'app/models/ums/user.rb', line 48 def password=(pwd) @password = pwd return if pwd.blank? create_salt self.hashed_password = Ums::User.encrypted_password(pwd,self.salt) end |
#record_operator ⇒ Object
记录操作人员
15 16 17 18 19 20 |
# File 'app/models/ums/user.rb', line 15 def record_operator if self.respond_to?(:session) && session[:user_id] self.created_by_id = session[:user_id] if new_record? self.updated_by_id = session[:user_id] end end |
#verify_password(password) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/models/ums/user.rb', line 34 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 |