Skip to content

Commit f6131d0

Browse files
committed
2 parents ba2b457 + fa35503 commit f6131d0

24 files changed

+660
-113
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const {
2929
eg016, eg017, eg018, eg019, eg020, eg022, eg023,
3030
eg024, eg025, eg026, eg027, eg028, eg029, eg030,
3131
eg031, eg032, eg033, eg034, eg035, eg036, eg037,
32-
eg038, eg039, eg040
32+
eg038, eg039, eg040, eg041
3333
} = require("./lib/eSignature/controllers");
3434

3535
const {
@@ -274,6 +274,8 @@ if (examplesApi.examplesApi.isRoomsApi) {
274274
.post('/eg039', eg039.createController)
275275
.get('/eg040', eg040.getController)
276276
.post('/eg040', eg040.createController)
277+
.get('/eg041', eg041.getController)
278+
.post('/eg041', eg041.createController)
277279
}
278280

279281
function dsLoginCB1(req, res, next) { req.dsAuthCodeGrant.oauth_callback1(req, res, next) }

lib/DSAuthCodeGrant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ DSAuthCodeGrant.prototype.oauth_callback2 = function _oauth_callback2(req, res,
119119
let eg = req.session.eg;
120120
req.session.eg = null;
121121
res.redirect(`/${eg}`);
122+
} else if (dsConfig.quickstart == "true") {
123+
res.redirect('/eg001')
122124
} else {res.redirect('/')}
123125
}
124126

lib/commonControllers.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
* @author DocuSign
55
*/
66

7+
const { utils } = require('mocha');
8+
const { rawListeners } = require('process');
9+
const { isCFR } = require('./utils.js');
10+
711
const fs = require('fs')
812
, dsConfig = require('../config/appsettings.json')
913
, examplesApi = require('../config/examplesAPI.json')
14+
, docusign = require('docusign-esign')
1015
, documentationTopic = 'auth-code-grant-node'
1116
;
1217

