22
33from flask import redirect , request , url_for , flash , render_template , Blueprint , session , current_app as app
44
5+ import json
56from .ds_client import DSClient
67from .utils import ds_logout_internal
78from ..consts import base_uri_suffix
89from ..ds_config import DS_CONFIG
9- from ..ds_config import EXAMPLES_API_TYPE
10+ from ..api_type import EXAMPLES_API_TYPE
1011
1112ds = Blueprint ("ds" , __name__ , url_prefix = "/ds" )
1213
@@ -28,6 +29,44 @@ def ds_logout():
2829 app .config ["quickstart" ] = False
2930 return redirect (url_for ("core.index" ))
3031
32+ @ds .route ("/choose_api" )
33+ def choose_api ():
34+ return render_template ("choose_api.html" , title = "Choose API" )
35+
36+ @ds .route ("/api_selected" , methods = ["GET" , "POST" ])
37+ def api_selected ():
38+ chosen_api = request .form .get ("chosen_api" )
39+
40+ new_api_type = EXAMPLES_API_TYPE
41+
42+ # Set all values to False
43+ for api_type in new_api_type :
44+ if new_api_type [api_type ] == True :
45+ new_api_type [api_type ] = False
46+
47+ # Update the new chosen API type to True
48+ if chosen_api == "ESignature" :
49+ new_api_type ["ESignature" ] = True
50+ elif chosen_api == "Rooms" :
51+ new_api_type ["Rooms" ] = True
52+ elif chosen_api == "Admin" :
53+ new_api_type ["Admin" ] = True
54+ elif chosen_api == "Monitor" :
55+ new_api_type ["Monitor" ] = True
56+ elif chosen_api == "Click" :
57+ new_api_type ["Click" ] = True
58+
59+ # Overwrite api_type.py file
60+ with open ("app/api_type.py" , "w" ) as api_type_file :
61+ api_type_file .write ("EXAMPLES_API_TYPE =" + str (new_api_type ))
62+
63+ ds_logout_internal ()
64+ flash ("You have logged out from DocuSign." )
65+ app .config ["isLoggedIn" ] = False
66+ app .config ["quickstart" ] = False
67+
68+ return render_template ("must_authenticate.html" , title = "Must authenticate" , chosen_api = chosen_api )
69+
3170
3271@ds .route ("/callback" )
3372def ds_callback ():
@@ -77,7 +116,7 @@ def ds_callback():
77116
78117@ds .route ("/must_authenticate" )
79118def ds_must_authenticate ():
80- if DS_CONFIG ["quickstart" ] == "true" and EXAMPLES_API_TYPE [' ESignature' ]:
119+ if DS_CONFIG ["quickstart" ] == "true" and EXAMPLES_API_TYPE [" ESignature" ]:
81120 session ["auth_type" ] = "code_grant"
82121 return redirect (url_for ("ds.ds_login" ))
83122
0 commit comments