Class: User

Inherits:
Object
  • Object
show all
Includes:
MongoMapper::Document
Defined in:
app/models/user.rb

Instance Method Summary collapse

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_passwordObject



16
17
18
# File 'app/models/user.rb', line 16

def encrypt_password
  self.lpassword=encrypt(self.lpassword)
end

#reserved_usersObject



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