Beispiel #1
0
 async def article(self, id):
     print('article')
     data = self.dg.article(id)
     if data == None:
         return Result().setCode(Result.CODE_ERROR).setMsg('无此文章').toJson()
     else:
         return Result().setCode(Result.CODE_SUCCESS).setData(data).setMsg('操作成功').toJson()
Beispiel #2
0
 def wechatLogin(self, data):
     openid = data['openid']
     uinfo = self.getUserInfoByField('wx_openid', openid)
     print(uinfo)
     rsdata = {}
     rsdata['is_reg'] = 0
     if uinfo == None:  #需要注册
         m1 = hashlib.md5()
         m1.update(openid.encode("utf8"))
         rsdata['is_reg'] = 1
         userinfo = {}
         userinfo['wx_openid'] = openid
         userinfo['unionid'] = data['unionid']
         userinfo['token'] = m1.hexdigest() + str(
             random.random() * 10000).split('.')[0]
         userinfo['nick_name'] = data['nickname']
         userinfo['head_image'] = data['head_image']
         userid = self._db.insert('user', userinfo)
         rsdata['userid'] = userid
         rsdata['token'] = userinfo['token']
         if int(userid) > 0:
             return Result().setCode(
                 Result.CODE_SUCCESS).setData(rsdata).setMsg('操作成功')
         else:
             return Result().setCode(Result.CODE_ERROR).setMsg('注册失败')
     rsdata['userid'] = uinfo['id']
     rsdata['token'] = uinfo['token']
     return Result().setCode(
         Result.CODE_SUCCESS).setData(rsdata).setMsg('操作成功')
Beispiel #3
0
 def setLogin(self, token):
     uinfo = self.getUserInfoByField('token', token)
     if uinfo == None:
         return Result().setCode(
             Result.CODE_ERROR).setMsg('不存在此用户').toJson()
     UserIdModel.getInstance().userid = uinfo['id']
     return None
Beispiel #4
0
def checkLogin(request):
    hand = Handler()
    params = hand.parseGet(request)
    token = params.get('loginToken')
    if token == None:
        return Result().setCode(Result.CODE_ERROR).setMsg('缺少参数').toJson()
    um = UserModel()
    return um.setLogin(token)
Beispiel #5
0
 def sendDiag(self, **kw):
     return Result().setCode(Result.CODE_SUCCESS).setMsg('操作成功').toJson()
Beispiel #6
0
 async def service(self):
     print('service')
     data = {}
     await asyncio.sleep(3)
     data['serviceList'] = await self.dg.service()
     return Result().setCode(Result.CODE_SUCCESS).setData(data).setMsg('操作成功').toJson()
Beispiel #7
0
 def index(self):
     data = {}
     #data['articleList'] = self.dg.articleList()
     return Result().setCode(Result.CODE_SUCCESS).setData(data).setMsg('操作成功').toJson()