def user_login(self, _inent): '''用户登录''' in_ent = LogingModel() in_ent.__dict__ = _inent if in_ent.loginName is None or in_ent.loginName == '': return AppReturnDTO(False, "用户名不能为空") if in_ent.password is None or in_ent.password == '': return AppReturnDTO(False, "密码不能为空") login = FaLogin.query.filter_by(LOGIN_NAME=in_ent.loginName).first() user = FaUser.query.filter_by(LOGIN_NAME=in_ent.loginName).first() if user is None or login is None: return AppReturnDTO(False, "用户名有误") if login.PASSWORD != hashlib.md5( in_ent.password.encode('utf-8')).hexdigest(): return AppReturnDTO(False, "密码有误") tmp = UserDal() tmp.__dict__ = user.__dict__ tmpId = [x.ID for x in user.fa_roles] tmp.roleIdList = tmpId moduleIdList, msg = self.user_all_module(user.ID) # 获取用户模块 if not msg.IsSuccess: return msg tmp.moduleList = json.loads( json.dumps(moduleIdList, cls=AlchemyEncoder)) token = LoginDal.generate_auth_token(tmp) token = token.decode('utf-8') return AppReturnDTO(True, "登录成功", tmp, token)
def view_export(): """ 导出EXCEL文件 """ j_data = request.json if j_data is None: return Fun.class_to_JsonStr(AppReturnDTO(False, "参数有误")) in_ent = RequestPagesModel(j_data) _modele = QueryDal() sql, cfg, message = _modele.query_GetSqlByCode( in_ent.Key, in_ent.SearchKey, in_ent.OrderBy) if not message.IsSuccess: return Fun.class_to_JsonStr(message) _dict, message = Fun.sql_to_dict(sql) if not message.IsSuccess: return Fun.class_to_JsonStr(message) dirpath = os.path.join(app.root_path, 'download') file_name = "query_{0}.xlsx".format(in_ent.Key) Of.Office.ExportToXls(_dict, cfg, dirpath + "\\" + file_name) # directory = os.getcwd() # 假设在当前目录 # response = make_response( # send_from_directory(directory, file_name, as_attachment=True)) # response.headers["Content-Disposition"] = "attachment; filename={}".format( # file_name.encode().decode('latin-1')) return Fun.class_to_JsonStr( AppReturnDTO(True, "{0}/{1}".format('download', file_name)))
def ResetPassword(self, VerifyCode, LoginName, NewPwd): if not VerifyCode.strip() or not LoginName.strip() or not NewPwd.strip( ): return None, AppReturnDTO(False, "参数有误") sql = "select ID from fa_login where VERIFY_CODE='{0}' and LOGIN_NAME='{1}' and FAIL_COUNT<5 and TIMESTAMPDIFF(MINUTE,VERIFY_TIME,NOW())<5 ;".format( VerifyCode, LoginName) print(sql) resource = db.session.execute(sql) dataListToup = resource.fetchall() #如果没有找到数据,则在错误次数加1 if len(dataListToup) != 1: sql = "update fa_login set FAIL_COUNT=FAIL_COUNT+1 where LOGIN_NAME='{0}'".format( LoginName) print(sql) db.session.execute(sql) return None, AppReturnDTO(False, "验证码有误请重新获取") sql = "update fa_login set PASSWORD='******' where LOGIN_NAME='{0}'".format( LoginName, hashlib.md5(NewPwd.encode('utf-8')).hexdigest()) print(sql) resource = db.session.execute(sql) updateNum = resource.rowcount db.session.commit() db.session.close() if updateNum != 1: return None, AppReturnDTO(False, "影响数不为1") return None, AppReturnDTO(True, "成功")
def AddUserInfoSimple(self, name, parentId): """ 只添加用户的名称和父节点,不会添加登录账号,没提交事务 :param name: 用户名 :param parentId:父ID """ parentEnt = FaUserInfo.query.filter(FaUserInfo.ID == parentId).first() if parentEnt is None: return None, AppReturnDTO(False, "父ID有问题") userInfoEnt = FaUserInfo() userInfoEnt.ID = Fun.GetSeqId(FaUser) userInfoEnt.NAME = name userInfoEnt.FATHER_ID = parentId userInfoEnt.DISTRICT_ID = parentEnt.DISTRICT_ID userInfoEnt.IS_LOCKED = 0 userInfoEnt.CREATE_TIME = datetime.datetime.now() userInfoEnt.LEVEL_ID = 1 userInfoEnt.STATUS = '正常' userInfoEnt.CREATE_USER_NAME = '自动' userInfoEnt.CREATE_USER_ID = '1' userInfoEnt.UPDATE_TIME = datetime.datetime.now() userInfoEnt.UPDATE_USER_NAME = 'admin' db.session.add(userInfoEnt) return userInfoEnt, AppReturnDTO(True)
def query_GetSqlByCode(self, code, criterion, where): """ 根据查询代码运算出查询的SQL 用于导出数据,并统一管理配置的SQL 返回SQL和配置 """ db_ent = FaQuery.query.filter(FaQuery.CODE == code).first() if db_ent is None: return "", "", AppReturnDTO(False, "代码不存在") sql = db_ent.QUERY_CONF orderArr = [] for order in criterion: orderArr.append("T.%(Key)s %(Value)s" % order) whereArr = [] for search in where: if search["Type"] == "like": whereArr.append("T.%(Key)s like ('%%%(Value)s%%')" % search) else: whereArr.append("T.%(Key)s %(Type)s %(Value)s " % search) sql = "SELECT * FROM ({0}) T{1}{2}".format( sql, " WHERE " + " AND ".join(whereArr) if len(whereArr) > 0 else "", " ORDER BY " + " , ".join(orderArr) if len(orderArr) > 0 else "", ) jsonStr = re.sub(r'\r|\n| ', "", db_ent.QUERY_CFG_JSON) jsonStr = re.sub(r'"onComponentInitFunction"((.|\n)+?)},', "", jsonStr) jsonStr = re.sub(r',},', ",", jsonStr) return sql, json.loads(jsonStr), AppReturnDTO(True)
def model_delete(model, key): '删除记录,并返回删除的条数' try: delMode = model.query.filter(model.ID == key).delete(synchronize_session=False) db.session.commit() return delMode,AppReturnDTO(True) except: return None,AppReturnDTO(False,'删除失败')
def ApiPublicGetSolarDate(): j_data, msg = Fun.post_to_dict(request) if j_data is None: return Fun.class_to_JsonStr(msg) postEnt = RequestSaveModel(j_data) if postEnt is None or postEnt.Data is None: return Fun.class_to_JsonStr(AppReturnDTO(False, "参数有问题")) t = time.strptime(postEnt.Data["Data"], "%Y-%m-%d") y, m, d = t[0:3] reStr = iSoft.core.LunarDate.LunarDate.fromSolarDate(y, m, d) reStr = "{0}-{1}-{2}".format(reStr.year, reStr.month, reStr.day) return Fun.class_to_JsonStr(AppReturnDTO(True, reStr))
def UpdateCode(self, loginName, verifyCode): nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') sql = "update fa_login set VERIFY_CODE='{0}',VERIFY_TIME='{1}',FAIL_COUNT=0 where LOGIN_NAME='{2}'".format( verifyCode, nowTime, loginName) resource = db.session.execute(sql) print(sql) updateNum = resource.rowcount db.session.commit() db.session.close() if updateNum != 1: return AppReturnDTO(False, "影响数不为1") return AppReturnDTO(True, "成功")
def login_reg(_inent): '''注册用户''' in_ent = LogingModel() in_ent.__dict__ = _inent if in_ent.loginName is None or in_ent.loginName == '': return AppReturnDTO(False, "电话号码不能为空") if not Fun.is_phonenum(in_ent.loginName): return AppReturnDTO(False, "电话号码格式不正确") complexity = Fun.password_complexity(in_ent.password) if complexity < PASSWORD_COMPLEXITY: return AppReturnDTO(False, "密码复杂度不够:" + str(complexity)) return AppReturnDTO(False, "暂不开放注册")
def AddUserInfoAndLogin(self, parentId, loginName, password, name, level_id, sex, YEARS_TYPE, BIRTHDAY_TIME, birthday_place, ICON_FILES_ID, ALIAS, AUTHORITY): '完善用户的基本资料以及登录账号' parentEnt = FaUserInfo.query.filter(FaUserInfo.ID == parentId).first() if parentEnt is None: return None, AppReturnDTO(False, "父ID有问题") # <- 获取添加成功后的Login实体 loginDal = LoginDal() loginDal.LOGIN_NAME = loginName loginDal.PASSWORD = password loginDal.PHONE_NO = loginName loginEng, msg = loginDal.AddLoginName() if not msg.IsSuccess: return msg # -> # <- 更新用户信息 userInfoEnt = FaUserInfo() userInfoEnt.ID = Fun.GetSeqId(FaUser) userInfoEnt.FATHER_ID = parentId userInfoEnt.LOGIN_NAME = loginDal.LOGIN_NAME userInfoEnt.UPDATE_TIME = datetime.datetime.now() userInfoEnt.NAME = name userInfoEnt.LEVEL_ID = level_id userInfoEnt.SEX = sex userInfoEnt.YEARS_TYPE = YEARS_TYPE if not Fun.IsNullOrEmpty(BIRTHDAY_TIME): userInfoEnt.BIRTHDAY_TIME = datetime.datetime.strptime( BIRTHDAY_TIME, '%Y-%m-%dT%H:%M:%SZ') userInfoEnt.BIRTHDAY_PLACE = birthday_place userInfoEnt.DIED_TIME = None userInfoEnt.DIED_PLACE = None userInfoEnt.DISTRICT_ID = parentEnt.DISTRICT_ID userInfoEnt.IS_LOCKED = 0 userInfoEnt.CREATE_TIME = datetime.datetime.now() userInfoEnt.LEVEL_ID = 1 userInfoEnt.STATUS = '正常' userInfoEnt.CREATE_USER_NAME = name userInfoEnt.CREATE_USER_ID = userInfoEnt.ID userInfoEnt.UPDATE_TIME = datetime.datetime.now() userInfoEnt.UPDATE_USER_NAME = name userInfoEnt.ICON_FILES_ID = ICON_FILES_ID userInfoEnt.ALIAS = ALIAS userInfoEnt.AUTHORITY = AUTHORITY db.session.add(userInfoEnt) return userInfoEnt, AppReturnDTO(True)
def FinishUserInfoAndLogin(self, userId, loginName, password, name, level_id, sex, YEARS_TYPE, BIRTHDAY_TIME, birthday_place): '完善用户的基本资料以及登录账号' # <- 获取添加成功后的Login实体 loginDal = LoginDal() loginDal.LOGIN_NAME = loginName loginDal.PASSWORD = password loginDal.PHONE_NO = loginName loginEng, msg = loginDal.AddLoginName() if not msg.IsSuccess: return msg # -> # <- 更新用户信息 userInfoEnt = FaUserInfo.query.filter( FaUserInfo.ID == int(userId)).first() if userInfoEnt is None: return AppReturnDTO(False, "用户的ID有误") userInfoEnt.LOGIN_NAME = loginDal.LOGIN_NAME userInfoEnt.UPDATE_TIME = datetime.datetime.now() userInfoEnt.NAME = name # userInfoEnt.NAME = in_ent.parentArr[0]["V"] userInfoEnt.LEVEL_ID = level_id userInfoEnt.SEX = sex userInfoEnt.YEARS_TYPE = YEARS_TYPE userInfoEnt.BIRTHDAY_TIME = datetime.datetime.strptime( BIRTHDAY_TIME, '%Y-%m-%dT%H:%M:%SZ') userInfoEnt.BIRTHDAY_PLACE = birthday_place userInfoEnt.DIED_TIME = None userInfoEnt.DIED_PLACE = None
def ApiUserInfoSave(): j_data = request.json if j_data is None: return Fun.class_to_JsonStr(AppReturnDTO(False, "参数有误")) in_ent = RequestSaveModel(j_data) _modele = UserInfoDal() # 更新添加的用户 if hasattr(g, "current_user"): # 表示添加 if "ID" not in in_ent.Data or in_ent.Data["ID"] is None or in_ent.Data[ "ID"] == 0: in_ent.Data["CREATE_USER_NAME"] = g.current_user.NAME if "CREATE_USER_NAME" not in in_ent.SaveKeys: in_ent.SaveKeys.append('CREATE_USER_NAME') in_ent.Data["CREATE_USER_ID"] = g.current_user.ID if "CREATE_USER_ID" not in in_ent.SaveKeys: in_ent.SaveKeys.append('CREATE_USER_ID') # 设置角色 in_ent.Data["roleIdList"] = "3" if "roleIdList" not in in_ent.SaveKeys: in_ent.SaveKeys.append('roleIdList') re_ent, message = _modele.userInfo_Save(in_dict=in_ent.Data, saveKeys=in_ent.SaveKeys) if message.IsSuccess: message.Data = json.loads(json.dumps(re_ent, cls=AlchemyEncoder)) # message.set_data(re_ent) return Fun.class_to_JsonStr(message)
def query_queryByCode(self, code, pageIndex, pageSize, criterion, where): sql, cfg, msg = self.query_GetSqlByCode(code, criterion, where) if not msg.IsSuccess: return sql, msg relist = db.session.execute(sql) num = relist.rowcount relist.close() if pageIndex < 1: pageSize = 1 if pageSize < 1: pageSize = 10 # 最大页码 max_page = math.ceil(num / pageSize) # 向上取整 if pageIndex > max_page: return None, AppReturnDTO(True, num) pageSql = "{0} LIMIT {1},{2}".format(sql, (pageIndex - 1) * pageSize, pageSize) allData, msg = Fun.sql_to_dict(pageSql) if msg.IsSuccess: msg.Msg = num # relist = relist.paginate(pageIndex, per_page=pageSize).items return allData, msg
def ApiPublicUpload(): if request.method == 'POST': f = request.files['file'] basepath = os.path.dirname(__file__) newName = "{0}{1}".format( str(time.time())[0:10], f.filename[f.filename.rfind("."):]) upload_path = os.path.join(basepath, "../static/uploads", newName) f.save(upload_path) userId = 0 if hasattr(g, "current_user"): userId = g.current_user.ID addFile = { "NAME": f.filename, "URL": 'uploads/{0}'.format(newName), "PATH": upload_path, "USER_ID": userId, "LENGTH": len(f.read()), "UPLOAD_TIME": datetime.datetime.now(), } dal = FileDal() re_ent, message = dal.file_Save(addFile, []) if message.IsSuccess: tmp = json.dumps(re_ent, cls=AlchemyEncoder) if len(tmp) < 5: tmp = json.dumps(re_ent, cls=AlchemyEncoder) msg = json.loads(tmp) # print(tmp) # print(re_ent) # print(msg) message.Data = msg reStr = Fun.class_to_JsonStr(message) return reStr return Fun.class_to_JsonStr(AppReturnDTO(False))
def UpdateCode(self, loginName, verifyCode): '更新短验证码,如果号码不存在,则添加新有号码,并发送短信' msg = "成功" if not send_verify_code(loginName, verifyCode): msg = verifyCode # return AppReturnDTO(False, "短信发送失败") loginEnt = FaLogin.query.filter( FaLogin.LOGIN_NAME == loginName).first() if loginEnt is None: loginEnt = self loginEnt.LOGIN_NAME = loginName loginEnt.VERIFY_CODE = verifyCode loginEnt.ID = Fun.GetSeqId(self) loginEnt.FAIL_COUNT = 0 loginEnt.VERIFY_TIME = datetime.datetime.now() db.session.add(loginEnt) else: loginEnt.VERIFY_CODE = verifyCode loginEnt.FAIL_COUNT = 0 loginEnt.VERIFY_TIME = datetime.datetime.now() db.session.commit() db.session.close() return AppReturnDTO(True, msg)
def model_delete(model, key): delSql = 'delete from {0} where ID IN ({1})'.format( model.__tablename__, key) print(delSql) db.session.execute(delSql) db.session.commit() return AppReturnDTO(True)
def module_list(): j_data = request.json if j_data is None: return Fun.class_to_JsonStr(AppReturnDTO(False, "参数有误")) in_ent = RequestPagesModel(j_data) where = [] for search in in_ent.SearchKey: if search["Type"] == "like": where.append( eval("FaModule.%(Key)s.like('%%%(Value)s%%')" % search)) else: where.append(eval("FaModule.%(Key)s%(Type)s%(Value)s" % search)) criterion = [] for search in in_ent.OrderBy: search["Value"] = search["Value"].lower() criterion.append(eval("FaModule.%(Key)s.%(Value)s()" % search)) _modele = ModuleDal() re_ent, message = _modele.module_findall(in_ent.PageIndex, in_ent.PageSize, criterion, where) if message.IsSuccess: message.set_data(re_ent) return Fun.class_to_JsonStr(message)
def user_module(): ''' 获取用户的所有模块 ''' j_data = request.json if j_data is None: return Fun.class_to_JsonStr(AppReturnDTO(False, "参数有误")) in_ent = PostBaseModel(j_data) _mod = UserDal() if g == None: return Fun.class_to_JsonStr(AppReturnDTO(False, "没有登录")) re_ent, message = _mod.user_all_module(g.current_user['ID']) if message.IsSuccess: message.set_data(re_ent) return Fun.class_to_JsonStr(message)
def ApiPublicGetLunarDate(): '获取阴历' j_data, msg = Fun.post_to_dict(request) if j_data is None: return Fun.class_to_JsonStr(msg) postEnt = RequestSaveModel(j_data) if postEnt is None or postEnt.Data is None: return Fun.class_to_JsonStr(AppReturnDTO(False, "参数有问题")) t = time.strptime(postEnt.Data["Data"], "%Y-%m-%dT%H:%M") y, m, d, h = t[0:4] converter = LunarSolarConverter() solar = Solar(y, m, d) lunar = converter.SolarToLunar(solar) reStr = "%d年%02d月%02d日%02d时" % (lunar.lunarYear, lunar.lunarMonth, lunar.lunarDay, h) return Fun.class_to_JsonStr(AppReturnDTO(True, reStr))
def module_delete(): j_data = request.json if j_data is None: return Fun.class_to_JsonStr(AppReturnDTO(False, "参数有误")) in_ent = PostBaseModel(j_data) _modele = ModuleDal() message = _modele.module_delete(in_ent.Key) return Fun.class_to_JsonStr(message)
def district_Save(self, in_dict, saveKeys): newParent = None saveKeys.append("ID_PATH") saveKeys.append("REGION") if "PARENT_ID" not in in_dict or in_dict["PARENT_ID"] is None: in_dict["LEVEL_ID"] = 0 in_dict["ID_PATH"] = "." in_dict["REGION"] = 0 else: newParent, is_succ = self.district_single(in_dict["PARENT_ID"]) if newParent is None: return None, AppReturnDTO(False, "上级节点有误") in_dict["LEVEL_ID"] = newParent.LEVEL_ID + 1 in_dict["ID_PATH"] = "{0}{1}.".format(newParent.ID_PATH, in_dict["PARENT_ID"]) in_dict["REGION"] = newParent.REGION pass #用于更新所有子节点的ID_PATH,如果修改过parent_id的话 if "ID" in in_dict and in_dict["ID"] is not None and in_dict["ID"] != 0: if str(in_dict["ID"]) == str(in_dict["PARENT_ID"]): return None, AppReturnDTO(False, "上级不能选择自己") sql = "SELECT ID FROM fa_district WHERE ID_PATH LIKE '%.{0}.%'".format( in_dict["ID"]) childListTuple = db.session.execute(sql).fetchall() childList = [item[0] for item in childListTuple] if int(in_dict["PARENT_ID"]) in childList: return None, AppReturnDTO(False, "上级不能自己子集") nowEnt = FaDistrict.query.filter( FaDistrict.ID == in_dict["ID"]).first() #如果PARENT_ID没有变化则不执行下面语句 if nowEnt.PARENT_ID != in_dict["PARENT_ID"]: if nowEnt is None: return None, AppReturnDTO(False, "ID有误") updateSql = "UPDATE fa_district SET ID_PATH= '{0}{1}.' WHERE ID_PATH LIKE '%{2}{1}.%'" updateSql = updateSql.format(in_dict["ID_PATH"], nowEnt.ID, nowEnt.ID_PATH) print(updateSql) db.session.execute(updateSql) relist, is_succ = Fun.model_save(FaDistrict, self, in_dict, saveKeys) return relist, is_succ
def auth_UserLogin(): '''手机用户登录''' j_data = request.json if j_data is None: return Fun.class_to_JsonStr(AppReturnDTO(False, "参数有误")) _model = UserDal() ent = _model.user_login(j_data) return Fun.class_to_JsonStr(ent)
def user_save_extend(self, user, in_dict, saveKeys): '更新扩展信息' # <!--更新用户的角色-- if "roleIdList" in saveKeys: sqlStr = ''' DELETE FROM fa_user_role WHERE fa_user_role.USER_ID = {0} '''.format(user.ID) print(sqlStr) execObj = db.session.execute(sqlStr) if len(in_dict["roleIdList"]) > 0: sqlStr = ''' INSERT INTO fa_user_role (ROLE_ID, USER_ID) SELECT m.ID ROLE_ID, {0} USER_ID FROM fa_role m WHERE m.ID IN ({1}) '''.format(user.ID, ','.join( str(i) for i in in_dict["roleIdList"])) print(sqlStr) execObj = db.session.execute(sqlStr) # --更新用户的角色--!> # <!--更新用户的附件-- if "filesList" in saveKeys: sqlStr = ''' DELETE FROM fa_user_file WHERE fa_user_file.USER_ID = {0} '''.format(user.ID) print(sqlStr) execObj = db.session.execute(sqlStr) if len(in_dict["filesList"]) > 0: sqlStr = ''' INSERT INTO fa_user_file (FILE_ID, USER_ID) SELECT m.ID FILE_ID, {0} USER_ID FROM fa_files m WHERE m.ID IN ({1}) '''.format(user.ID, ','.join( str(i["ID"]) for i in in_dict["filesList"])) print(sqlStr) execObj = db.session.execute(sqlStr) # --更新用户的角色--!> db.session.commit() return user, AppReturnDTO(True)
def AddSonItem(self, mainList, inFather, levelId, maxLevelId, inAxisXY): """ 添加子节点,和计算当前坐标HorizonVal :param mainList: :param inFather: :param levelId: :param maxLevelId: :param inAxisXY: """ # 初始化最小值 reEnt = HorizonVal(inAxisXY.X, inAxisXY.X) if levelId > maxLevelId: # 如果层级过大,则退出 return reEnt, AppReturnDTO(True) # 如果没有子项也退出 if inFather.fa_user_infos is None or len(inFather.fa_user_infos) == 0: return reEnt, AppReturnDTO(True) startX = inAxisXY.X # 循环所有子项,子项从小到大 allChildren = sorted(inFather.fa_user_infos, key=lambda x: x.LEVEL_ID) allChildXList = [] for index, son in enumerate(allChildren): #获取子项的 nowHorizonVal, msg = self.AddSonItem( mainList, son, levelId + 1, maxLevelId, AxisXY(startX, inAxisXY.Y + 1)) # 该值会传入入下一项兄弟项,加2是因为每个项间隔都是2,在除的时候,才会有整数 startX = nowHorizonVal.AllMaxHorizon if nowHorizonVal.AllMaxHorizon > nowHorizonVal.RowMaxHorizon + 2 else nowHorizonVal.RowMaxHorizon + 2 #获取所有子项的中间值 thisItemX = nowHorizonVal.Between() # 保存所有子项的X坐标 allChildXList.append(thisItemX) item = self.UserInfoToRelativeItem(son, thisItemX, inAxisXY.Y + 1) mainList.append(item) reEnt.RowMaxHorizon = max(allChildXList) reEnt.RowMinHorizon = min(allChildXList) reEnt.AllMaxHorizon = startX if startX > reEnt.RowMaxHorizon else reEnt.RowMaxHorizon return reEnt, AppReturnDTO(True)
def user_all_module(self, userId): db_ent = FaUser.query.filter(FaUser.ID == userId).first() if db_ent is not None: # 获取所有 选中的模块,没有隐藏的模块 roleIdList = [[x for x in item.fa_modules if x.IS_HIDE == 0] for item in db_ent.fa_roles if len(item.fa_modules) > 0] moduleList = list(numpy.array(roleIdList).flatten()) moduleList = sorted(moduleList, key=lambda x: x.SHOW_ORDER) moduleIdList = [item.ID for item in moduleList] moduleParentIdList = [ item.PARENT_ID for item in moduleList if item.PARENT_ID not in moduleIdList ] moduleParentList = FaModule.query.filter( FaModule.ID.in_(moduleParentIdList)).all() return moduleList + moduleParentList, AppReturnDTO(True) return None, AppReturnDTO(True)
def query_single_code(): j_data = request.json if j_data is None: return Fun.class_to_JsonStr(AppReturnDTO(False, "参数有误")) in_ent = PostBaseModel(j_data) _modele = QueryDal() re_ent, message = _modele.query_singleByCode(in_ent.Key) if message.IsSuccess: message.set_data(re_ent) return Fun.class_to_JsonStr(message)
def module_save(): j_data = request.json if j_data is None: return Fun.class_to_JsonStr(AppReturnDTO(False, "参数有误")) in_ent = RequestSaveModel(j_data) _modele = ModuleDal() re_ent, message = _modele.module_Save(in_dict=in_ent.Data, saveKeys=in_ent.SaveKeys) if message.IsSuccess: message.set_data(re_ent) return Fun.class_to_JsonStr(message)
def UserInfo_SingleByName(): ''' 根据用户名查询用户:RequestSaveModel对象,其中Data里包括name ''' j_data, message = Fun.post_to_dict(request) if j_data is None: return Fun.class_to_JsonStr(message) postEnt = RequestSaveModel(j_data) if postEnt is None or postEnt.Data is None: return Fun.class_to_JsonStr(AppReturnDTO(False, "参数有问题")) if "name" not in postEnt.Data or Fun.IsNullOrEmpty(postEnt.Data["name"]): return Fun.class_to_JsonStr(AppReturnDTO(False, "没有值")) dal = UserInfoDal() re_ent, message = dal.userInfo_SingleByName(postEnt.Data["name"]) if message.IsSuccess: message.set_data(re_ent) return json.dumps(Fun.convert_to_dict(message))
def ResetPassword(self, VerifyCode, LoginName, NewPwd): '重设置密码' checkOutPwd, msg = self.CheckOutVerifyCode(VerifyCode, LoginName) # 失败则退出 if not msg.IsSuccess or not checkOutPwd: return None, msg sql = "update fa_login set PASSWORD='******' where LOGIN_NAME='{0}'".format( LoginName, hashlib.md5(NewPwd.encode('utf-8')).hexdigest()) print(sql) resource = db.session.execute(sql) updateNum = resource.rowcount db.session.commit() db.session.close() if updateNum != 1: return None, AppReturnDTO(False, "影响数不为1") return None, AppReturnDTO(True, "成功")
def ApiUserInfoDelete(): ''' 重置密码:RequestSaveModel对象,其中Data里包括VerifyCode,LoginName、NewPwd ''' if g is None: return Fun.class_to_JsonStr(AppReturnDTO(False, "没有登录")) j_data, message = Fun.post_to_dict(request) if j_data is None: return Fun.class_to_JsonStr(message) in_ent = PostBaseModel(j_data) if Fun.IsNullOrEmpty(in_ent.Key): return Fun.class_to_JsonStr(AppReturnDTO(False, "参数有问题")) dal = UserInfoDal() delMode, message = dal.userInfo_delete(in_ent.Key) if message.IsSuccess: message.Data = delMode return Fun.class_to_JsonStr(message)