def sample32(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    formGuid = request.POST.get('form_guid')
    templateGuid = request.POST.get('template_guid')
    callbackUrl = request.POST.get('callbackUrl')
    basePath = request.POST.get('server_type')
    email = request.POST.get('email')
    message = ""
    # Checking clientId, privateKey and file_Id
    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
        return render_to_response('__main__:templates/sample32.pt',
                                  { 'error' : 'You do not enter all parameters' })

    #Get curent work directory
    currentDir = os.path.dirname(os.path.realpath(__file__))
    #Create text file
    fp = open(currentDir + '/../user_info.txt', 'w')
    #Write user info to text file
    fp.write(clientId + "\r\n" + privateKey + "\r\n" + email)
    fp.close()
    ####Create Signer, ApiClient and Storage Api objects

    #Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    #Create apiClient object
    apiClient = ApiClient(signer)
    #Create Storage Api object
    signatureApi = SignatureApi(apiClient)
    #Set base Path
    if basePath == "":
        basePath = "https://api.groupdocs.com/v2.0"
    signatureApi.basePath = basePath
    #Create webHook and set callback URL
    webHook = WebhookInfo()
    webHook.callbackUrl = callbackUrl
    ####Make a request to Signature API using clientId
    if formGuid != "":
        try:
            #Post form by entered form GUID
            postForm = signatureApi.PublishSignatureForm(clientId, formGuid, body=webHook)
            if postForm.status == "Ok":
                message = '<font color="green">Form is published successfully</font>'
                #Generate iframe url
                if basePath == "https://api.groupdocs.com/v2.0":
                    iframe = 'https://apps.groupdocs.com/signature2/forms/signembed/' + formGuid
                #iframe to dev server
                elif basePath == "https://dev-api.groupdocs.com/v2.0":
                    iframe = 'https://dev-apps.groupdocs.com/signature2/forms/signembed/' + formGuid
                #iframe to test server
                elif basePath == "https://stage-apps-groupdocs.dynabic.com/v2.0":
                    iframe = 'https://stage-apps-groupdocs.dynabic.com/signature2/forms/signembed/' + formGuid
                elif basePath == "http://realtime-api.groupdocs.com":
                    iframe = 'https://relatime-apps.groupdocs.com/signature2/forms/signembed/' + formGuid
                iframe = signer.signUrl(iframe)
            else:
                raise Exception(postForm.error_message)
        except Exception, e:
            return render_to_response('__main__:templates/sample32.pt',
                { 'error' : str(e) })
def sample36(request):
    clientId = request.POST.get("clientId")
    privateKey = request.POST.get("privateKey")
    basePath = request.POST.get("basePath")
    envelopeGuid = request.POST.get("envelopeGuid")
    # Checking clientId, privateKey and envelopeGuid
    if not clientId or not privateKey or not envelopeGuid:
        return render_to_response("__main__:templates/sample36.pt", dict(error="You do not enter all parameters"))

    ####Create Signer, ApiClient and Storage Api objects

    # Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    # Create apiClient object
    apiClient = ApiClient(signer)
    # Create Storage Api object
    signatureApi = SignatureApi(apiClient)
    if not basePath:
        # If base path empty set base path to the dev server
        basePath = "https://api.groupdocs.com/v2.0"
    signatureApi.basePath = basePath
    ####Make a request to Signature API using envelopeGuid

    try:
        ####Make a request to Storage Api for downloading file
        # Obtaining file stream of downloading file and definition of folder where to download file
        # Set path for local storage were to download file
        currentDir = os.path.dirname(os.path.realpath(__file__))
        newPath = currentDir + "/../templates/downloads/"
        # Create folder for downloads if not exist
        if not os.path.exists(newPath):
            os.makedirs(newPath)
        # Get envelop info
        envelopInfo = signatureApi.GetSignatureEnvelopeDocuments(clientId, envelopeGuid)
        if envelopInfo.status == "Ok":
            # Get document name from envelop info
            documentName = envelopInfo.result.documents[0].name
            # Get file stream for signed document from envelop
            getSignedFile = signatureApi.GetSignedEnvelopeDocuments(clientId, envelopeGuid)
            if getSignedFile:
                # Write file stream to file
                filePath = newPath + documentName
                with open(filePath, "wb") as fp:
                    shutil.copyfileobj(getSignedFile.inputStream, fp)
                # Result message with link to downloaded file for view in browser
                message = (
                    '<span style="color:green">Files from the envelope were downloaded to server\'s local folder. You can check them <a href="/downloads/'
                    + documentName
                    + '">here</a></span>'
                )
            else:
                raise Exception("Wrong envelop GUID!")
        else:
            raise Exception(envelopInfo.error_message)
    except Exception, e:
        return render_to_response("__main__:templates/sample36.pt", {"error": str(e)})
def sample44(request):
    clientId = request.POST.get('clientId')
    privateKey = request.POST.get('privateKey')
    inputFile = request.POST.get('file')
    basePath = request.POST.get('basePath')
    firstName = request.POST.get('firstName')
    gender = request.POST.get('gender')
    lastName = request.POST.get('lastName')
    firstEmail = request.POST.get('firstEmail')
    secondEmail = request.POST.get('secondEmail')
    fileGuId = None
    # Checking clientId and privateKey
    if not clientId or not privateKey or not firstEmail or not firstName or not secondEmail:
        return render_to_response('__main__:templates/sample44.pt',
                                  dict(error='Please enter all required data', url1=''))
    ####Create Signer, ApiClient and Storage Api objects
    #Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    #Create apiClient object
    apiClient = ApiClient(signer)
    #Create Storage Api object
    storage = StorageApi(apiClient)
    #Create AsyncApi object
    async = AsyncApi(apiClient)
    #Create MergeApi object
    merge = MergeApi(apiClient)
    #Create DocApi object
    doc = DocApi(apiClient)
    #Create Signature object
    signature = SignatureApi(apiClient)
    #Check is base path entered
    if not basePath:
        #If base path empty set base path to the dev server
        basePath = 'https://api.groupdocs.com/v2.0'
    #Set base path for api
    storage.basePath = basePath
    async.basePath = basePath
    merge.basePath = basePath
    doc.basePath = basePath
    signature.basePath = basePath
    #A hack to get uploaded file size
    inputFile.file.seek(0, 2)
    fileSize = inputFile.file.tell()
    inputFile.file.seek(0)
    fs = FileStream.fromStream(inputFile.file, fileSize)
    ####Make a request to Storage API using clientId
    try:
        #Upload file to current user storage
        upload = storage.Upload(clientId, inputFile.filename,  fs, overrideMode=0)
        if upload.status == "Ok":
            #Get file guid
            fileGuId = upload.result.guid
    except Exception, e:
        return render_to_response('__main__:templates/sample44.pt',
                                  dict(error=str(e), url1=''))
Example #4
0
def publish_callback(request):
    currentDir = os.path.dirname(os.path.realpath(__file__))
    if os.path.exists(currentDir + '/../user_info.txt'):
        f = open(currentDir + '/../user_info.txt', "r")
        lines = f.readlines()
        f.close()
        lineArray = []
        lineArray = lines[0].split()
        clientId = lineArray[0]
        privateKey = lineArray[1]
        email = lineArray[2]

    if IsNotNull(request.json_body):
        jsonPostData = request.json_body
        formId = jsonPostData['SourceId']
        #Create signer object
        signer = GroupDocsRequestSigner(privateKey)
        # Create apiClient object
        apiClient = ApiClient(signer)
        # Create AsyncApi object
        signature = SignatureApi(apiClient)
        # Create Storage object
        getFileFromForm = signature.PublicGetSignatureFormDocuments(formId)
        if getFileFromForm.status == "Ok":
            documentName = getFileFromForm.result.documents[0].name
            out = "*****@*****.**"
            to = email
            msg = MIMEMultipart('alternative')
            msg['Subject'] = "Link"
            msg['From'] = out
            msg['To'] = to
            html = """\
                <html>
                  <head></head>
                  <body>
                    <p>Document""" + documentName + """ is signed</p>
                  </body>
                </html>
                """
            body = MIMEText(html, 'html')
            msg.attach(body)
            s = smtplib.SMTP('localhost')
            s.sendmail(out, to, msg.as_string())
            s.quit()
def signature_callback(request):
    currentDir = os.path.dirname(os.path.realpath(__file__))
    if os.path.exists(currentDir + '/../user_info.txt'):
        f = open(currentDir + '/../user_info.txt')
        lines = f.readlines()
        f.close()
        clientId = lines[0].replace("\r\n", "")
        privateKey = lines[1]

    if IsNotNull(request.json_body):
        jsonPostData = request.json_body
        envelopId = jsonPostData['SourceId']
        # Create signer object
        signer = GroupDocsRequestSigner(privateKey)
        # Create apiClient object
        apiClient = ApiClient(signer)
        # Create AsyncApi object
        signature = SignatureApi(apiClient)
        # Create Storage object
        api = StorageApi(apiClient)
        if envelopId != '':
            time.sleep(5)
            print envelopId
            document = signature.GetSignatureEnvelopeDocuments(
                clientId, envelopId)
            if document.status == "Ok":
                guid = document.result.documents[0].documentId
                name = document.result.documents[0].name
                currentDir = os.path.dirname(os.path.realpath(__file__))
                downloadFolder = currentDir + '/../downloads/'
                if not os.path.isdir(downloadFolder):
                    os.makedirs(downloadFolder)

                #Downlaoding of file
                fs = api.GetFile(clientId, guid)

                if fs:

                    filePath = downloadFolder + name

                    with open(filePath, 'wb') as fp:
                        shutil.copyfileobj(fs.inputStream, fp)
            try:
                #Delete file from folder
                os.unlink(file_path)

            except Exception, e:
                print e
    ### Create Signer, ApiClient and Annotation Api objects

    # Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    # Create apiClient object
    apiClient = ApiClient(signer)
    # Create StorageApi object
    storage = StorageApi(apiClient)
    # Create SignatureApi object
    signature = SignatureApi(apiClient)
    docApi = DocApi(apiClient)
    mergeApi = MergeApi(apiClient)
    asyncApi = AsyncApi(apiClient)
    if basePath == "":
        basePath = 'https://api.groupdocs.com/v2.0'
    #Set base path
    storage.basePath = basePath
    signature.basePath = basePath
    docApi.basePath = basePath
    mergeApi.basePath = basePath
    asyncApi.basePath = basePath
    guid = fileId
    #Create list with entered data
    enteredData = {
        "email": email,
def sample40(request):
    clientId = request.POST.get('clientId')
    privateKey = request.POST.get('privateKey')
    formGuid = request.POST.get('formGuid')
    callbackUrl = request.POST.get('callbackUrl')
    basePath = request.POST.get('basePath')
    # Checking clientId, privateKey and form GUID
    if not clientId or not privateKey or not formGuid:
        return render_to_response('__main__:templates/sample40.pt',
                                  dict(error='You do not enter all parameters'))

    #Get current work directory
    currentDir = os.path.dirname(os.path.realpath(__file__))
    #Create temporary text file
    fp = open(currentDir + '/../user_info.txt', 'w')
    #Write user info to text file
    fp.write(clientId + "\r\n" + privateKey)
    fp.close()
    #Check is temporary file with callback info is exist
    if os.path.exists(currentDir + '/../callback_info.txt'):
        #If exist delete it
        os.remove(currentDir + '/../callback_info.txt')
    ####Create Signer, ApiClient and Storage Api objects
    #Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    #Create apiClient object
    apiClient = ApiClient(signer)
    #Create Storage Api object
    signatureApi = SignatureApi(apiClient)
    #Set base Path
    if not basePath:
        basePath = "https://api.groupdocs.com/v2.0"
    signatureApi.basePath = basePath
    #Create webHook and set callback URL
    webHook = WebhookInfo()
    webHook.callbackUrl = callbackUrl
    ####Make a request to Signature API using clientId
    #create random number
    rand = random.randint(0, 500)
    #Create string variable with new form name
    formName = 'test' + str(rand)
    try:
        #Copy form
        createForm = signatureApi.CreateSignatureForm(clientId, name=formName, formGuid=formGuid)
        if createForm.status == "Ok":
            try:
                #Publish created form
                postForm = signatureApi.PublishSignatureForm(clientId, createForm.result.form.id, body=webHook)
                if postForm.status == "Ok":
                    message = '<font color="green">Form is published successfully</font>'
                    iframe = None
                    #Generate iframe url
                    if basePath == "https://api.groupdocs.com/v2.0":
                        iframe = 'https://apps.groupdocs.com/signature2/forms/signembed/' + \
                                 createForm.result.form.id
                    #iframe to dev server
                    elif basePath == "https://dev-api-groupdocs.dynabic.com/v2.0":
                        iframe = 'https://dev-apps-groupdocs.dynabic.com/signature2/forms/signembed/' + \
                                 createForm.result.form.id
                    #iframe to test server
                    elif basePath == "https://stage-apps-groupdocs.dynabic.com/v2.0":
                        iframe = 'https://stage-apps-groupdocs.dynabic.com/signature2/forms/signembed/' + \
                                 createForm.result.form.id
                    elif basePath == "http://realtime-api-groupdocs.dynabic.com":
                        iframe = 'https://relatime-apps-groupdocs.dynabic.com/signature2/forms/signembed/' + \
                                 createForm.result.form.id
                    iframe = signer.signUrl(iframe)
                else:
                    raise Exception(postForm.error_message)
            except Exception, e:
                return render_to_response('__main__:templates/sample40.pt',
                                          dict(error=str(e)))
        else:
Example #8
0
def sample06(request):
    if request.content_type != 'application/json':
        return render_to_response('__main__:templates/sample06.pt', {})
        #Request to json

    jsonPostData = request.json_body
    #    import pdb; pdb.set_trace()
    #Get parameters
    clientId = jsonPostData["userId"]
    privateKey = jsonPostData["privateKey"]
    documents = jsonPostData['documents']
    signers = jsonPostData['signers']

    #Checking parameters

    if IsNotNull(clientId) == False or IsNotNull(
            privateKey) == False or IsNotNull(documents) == False or IsNotNull(
                signers) == False:
        return render_to_response(
            '__main__:templates/sample06.pt',
            {'error': 'You do not enter you User id or Private key'})
        #Determination of placeSignatureOn parameter
    for i, signer in enumerate(signers):
        signers[i]['placeSignatureOn'] = ''
        ####Create Signer, ApiClient and Storage Api objects

    #Create signer object
    signerReq = GroupDocsRequestSigner(privateKey)
    #Create apiClient object
    apiClient = ApiClient(signerReq)
    #Create Signsture API object
    signatureApi = SignatureApi(apiClient)
    #Create setting variable for signature SignDocument method
    settings = SignatureSignDocumentSettingsInfo()
    settings.documents = documents
    settings.signers = signers
    ####Make a request to Signature Api for sign document
    #Sign document using current user id and sign settings
    response = signatureApi.SignDocument(clientId, body=settings)

    #If request was successfull - set variables for template
    error = ''
    if response.status == 'Ok':
        time.sleep(5)
        getDocumentStatus = signatureApi.GetSignDocumentStatus(
            clientId, response.result.jobId)
        if getDocumentStatus.status == "Ok":

            guid = getDocumentStatus.result.documents[0].documentId
            iframe = 'https://apps.groupdocs.com/document-viewer/embed/' + guid
            iframe = signerReq.signUrl(iframe)
            return_data = json.dumps({'responseCode': 200, 'url': iframe})
            return Response(body=return_data, content_type='application/json')
        else:
            error = getDocumentStatus.error_message
            return render_to_response('__main__:templates/sample06.pt',
                                      {'error': response.error_message})
    else:
        error = response.error_message
        return render_to_response('__main__:templates/sample06.pt',
                                  {'error': response.error_message})
            try:
                #Delete file from folder
                os.unlink(file_path)

            except Exception, e:
                print e
                ### Create Signer, ApiClient and Annotation Api objects

    # Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    # Create apiClient object
    apiClient = ApiClient(signer)
    # Create StorageApi object
    storage = StorageApi(apiClient)
    # Create SignatureApi object
    signature = SignatureApi(apiClient)
    if not basePath:
        basePath = 'https://api.groupdocs.com/v2.0'
        #Set base path
    storage.basePath = basePath
    signature.basePath = basePath
    if url:
        try:
            # Upload file to current user storage using entered URl to the file
            upload = storage.UploadWeb(clientId, url)
            guid = upload.result.guid
            try:
                ####Make a request to Storage API using clientId

                #Obtaining all Entities from current user
                files = storage.ListEntities(userId=clientId, path='My Web Documents', pageIndex=0)
Example #10
0
def sample32(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    formGuid = request.POST.get('form_guid')
    templateGuid = request.POST.get('template_guid')
    callbackUrl = request.POST.get('callbackUrl')
    basePath = request.POST.get('server_type')
    email = request.POST.get('email')
    message = ""
    # Checking clientId, privateKey and file_Id
    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
        return render_to_response('__main__:templates/sample32.pt',
                                  {'error': 'You do not enter all parameters'})

    #Get curent work directory
    currentDir = os.path.dirname(os.path.realpath(__file__))
    #Create text file
    fp = open(currentDir + '/../user_info.txt', 'w')
    #Write user info to text file
    fp.write(clientId + "\r\n" + privateKey + "\r\n" + email)
    fp.close()
    ####Create Signer, ApiClient and Storage Api objects

    #Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    #Create apiClient object
    apiClient = ApiClient(signer)
    #Create Storage Api object
    signatureApi = SignatureApi(apiClient)
    #Set base Path
    if basePath == "":
        basePath = "https://api.groupdocs.com/v2.0"
    signatureApi.basePath = basePath
    #Create webHook and set callback URL
    webHook = WebhookInfo()
    webHook.callbackUrl = callbackUrl
    ####Make a request to Signature API using clientId
    if formGuid != "":
        try:
            #Post form by entered form GUID
            postForm = signatureApi.PublishSignatureForm(clientId,
                                                         formGuid,
                                                         body=webHook)
            if postForm.status == "Ok":
                message = '<font color="green">Form is published successfully</font>'
                #Generate iframe url
                if basePath == "https://api.groupdocs.com/v2.0":
                    iframe = 'https://apps.groupdocs.com/signature2/forms/signembed/' + formGuid
                #iframe to dev server
                elif basePath == "https://dev-api.groupdocs.com/v2.0":
                    iframe = 'https://dev-apps.groupdocs.com/signature2/forms/signembed/' + formGuid
                #iframe to test server
                elif basePath == "https://stage-apps-groupdocs.dynabic.com/v2.0":
                    iframe = 'https://stage-apps-groupdocs.dynabic.com/signature2/forms/signembed/' + formGuid
                elif basePath == "http://realtime-api.groupdocs.com":
                    iframe = 'https://relatime-apps.groupdocs.com/signature2/forms/signembed/' + formGuid
                iframe = signer.signUrl(iframe)
            else:
                raise Exception(postForm.error_message)
        except Exception, e:
            return render_to_response('__main__:templates/sample32.pt',
                                      {'error': str(e)})
Example #11
0
            try:
                #Delete file from folder
                os.unlink(file_path)

            except Exception, e:
                print e
    ### Create Signer, ApiClient and Annotation Api objects

    # Create signer object
    signer = GroupDocsRequestSigner(privateKey)
    # Create apiClient object
    apiClient = ApiClient(signer)
    # Create StorageApi object
    storage = StorageApi(apiClient)
    # Create SignatureApi object
    signature = SignatureApi(apiClient)
    if basePath == "":
        basePath = 'https://api.groupdocs.com/v2.0'
        #Set base path
    storage.basePath = basePath
    signature.basePath = basePath
    if url != "":
        try:
            # Upload file to current user storage using entere URl to the file
            upload = storage.UploadWeb(clientId, url)
            guid = upload.result.guid
            try:
                ####Make a request to Storage API using clientId

                #Obtaining all Entities from current user
                files = storage.ListEntities(userId=clientId,