def get(self): get_class = self.get_argument('class') ukid = self.get_argument('ukid') AccountNumber = self.get_argument('f2') md5_from = self.get_argument('f5') copy_account = self.get_argument('f11', "") edit_flag = self.get_argument('f12', "") md5_from2 = self.get_argument('f13', "") MasterKey = self.get_argument('f14', "") pid = self.get_argument('s0', 0) echotext = "" if get_class == "edit": # 修改授权 # 二次较检 md5_str = AccountNumber + copy_account + str(config.TineMd5Info) str_md5 = hashlib.md5(md5_str.encode(encoding='UTF-8')).hexdigest() if str_md5 == md5_from2: # 信息验证成功,进行相关操作 R = RedisClass() followid = yield R.chick_MD5_uaid(AccountNumber, md5_from, ukid) if followid > 0: m_flag = yield R.chick_MaterAuthorize( followid, copy_account) if edit_flag == "1" and m_flag == True: echotext = "0,0," elif edit_flag == "0" and m_flag == False: echotext = "0,0," else: #需要修改授权 M = MasterModel() flag = R.RH.hget( config.redis_master_uaid_Hash + str(followid), str(copy_account)) if flag == 1 or flag == "1": mflag = yield M.setMaterAuthorize( followid, copy_account, 0) if mflag == True: R.RH.hset( config.redis_master_uaid_Hash + str(followid), str(copy_account), "0") echotext = "1,0," else: echotext = "-3,0," else: # 判断超过授权数量 copy_max_num = yield M.get_copy_num( R.RH.hgetall(config.redis_master_uaid_Hash + str(followid))) master_max_num = yield M.getMaterCopyNum( pid, followid) if copy_max_num >= master_max_num: # 授权数量超过 echotext = "-6,0," else: mflag = yield M.setMaterAuthorize( followid, copy_account, 1) if mflag == True: R.RH.hset( config.redis_master_uaid_Hash + str(followid), str(copy_account), "1") echotext = "1,1," else: echotext = "-3,0," else: echotext = "-4,0," else: echotext = "-5,0," elif get_class == "apply": # 申请授权 # 二次较检 md5_str = AccountNumber + MasterKey + str(config.TineMd5Info) str_md5 = hashlib.md5(md5_str.encode(encoding='UTF-8')).hexdigest() if str_md5 == md5_from2: #信息验证成功 R = RedisClass() uaid = yield R.chick_MD5_uaid(AccountNumber, md5_from, ukid) if uaid > 0: M = MasterModel() followid = yield R.get_Mater_uaid(MasterKey) if followid == None: mflag = False else: mflag = yield R.chick_MaterAuthorize(followid, uaid) if mflag == True: #已经授权 echotext = "2," + str( config.ERROR_TIME) + ",9947" + str(followid) + "," else: if followid != None: # 有MasterKey的策略,进行申请操作 yield R.insert_master_uaid(MasterKey, followid) #检查数据库 # print(followid,uaid) yield M.checkMaterFollow(followid, uaid) # 更新Redis yield R.set_MaterFollow(followid, uaid, 0) echotext = "1,0," else: #无效MasterKey,找不到相关策略 echotext = "-3,0," else: echotext = "-4,0," else: echotext = "-5,0," self.write(echotext + config.StringEnd) self.finish()
def post(self): echo_dist = {} if self.session['web_uid'] == None: echo_dist['reponse_status'] = -1 else: # F = AccountsForm(self.request.arguments) if F.validate(): #and F.cla.data == "SendError" from models.user.strategy_model import StrategyModel S = StrategyModel() echo_dist['reponse_status'] = 5 cookie_dist = self.getCookie(1) page_papa = {} page_papa['start'] = F.start.data page_papa['length'] = F.length.data page_papa['search'] = self.get_argument('search[value]', '0') page_papa['fx_type'] = F.fx_type.data page_papa['fx_id'] = F.fx_id.data if F.fx_type.data == "edit_authorization": # 修改授权 R = RedisClass() flag = yield S.edit_authorization( self.session['web_uid'], self.get_user_ip(), cookie_dist["current_strategy"], F.fx_id.data) if flag < 0: echo_dist['reponse_status'] = flag else: logger.debug("edit_authorization:%s,%s,%s" % (cookie_dist["current_strategy"], str(F.fx_id.data), str(flag))) # R.RH.hset(config.redis_master_uaid_Hash + str(self.get_secure_cookie("current_strategy"), # encoding="utf-8"), str(F.fx_id.data), str(flag)) yield R.set_MaterFollow( cookie_dist["current_strategy"], str(F.fx_id.data), str(flag)) echo_dist['echo'] = flag elif F.fx_type.data == "list_master": echo_dist['data'] = yield S.getStrategyListPage( self.session['web_uid'], page_papa, 1) if len(echo_dist.get('data')) > 0: if 'allnum' in echo_dist['data'][-1]: allnum = echo_dist['data'].pop() logger.debug(allnum) echo_dist["recordsTotal"] = allnum['allnum'] echo_dist["recordsFiltered"] = allnum['allnum'] # s_data.pop() else: echo_dist['echo'] = self.locale.translate("无数据") echo_dist['reponse_status'] = 5 elif F.fx_type.data == "click_delete": echo_dist['reponse_status'] = yield S.edit_master_delete( self.session['web_uid'], self.get_user_ip(), F.fx_id.data) if echo_dist['reponse_status'] != 5: echo_dist['echo'] = self.locale.translate("操作失败") elif F.fx_type.data == "delete_follow_flag": echo_dist['reponse_status'] = yield S.edit_follow_delete( cookie_dist["current_strategy"], self.session['web_uid'], self.get_user_ip(), F.fx_id.data) if echo_dist['reponse_status'] != 5: echo_dist['echo'] = self.locale.translate("操作失败") else: # 表单错误 from models.public.confrom_model import get_ErrorForm echo_dist['echo'] = get_ErrorForm(F) echo_dist['reponse_status'] = 1 # from models.public.headers_model import DateEncoder # yield self.write(json.dumps(echo_dist, cls=DateEncoder)) self.write(json.dumps(echo_dist)) self.finish()