def Upimg(self): # 验证 token = self.Post('token') msg = AdminToken.Verify(token, request.path) if msg != '': return self.GetJSON({'code': 4001, 'msg': msg}) tData = AdminToken.Token(token) # 参数 base64 = self.Post('base64') if not base64: return self.GetJSON({'code': 4000, 'msg': '参数错误!'}) # 上传 img = Upload.Base64({'path': self.ImgDir, 'base64': base64}) if not img: return self.GetJSON({'code': 5000, 'msg': '上传失败!'}) # 数据 model = UserInfoM() model.Columns('img') model.Where('uid=%s', tData['uid']) imgData = model.FindFirst() model.Set({'img': self.ImgDir + img}) model.Where('uid=%s', tData['uid']) if not model.Update(): return self.GetJSON({'code': 5000, 'msg': '上传失败!'}) # 清理 rmImg = imgData['img'] FileEo.RemoveAll(rmImg) # 返回 return self.GetJSON({ 'code': 0, 'msg': '成功', 'img': Data.Img(self.ImgDir + img) })
def Edit(self): # 验证 token = self.Post('token') msg = AdminToken.Verify(token, request.path) if msg != '': return self.GetJSON({'code': 4001, 'msg': msg}) tData = AdminToken.Token(token) # 参数 data = self.Post('data') if not data: return self.GetJSON({'code': 4000, 'msg': '参数错误!'}) param = Util.JsonDecode(data) # 数据 model = UserInfoM() info = { 'nickname': Util.Trim(param['nickname']), 'name': Util.Trim(param['name']), 'gender': Util.Trim(param['gender']), 'birthday': Util.Strtotime(Util.Trim(param['birthday']), '%Y-%m-%d'), 'position': Util.Trim(param['position']), } model.Set(info) model.Where('uid=%s', tData['uid']) model.Update() # 返回 info['uname'] = tData['uname'] info['img'] = param['img'] info['birthday'] = Util.Date('%Y-%m-%d', info['birthday']) return self.GetJSON({'code': 0, 'msg': '成功', 'uinfo': info})
def Token(self): # 验证 token = self.Post('token') msg = ApiToken.Verify(token, '') if msg != '' : return self.GetJSON({'code':4001, 'msg':msg}) # 参数 uinfo = self.Post('uinfo') tData = ApiToken.Token(token) if uinfo!='1' : return self.GetJSON({'code':0, 'msg':'成功', 'token_time':tData['time']}) # 用户信息 model = UserInfo() model.Columns('nickname','position','name','img') model.Where('uid=%s',tData['uid']) info = model.FindFirst() info['uname'] = tData['uname'] info['img'] = Data.Img(info['img']) return self.GetJSON({'code':0, 'msg':'成功', 'token_time':tData['time'], 'uinfo':info})
def List(self): # 验证 token = self.Post('token') msg = AdminToken.Verify(token, request.path) if msg != '': return self.GetJSON({'code': 4001, 'msg': msg}) tData = AdminToken.Token(token) # 查询 model = UserInfoM() model.Columns('nickname', 'name', 'gender', 'FROM_UNIXTIME(birthday, %s) as birthday', 'position', 'img') model.Where('uid=%s', '%Y-%m-%d', str(tData['uid'])) list = model.FindFirst() # 数据 list['img'] = Data.Img(str(list['img'])) # 返回 return self.GetJSON({'code': 0, 'msg': '成功', 'list': list})