user.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. """
  3. demeter web page
  4. name:user.py
  5. author:rabin
  6. """
  7. from .__load__ import *
  8. class login_path(Load):
  9. def get(self):
  10. #url = Demeter.config['web']['url']
  11. #self.redirect(url)
  12. mobile = self.input('username')
  13. password = self.input('password')
  14. if mobile and password:
  15. user = self.service('common').one('farm_user', mobile=mobile)
  16. if user:
  17. temp = user['password'].split('_')
  18. if password + '_' + temp[1] == user['password']:
  19. self.set_secure_cookie('user', str(user['id']))
  20. url = self.input('url', '/device')
  21. self.redirect(url)
  22. self.data['url'] = self.input('url', '/device')
  23. self.view("login.html")
  24. def post(self):
  25. mobile = self.input('username')
  26. password = self.input('password')
  27. if mobile and password:
  28. user = self.service('common').one('farm_user', mobile=mobile)
  29. if user:
  30. temp = user['password'].split('_')
  31. if Demeter.md5(password, temp[1]) == user['password']:
  32. self.set_secure_cookie('user', str(user['id']))
  33. self.out('yes', {'id':user['id']})
  34. return
  35. self.out('手机号或安全码错误,登录失败')
  36. class loginout_path(Load):
  37. def get(self):
  38. self.set_secure_cookie('user', '')
  39. self.redirect('/user/login')