def RetrieveAllEntity(**argd):
     """
     Restful API for getting all entities in the COrgan, ONLY USE BY NAME SERVICE.
     :param argd: request argument dictionary
     :return: dumped json string
     """
     checkSign = argd["nsid"] + "," + argd["renid"]
     token = EncryptUtil.DecodeURLSafeBase64(argd["token"])
     try:
         tokenRet = EncryptUtil.VerifySign(
             checkSign, token,
             GlobalConfigContext.AUTH_NameService_PublicKey)
     except:
         tokenRet = False
     if tokenRet is False:
         return CGateway._UnauthorizedServiceResponse(token)
     flag1, ret1 = CGateway.core.RetrieveAllHuman(
         GlobalConfigContext.AUTH_INTERNAL_SESSION)
     flag2, ret2 = CGateway.core.RetrieveAllAgent(
         GlobalConfigContext.AUTH_INTERNAL_SESSION)
     flag3, ret3 = CGateway.core.RetrieveAllGroup(
         GlobalConfigContext.AUTH_INTERNAL_SESSION)
     flag4, ret4 = CGateway.core.RetrieveAllPosition(
         GlobalConfigContext.AUTH_INTERNAL_SESSION)
     flag5, ret5 = CGateway.core.RetrieveAllCapabilities(
         GlobalConfigContext.AUTH_INTERNAL_SESSION)
     retDict = dict()
     retDict["human"] = ret1
     retDict["agent"] = ret2
     retDict["group"] = ret3
     retDict["position"] = ret4
     retDict["capability"] = ret5
     return CGateway._DumpResponse(retDict)
 def RetrieveDataVersionGid(**argd):
     """
     Restful API for getting data version of COrgan, ONLY USE BY NAME SERVICE.
     :param argd: request argument dictionary
     :return: dumped json string
     """
     checkSign = argd["nsid"] + "," + argd["renid"]
     token = EncryptUtil.DecodeURLSafeBase64(argd["token"])
     try:
         tokenRet = EncryptUtil.VerifySign(
             checkSign, token,
             GlobalConfigContext.AUTH_NameService_PublicKey)
     except:
         tokenRet = False
     if tokenRet is False:
         return CGateway._UnauthorizedServiceResponse(token)
     flag1, ret1 = CGateway.core.GetCurrentDataVersion(
         GlobalConfigContext.AUTH_INTERNAL_SESSION)
     flag2, ret2 = CGateway.core.GetOrganizationId(
         GlobalConfigContext.AUTH_INTERNAL_SESSION)
     xFlag = CGateway._HandleExceptionAndUnauthorized(
         flag1 & flag2, ret1, GlobalConfigContext.AUTH_INTERNAL_SESSION)
     if xFlag is not None:
         return xFlag
     return CGateway._DumpResponse("%s,%s" % (ret1, ret2))
def performAddPlatformUser():
    from Utility.EncryptUtil import EncryptUtil
    flag, res = core.PlatformUserAdd(
        session['SID'], request.form['f_username'],
        EncryptUtil.EncryptSHA256(request.form['f_nPassword']),
        1 if request.form['f_level'] == u"管理员" else 0)
    if (flag & res) is False:
        return redirect(url_for('AccessErrorPage', dt='add'))
    return redirect(url_for('userManagement'))
 def RetrieveWorkerEntityByGid(**argd):
     """
     Restful API for getting a list of worker entity, ONLY USE BY NAME SERVICE.
     :param argd: request argument dictionary
     :return: dumped json string
     """
     checkSign = argd["nsid"] + "," + argd["renid"]
     token = EncryptUtil.DecodeURLSafeBase64(argd["token"])
     try:
         tokenRet = EncryptUtil.VerifySign(
             checkSign, token,
             GlobalConfigContext.AUTH_NameService_PublicKey)
     except:
         tokenRet = False
     if tokenRet is False:
         return CGateway._UnauthorizedServiceResponse(token)
     flag, ret = CGateway.core.RetrieveWorkersEntity(
         GlobalConfigContext.AUTH_INTERNAL_SESSION, argd["gids"])
     return CGateway._DumpResponse(ret)
