示例#1
0
def updUserRole():
    myRes = MyResponse()
    ROLE_KEYS = MyRequest.getList("ROLE_KEYS[]")
    USER_KEY = MyRequest.get("USER_KEY", type=int)
    try:
        db_session.begin_nested()
        db_session.query(UserRole).filter(
            UserRole.USER_KEY == USER_KEY).delete()
        for key in ROLE_KEYS:
            userRole = UserRole()
            userRole.USER_KEY = USER_KEY
            userRole.ROLE_KEY = key
            db_session.add(userRole)
        db_session.commit()
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        db_session.rollback()
        mylog.error(ex)
        myRes.msg = str(ex)
    finally:
        db_session.close()
    return myRes.to_json()
def delete():
    myRes = MyResponse()
    ROLE_KEY = MyRequest.get("ROLE_KEY", type=int)
    try:
        MySqlalchemy.comDel(RoleInfo, [RoleInfo.ROLE_KEY == ROLE_KEY])
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        db_session.rollback()
        mylog.error(ex)
        myRes.msg = str(ex)
    finally:
        db_session.close()
    return myRes.to_json()
示例#3
0
def resetMyPwd():
    myRes = MyResponse()
    FuserId = g.USER_KEY
    FoldPwd = MyRequest.get_verify_empty("FoldPwd", errmsg="旧密码不能为空")
    FnewPwd = MyRequest.get_verify_empty("FnewPwd", errmsg="新密码不能为空")
    FnewPwdOk = MyRequest.get("FnewPwdOk", type=str)
    try:
        if FnewPwd != FnewPwdOk:
            return myRes.to_json_msg("新旧密码不一致")
        userInfo = db_session.query(UserInfo).filter(
            UserInfo.USER_KEY == FuserId).one()
        if not userInfo.check_password(userInfo.USER_PWD, FoldPwd):
            return myRes.to_json_msg("旧密码错误,请重新输入")
        userInfo.set_password(FnewPwd)
        db_session.commit()
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    finally:
        db_session.close()
    return myRes.to_json()
示例#4
0
def getRoleListByUserKey():
    myRes = MyResponse()
    USER_KEY = MyRequest.get("USER_KEY", type=int)
    try:
        clomns = [UserRole.USER_KEY, RoleInfo.ROLE_NAME, UserRole.ROLE_KEY]
        query_data = db_session.query(*clomns).outerjoin(
            RoleInfo, RoleInfo.ROLE_KEY == UserRole.ROLE_KEY).filter(
                UserRole.USER_KEY == USER_KEY)
        myRes.data = MySqlalchemy.convertToList(query_data)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    return myRes.to_json()
def getRoleMenuAndOperList():
    myRes = MyResponse()
    ROLE_KEY = MyRequest.get("ROLE_KEY", type=int)
    try:
        query_data = db_session.query(RolePermission.ROLE_KEY,
                                      RolePermission.RESOURCE_KEY,
                                      RolePermission.RESOURCE_TYPE).filter(
                                          RolePermission.ROLE_KEY == ROLE_KEY)
        myRes.data = MySqlalchemy.convertToList(query_data)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    return myRes.to_json()
示例#6
0
def resetPwdByUserKey():
    myRes = MyResponse()
    USER_KEY = MyRequest.get("USER_KEY", type=int)
    try:
        q_model = db_session.query(UserInfo).filter(
            UserInfo.USER_KEY == USER_KEY).one()
        q_model.set_password("123456")
        db_session.commit()
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    finally:
        db_session.close()
    return myRes.to_json()
示例#7
0
def delete():
    myRes = MyResponse()
    DPT_KEY = MyRequest.get_verify_empty("DPT_KEY", errmsg="ID不能为空")
    try:
        rows = db_session.query(DptInfo).filter(DptInfo.DPT_KEY.like(DPT_KEY+"%")).delete(synchronize_session=False)
        db_session.commit()
        if rows < 1:
            raise SQLAlchemyError("操作失败")
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = ResState.ERROR_DB
    finally:
        db_session.close()
    return myRes.to_json()