@@ -15,7 +20,7 @@ const commonControllers = exports;
1520
/**
1621
* Home page for this application
1722
*/
18-
commonControllers.indexController = (req, res) => {
23+
commonControllers.indexController = async (req, res) => {
1924
if (dsConfig.quickstart == 'true' && req.user == undefined) {
2025
console.debug ('quickstart mode on');
2126
return res.redirect('/eg001');
@@ -27,6 +32,17 @@ commonControllers.indexController = (req, res) => {
2732
showDoc: dsConfig.documentation
2833
});
2934
}
35+
else if (req.dsAuth.checkToken(3)){
36+
let enableCFR = await isCFR(req.user.accessToken, req.session.accountId, req.session.basePath);
37+
if (enableCFR == "enabled"){
38+
res.locals.statusCFR = "enabled";
39+
}
40+
res.render('pages/index', {
41+
title: "Home",
42+
documentation: dsConfig.documentation + documentationTopic,
43+
showDoc: dsConfig.documentation
44+
});
45+
}
3046
else {
3147
res.render('pages/index', {
3248
title: "Home",
@@ -37,8 +53,9 @@ commonControllers.indexController = (req, res) => {
3753
}
3854

3955
commonControllers.mustAuthenticateController = (req, res) => {
40-
if (dsConfig.quickstart == 'true')
56+
if (dsConfig.quickstart == 'true') {
4157
res.redirect('login');
58+
}
4259
else if (examplesApi.examplesApi.isMonitorApi) {
4360
// Monitor API supports JWT only
4461
req.dsAuth = req.dsAuthJwt;

lib/eSignature/controllers/eg001EmbeddedSigning.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
const validator = require("validator");
1010
const { getExampleByNumber } = require("../../manifestService");
1111
const dsConfig = require("../../../config/index.js").config;
12+
const { isCFR } = require('../../utils.js');
1213

1314
const eg001EmbeddedSigning = exports;
1415
const exampleNumber = 1;
@@ -79,7 +80,7 @@
7980
/**
8081
* Form page for this application
8182
*/
82-
eg001EmbeddedSigning.getController = (req, res) => {
83+
eg001EmbeddedSigning.getController = async (req, res) => {
8384
console.log(req.dsAuth);
8485
// Check that the authentication token is ok with a long buffer time.
8586
// If needed, now is the best time to ask the user to authenticate
@@ -90,9 +91,16 @@
9091
req.dsAuth.setEg(req, eg);
9192
return res.redirect(mustAuthenticate);
9293
}
94+
95+
let enableCFR = await isCFR(req.user.accessToken, req.session.accountId, req.session.basePath);
96+
if (enableCFR == "enabled"){
97+
res.locals.statusCFR = "enabled";
98+
}
9399

94100
const example = getExampleByNumber(res.locals.manifest, exampleNumber);
95-
if (res.locals.quickACG) {
101+
if (res.locals.quickACG && res.locals.statusCFR == "enabled") {
102+
res.redirect('/eg041');
103+
} else if (res.locals.quickACG) {
96104
res.render("pages/examples/quickEmbeddedSigning", {
97105
eg: eg,
98106
csrfToken: req.csrfToken(),
@@ -104,6 +112,12 @@
104112
documentation: dsConfig.documentation + eg,
105113
showDoc: dsConfig.documentation,
106114
});
115+
} else if (res.locals.statusCFR == "enabled" && dsConfig.quickstart == "true") {
116+
res.redirect('/eg041');
117+
} else if (res.locals.statusCFR == "enabled") {
118+
res.render('pages/invalid_with_cfr', {
119+
title: "Not CFR Part 11 compatible"
120+
});
107121
} else {
108122
res.render("pages/examples/eg001EmbeddedSigning", {
109123
eg: eg,

lib/eSignature/controllers/eg014CollectPayment.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { createEnvelopeWithPayment } = require('../examples/collectPayment');
99
const validator = require('validator');
1010
const { getExampleByNumber } = require("../../manifestService");
1111
const dsConfig = require('../../../config/index.js').config;
12-
const { formatString } = require('../../utils.js');
12+
const { formatString, isCFR } = require('../../utils.js');
1313

1414
const eg014CollectPayment = exports;
1515
const exampleNumber = 14;
@@ -85,7 +85,7 @@ eg014CollectPayment.createController = async (req, res) => {
8585
/**
8686
* Form page for this application
8787
*/
88-
eg014CollectPayment.getController = (req, res) => {
88+
eg014CollectPayment.getController = async (req, res) => {
8989
// Check that the authentication token is ok with a long buffer time.
9090
// If needed, now is the best time to ask the user to authenticate
9191
// since they have not yet entered any information into the form.
@@ -96,15 +96,26 @@ eg014CollectPayment.getController = (req, res) => {
9696
return res.redirect(mustAuthenticate);
9797
}
9898

99+
let enableCFR = await isCFR(req.user.accessToken, req.session.accountId, req.session.basePath);
100+
if (enableCFR == "enabled"){
101+
res.locals.statusCFR = "enabled";
102+
}
103+
99104
const example = getExampleByNumber(res.locals.manifest, exampleNumber);
100105
const sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
101-
res.render('pages/examples/eg014CollectPayment', {
102-
eg: eg, csrfToken: req.csrfToken(),
103-
example: example,
104-
gatewayOk: dsConfig.gatewayAccountId && dsConfig.gatewayAccountId.length > 25,
105-
sourceFile: sourceFile,
106-
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/examples/' + sourceFile,
107-
documentation: dsConfig.documentation + eg,
108-
showDoc: dsConfig.documentation
109-
});
106+
if (res.locals.statusCFR == "enabled") {
107+
res.render('pages/invalid_with_cfr', {
108+
title: "Not CFR Part 11 compatible"
109+
});
110+
} else {
111+
res.render('pages/examples/eg014CollectPayment', {
112+
eg: eg, csrfToken: req.csrfToken(),
113+
example: example,
114+
gatewayOk: dsConfig.gatewayAccountId && dsConfig.gatewayAccountId.length > 25,
115+
sourceFile: sourceFile,
116+
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/examples/' + sourceFile,
117+
documentation: dsConfig.documentation + eg,
118+
showDoc: dsConfig.documentation
119+
});
120+
}
110121
}

lib/eSignature/controllers/eg020PhoneAuthentication.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { phoneAuthentication } = require('../examples/phoneAuthentication');
99
const validator = require('validator');
1010
const { getExampleByNumber } = require("../../manifestService");
1111
const dsConfig = require('../../../config/index.js').config;
12-
const { formatString } = require('../../utils.js');
12+
const { formatString, isCFR } = require('../../utils.js');
1313

1414
const eg020PhoneAuthentication = exports;
1515
const exampleNumber = 20;
@@ -93,7 +93,7 @@ eg020PhoneAuthentication.createController = async (req, res) => {
9393
/**
9494
* Form page for this application
9595
*/
96-
eg020PhoneAuthentication.getController = (req, res) => {
96+
eg020PhoneAuthentication.getController = async (req, res) => {
9797
// Check that the authentication token is ok with a long buffer time.
9898
// If needed, now is the best time to ask the user to authenticate
9999
// since they have not yet entered any information into the form.
@@ -104,13 +104,24 @@ eg020PhoneAuthentication.getController = (req, res) => {
104104
return res.redirect(mustAuthenticate);
105105
}
106106

107+
let enableCFR = await isCFR(req.user.accessToken, req.session.accountId, req.session.basePath);
108+
if (enableCFR == "enabled"){
109+
res.locals.statusCFR = "enabled";
110+
}
111+
107112
const example = getExampleByNumber(res.locals.manifest, exampleNumber);
108-
res.render('pages/examples/eg020PhoneAuthentication', {
109-
eg: eg, csrfToken: req.csrfToken(),
110-
example: example,
111-
sourceFile: path.basename(__filename),
112-
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/' + path.basename(__filename),
113-
documentation: dsConfig.documentation + eg,
114-
showDoc: dsConfig.documentation
115-
});
113+
if (res.locals.statusCFR == "enabled") {
114+
res.render('pages/invalid_with_cfr', {
115+
title: "Not CFR Part 11 compatible"
116+
});
117+
} else {
118+
res.render('pages/examples/eg020PhoneAuthentication', {
119+
eg: eg, csrfToken: req.csrfToken(),
120+
example: example,
121+
sourceFile: path.basename(__filename),
122+
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/' + path.basename(__filename),
123+
documentation: dsConfig.documentation + eg,
124+
showDoc: dsConfig.documentation
125+
});
126+
}
116127
}

lib/eSignature/controllers/eg032PauseSignatureWorkflow.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { pauseSignatureWorkflow } = require("../examples/pauseSignatureWorkflow")
99
const validator = require("validator");
1010
const { getExampleByNumber } = require("../../manifestService");
1111
const dsConfig = require("../../../config/index.js").config;
12-
const { formatString } = require('../../utils.js');
12+
const { formatString, isCFR } = require('../../utils.js');
1313

1414
const eg032PauseSignatureWorkflow = exports;
1515
const exampleNumber = 32;
@@ -94,14 +94,25 @@ eg032PauseSignatureWorkflow.getController = async (req, res) => {
9494
return res.redirect(mustAuthenticate);
9595
}
9696

97+
let enableCFR = await isCFR(req.user.accessToken, req.session.accountId, req.session.basePath);
98+
if (enableCFR == "enabled"){
99+
res.locals.statusCFR = "enabled";
100+
}
101+
97102
const example = getExampleByNumber(res.locals.manifest, exampleNumber);
98103
const sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
99-
res.render("pages/examples/eg032PauseSignatureWorkflow", {
100-
eg: eg, csrfToken: req.csrfToken(),
101-
example: example,
102-
sourceFile: sourceFile,
103-
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/examples/' + sourceFile,
104-
documentation: dsConfig.documentation + eg,
105-
showDoc: dsConfig.documentation
106-
});
104+
if (res.locals.statusCFR == "enabled") {
105+
res.render('pages/invalid_with_cfr', {
106+
title: "Not CFR Part 11 compatible"
107+
});
108+
} else {
109+
res.render("pages/examples/eg032PauseSignatureWorkflow", {
110+
eg: eg, csrfToken: req.csrfToken(),
111+
example: example,
112+
sourceFile: sourceFile,
113+
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/examples/' + sourceFile,
114+
documentation: dsConfig.documentation + eg,
115+
showDoc: dsConfig.documentation
116+
});
117+
}
107118
}

lib/eSignature/controllers/eg033UnpauseSignatureWorkflow.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const path = require("path");
88
const { unpauseSignatureWorkflow } = require("../examples/unpauseSignatureWorkflow");
99
const { getExampleByNumber } = require("../../manifestService");
1010
const dsConfig = require("../../../config/index.js").config;
11-
const { formatString } = require('../../utils.js');
11+
const { formatString, isCFR } = require('../../utils.js');
1212

1313
const eg033UnpauseSignatureWorkflow = exports;
1414
const exampleNumber = 33;
@@ -82,15 +82,26 @@ eg033UnpauseSignatureWorkflow.getController = async (req, res) => {
8282
return res.redirect(mustAuthenticate);
8383
}
8484

85+
let enableCFR = await isCFR(req.user.accessToken, req.session.accountId, req.session.basePath);
86+
if (enableCFR == "enabled"){
87+
res.locals.statusCFR = "enabled";
88+
}
89+
8590
const example = getExampleByNumber(res.locals.manifest, exampleNumber);
8691
const sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
87-
res.render("pages/examples/eg033UnpauseSignatureWorkflow", {
88-
eg: eg, csrfToken: req.csrfToken(),
89-
example: example,
90-
envelopeOk: req.session.hasOwnProperty("pausedEnvelopeId"),
91-
sourceFile: sourceFile,
92-
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/examples/' + sourceFile,
93-
documentation: dsConfig.documentation + eg,
94-
showDoc: dsConfig.documentation
95-
});
92+
if (res.locals.statusCFR == "enabled") {
93+
res.render('pages/invalid_with_cfr', {
94+
title: "Not CFR Part 11 compatible"
95+
});
96+
} else {
97+
res.render("pages/examples/eg033UnpauseSignatureWorkflow", {
98+
eg: eg, csrfToken: req.csrfToken(),
99+
example: example,
100+
envelopeOk: req.session.hasOwnProperty("pausedEnvelopeId"),
101+
sourceFile: sourceFile,
102+
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/examples/' + sourceFile,
103+
documentation: dsConfig.documentation + eg,
104+
showDoc: dsConfig.documentation
105+
});
106+
}
96107
}

lib/eSignature/controllers/eg034UseConditionalRecipients.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { useConditionalRecipients } = require("../examples/useConditionalRecipien
99
const validator = require("validator");
1010
const { getExampleByNumber } = require("../../manifestService");
1111
const dsConfig = require("../../../config/index.js").config;
12-
const { formatString } = require('../../utils.js');
12+
const { formatString, isCFR } = require('../../utils.js');
1313

1414
const eg034UseConditionalRecipients = exports;
1515
const exampleNumber = 34;
@@ -100,14 +100,25 @@ eg034UseConditionalRecipients.getController = async (req, res) => {
100100
return res.redirect(mustAuthenticate);
101101
}
102102

103+
let enableCFR = await isCFR(req.user.accessToken, req.session.accountId, req.session.basePath);
104+
if (enableCFR == "enabled"){
105+
res.locals.statusCFR = "enabled";
106+
}
107+
103108
const example = getExampleByNumber(res.locals.manifest, exampleNumber);
104109
const sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
105-
res.render("pages/examples/eg034UseConditionalRecipients", {
106-
eg: eg, csrfToken: req.csrfToken(),
107-
example: example,
108-
sourceFile: sourceFile,
109-
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/examples/' + sourceFile,
110-
documentation: dsConfig.documentation + eg,
111-
showDoc: dsConfig.documentation
112-
});
110+
if (res.locals.statusCFR == "enabled") {
111+
res.render('pages/invalid_with_cfr', {
112+
title: "Not CFR Part 11 compatible"
113+
});
114+
} else {
115+
res.render("pages/examples/eg034UseConditionalRecipients", {
116+
eg: eg, csrfToken: req.csrfToken(),
117+
example: example,
118+
sourceFile: sourceFile,
119+
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/examples/' + sourceFile,
120+
documentation: dsConfig.documentation + eg,
121+
showDoc: dsConfig.documentation
122+
});
123+
}
113124
}

0 commit comments

Comments
 (0)