user.py 875 B

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