user.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. self.data['url'] = self.input('url', '/device')
  13. self.view("login.html")
  14. def post(self):
  15. mobile = self.input('username')
  16. password = self.input('password')
  17. if mobile and password:
  18. user = self.service('common').one('farm_user', mobile=mobile)
  19. if user:
  20. temp = user['password'].split('_')
  21. if Demeter.md5(password, temp[1]) == user['password']:
  22. self.set_secure_cookie('user', str(user['id']))
  23. farm = self.service('common').one('farm', id=user['farm_id'])
  24. if 'eros_status' in farm and farm['eros_status'] == 1 and farm['eros_server']:
  25. url = 'http://' + farm['eros_server'] + ':8081/user/login?username='+mobile+'&password='+temp[0]
  26. #self.redirect(url)
  27. self.out('yes', {'id':user['id'],'url':url})
  28. else:
  29. self.out('yes', {'id':user['id']})
  30. return
  31. self.out('手机号或安全码错误,登录失败')
  32. class loginout_path(Load):
  33. def get(self):
  34. self.set_secure_cookie('user', '')
  35. self.redirect('/user/login')