login.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter web
  5. name:login.py 登录相关接口
  6. author:rabin
  7. """
  8. from __load__ import *
  9. class login_path(Load):
  10. @Web.setting
  11. def get(self):
  12. mobile = self.input('mobile')
  13. password = self.input('password')
  14. if mobile and password:
  15. user = self.service('common').one('user', mobile=mobile)
  16. if user:
  17. temp = user['password'].split('_')
  18. if Demeter.md5(password, temp[1]) == user['password']:
  19. self.bind(user['id'])
  20. #self.set_secure_cookie('user', str(user['id']))
  21. #self.redirect('/')
  22. self.out('yes', {'uid':user['id']})
  23. return
  24. else:
  25. self.out('手机号或密码错误,登录失败')
  26. return
  27. @Web.setting
  28. def bind(self, uid):
  29. code = self.input('code')
  30. if not code:
  31. self.out('no')
  32. return
  33. url = Demeter.config['weixinApp']['login']
  34. url = url + '?appid=' + Demeter.config['weixinApp']['appid']
  35. url = url + '&secret=' + Demeter.config['weixinApp']['secret']
  36. url = url + '&js_code=' + code
  37. url = url + '&grant_type=authorization_code'
  38. data = Demeter.curl(url)
  39. return data