示例#8
0
def getDetail():
    myRes = MyResponse()
    USER_KEY = MyRequest.get("USER_KEY", type=int)
    try:
        columns = [
            UserInfo.USER_KEY, UserInfo.DPT_KEY, UserInfo.USER_NAME,
            UserInfo.LOGIN_NAME, UserInfo.USER_SEX, UserInfo.USER_POSITION,
            UserInfo.PHONE, UserInfo.TIME_CREATE, UserRole.ROLE_KEY
        ]
        dict_user = MySqlalchemy.get_detail(
            columns,
            outerjoins=[UserRole, UserRole.USER_KEY == UserInfo.USER_KEY],
            filters=[UserInfo.USER_KEY == USER_KEY])
        myRes.code = ResState.HTTP_SUCCESS
        myRes.data = dict_user
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    return myRes.to_json()
示例#9
0
 def wrapper(*args, **kargs):
     responseInfo = func()
     ###操作成功后,记录操作日志
     if json.loads(responseInfo.data)["code"] == ResState.HTTP_SUCCESS:
         try:
             logOper = LogOper()
             logOper.USER_KEY = g.USER_KEY
             logOper.IP_ADDRESS = request.remote_addr
             logOper.LOGO_FUNC = "function(name=%s,args=%s,kargs=%s)" % (
                 func.__name__, args, kargs)
             logOper.LOGO_REQ_PARAMS = json.dumps(MyRequest.getAll())
             logOper.TIME_CREATE = getSysDateTime()
             logOper.DESCRIPT = oper_descript
             try:
                 MySqlalchemy.comAdd(logOper)
             except SQLAlchemyError as ex:
                 mylog.error(ex)
         except:
             print(sys.exc_info())
             pass
     return responseInfo
示例#10
0
def delete():
    myRes = MyResponse()
    OPER_KEY = MyRequest.get_verify_empty("OPER_KEY", errmsg="OPER_KEY不能为空")
    try:
        db_session.begin_nested()
        ###删除按钮相关的角色权限信息
        db_session.query(RolePermission).filter(
            RolePermission.RESOURCE_TYPE == 1).filter(
                RolePermission.RESOURCE_KEY.like(OPER_KEY + "%")).delete(
                    synchronize_session=False)
        ###删除按钮信息
        db_session.query(OperInfo).filter(
            OperInfo.OPER_KEY.like(OPER_KEY +
                                   "%")).delete(synchronize_session=False)
        db_session.commit()
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        db_session.rollback()
        mylog.error(ex)
        myRes.msg = str(ex)
    finally:
        db_session.close()
    return myRes.to_json()
示例#11
0
def update():
    myRes = MyResponse()
    USER_KEY = MyRequest.get("USER_KEY", type=int)
    upd_attr = {}
    upd_attr["USER_NAME"] = MyRequest.get_verify_empty("USER_NAME",
                                                       errmsg="姓名不能为空")
    upd_attr["USER_SEX"] = MyRequest.get("USER_SEX", type=int, default=1)
    upd_attr["DPT_KEY"] = MyRequest.get_verify_empty("DPT_KEY",
                                                     errmsg="部门ID不能为空")
    upd_attr["USER_POSITION"] = MyRequest.get("USER_POSITION", type=str)
    upd_attr["PHONE"] = MyRequest.get("PHONE", type=str)
    upd_attr["TIME_MODIFY"] = getSysDateTime()
    try:
        MySqlalchemy.comUpdate(UserInfo, [UserInfo.USER_KEY == USER_KEY],
                               upd_attr)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = str(ex)
    return myRes.to_json()
示例#12
0
def add():
    myRes = MyResponse()
    user = UserInfo()
    user.LOGIN_NAME = MyRequest.get_verify_empty("LOGIN_NAME",
                                                 errmsg="用户名不能为空")
    user.USER_NAME = MyRequest.get_verify_empty("USER_NAME", errmsg="姓名不能为空")
    user.USER_SEX = MyRequest.get("USER_SEX", type=int)
    user.DPT_KEY = MyRequest.get_verify_empty("DPT_KEY", errmsg="DPT_KEY不能为空")
    user.set_password("123456")
    user.USER_POSITION = MyRequest.get("USER_POSITION", type=str)
    user.PHONE = MyRequest.get("PHONE", type=str)
    user.TIME_CREATE = getSysDateTime()
    user.TIME_MODIFY = getSysDateTime()
    try:
        MySqlalchemy.comAdd(user)
        myRes.code = ResState.HTTP_SUCCESS
        myRes.msg = "操作成功"
    except SQLAlchemyError as ex:
        mylog.error(ex)
        myRes.msg = ResState.ERROR_DB
    return myRes.to_json()