Beispiel #5
0
 def Auth(username, rawPassword):
     """
     Get authorization token by username and password
     :param username: unique username string, in pattern of username@domain
     :param rawPassword: password without encryption
     :return:
     """
     retVal = SessionManager.Login(username,
                                   EncryptUtil.EncryptSHA256(rawPassword))
     return retVal is not None, retVal
def performEditPlatformUser():
    pwd = None
    if request.form['f_nPassword'] != "":
        from Utility.EncryptUtil import EncryptUtil
        pwd = EncryptUtil.EncryptSHA256(request.form['f_nPassword'])
    flag, res = core.PlatformUserUpdate(
        session['SID'], request.form['h_username'], pwd,
        1 if request.form['f_level'] == u"管理员" else 0)
    if flag is False:
        return redirect(url_for('AccessErrorPage', dt='x'))
    return redirect(url_for('userManagement'))
 def RetrieveWorkerInCapability(**argd):
     """
     Restful API for getting a set of workers that a specific capability contains, ONLY USE BY NAME SERVICE.
     :param argd: request argument dictionary
     :return: dumped json string
     """
     checkSign = argd["nsid"] + "," + argd["renid"]
     token = EncryptUtil.DecodeURLSafeBase64(argd["token"])
     try:
         tokenRet = EncryptUtil.VerifySign(
             checkSign, token,
             GlobalConfigContext.AUTH_NameService_PublicKey)
     except:
         tokenRet = False
     if tokenRet is False:
         return CGateway._UnauthorizedServiceResponse(token)
     flag1, ret1 = CGateway.core.RetrieveHumanWithCapability(
         GlobalConfigContext.AUTH_INTERNAL_SESSION, argd["capabilityName"])
     flag2, ret2 = CGateway.core.RetrieveAgentWithCapability(
         GlobalConfigContext.AUTH_INTERNAL_SESSION, argd["capabilityName"])
     return CGateway._DumpResponse(ret1 + ret2)
 def RetrieveAllConnection(**argd):
     """
     Restful API for getting all connections in the COrgan, ONLY USE BY NAME SERVICE.
     :param argd: request argument dictionary
     :return: dumped json string
     """
     checkSign = argd["nsid"] + "," + argd["renid"]
     token = EncryptUtil.DecodeURLSafeBase64(argd["token"])
     try:
         tokenRet = EncryptUtil.VerifySign(
             checkSign, token,
             GlobalConfigContext.AUTH_NameService_PublicKey)
     except:
         tokenRet = False
     if tokenRet is False:
         return CGateway._UnauthorizedServiceResponse(token)
     flag, ret = CGateway.core.RetrieveAllConnection(
         GlobalConfigContext.AUTH_INTERNAL_SESSION)
     xFlag = CGateway._HandleExceptionAndUnauthorized(
         flag, ret, GlobalConfigContext.AUTH_INTERNAL_SESSION)
     if xFlag is not None:
         return xFlag
     return CGateway._DumpResponse(ret)
 def Connect(**argd):
     """
     Restful API for authority connection.
     :param argd: request argument dictionary
     :return: dumped json string
     """
     flag, ret = CController.CController.Connect(
         argd["username"], EncryptUtil.EncryptSHA256(argd["password"]))
     if flag is False:
         return CGateway._ExceptionResponse()
     if ret is None:
         return CGateway._FailureResponse(
             {"return": "invalid user id or password"})
     return CGateway._SuccessResponse({"session": ret})
def performLogin():
    if request.method == 'GET':
        return redirect(url_for('Login'))
    usrId = request.form["passedUserId"]
    usrPwd = request.form["passedUserPwd"]
    import re
    if re.match('^[A-Za-z0-9@.]+$', usrId) is None:
        return redirect(url_for('Login2'))
    from Utility.EncryptUtil import EncryptUtil
    usrPwd = EncryptUtil.EncryptSHA256(usrPwd)
    flag, ret = core.Connect(usrId, usrPwd)
    if flag is False or ret is None:
        return redirect(url_for('Login2'))
    session['AuID'] = usrId
    session['SID'] = ret
    session['AuType'] = 1 if core.AmIAdmin(ret)[1] is True else 0
    return redirect(url_for('home'))