Class: User
- Inherits:
-
Object
- Object
- User
- Includes:
- MongoMapper::Document
- Defined in:
- app/models/user.rb
Instance Method Summary collapse
- #auth(user, passwd) ⇒ Object
- #encrypt(password) ⇒ Object
- #encrypt_password ⇒ Object
- #reserved_users ⇒ Object
- #search(str) ⇒ Object
- #search_ltime(str) ⇒ Object
Instance Method Details
#auth(user, passwd) ⇒ Object
50 51 52 |
# File 'app/models/user.rb', line 50 def auth(user,passwd) find_by_lname_and_lpassword_and_status(user,self.encrypt(passwd),"正常") end |
#encrypt(password) ⇒ Object
42 43 44 |
# File 'app/models/user.rb', line 42 def encrypt(password) Digest::SHA2.hexdigest(password) end |
#encrypt_password ⇒ Object
16 17 18 |
# File 'app/models/user.rb', line 16 def encrypt_password self.lpassword=encrypt(self.lpassword) end |
#reserved_users ⇒ Object
46 47 48 |
# File 'app/models/user.rb', line 46 def reserved_users raise "不能修改删除根用户" if ["root"].include?(lname) end |
#search(str) ⇒ Object
20 21 22 23 |
# File 'app/models/user.rb', line 20 def search(str) pat=/#{str}/ where("$or"=>[{:lname=>pat},{:status=>pat},{:last_lip=>pat}]) end |
#search_ltime(str) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/user.rb', line 25 def search_ltime(str) op=str[0] str[0]="" str=str.strip case op when ">" where(:last_ltime.gt=>Time.parse(str)) when "<" where(:last_ltime.lt=>Time.parse(str)) when "!" stime=str.split(",") start_at=Time.parse(stime[0]) stop_at=Time.parse(stime[1]) where(:last_ltime=>{"$gte"=>start_at,"$lte"=>stop_at}) end end |