|
| 1 | +# import Flask library (class) that has needed functionality to build Web Server |
| 2 | +# import render_template - this is library that works with Flask Jinja (HTML) templates |
| 3 | +# import request - to access incoming request data, you can use the global request object. |
| 4 | +# Flask parses incoming request data for you and gives you access to it through that global object. |
| 5 | +# import flask_wtf and wtfforms are libraries that will help us with the form data |
| 6 | + |
| 7 | +from flask import Flask, render_template, request |
| 8 | +from flask_cors import CORS, cross_origin |
| 9 | +from flask_wtf import FlaskForm |
| 10 | +from wtforms import StringField, validators |
| 11 | + |
| 12 | +import requests |
| 13 | +import datetime |
| 14 | +import json |
| 15 | +import uuid |
| 16 | +import jwt |
| 17 | + |
| 18 | +app = Flask(__name__) |
| 19 | +CORS(app) |
| 20 | +cors = CORS(app, resources={ |
| 21 | + r"/*":{ |
| 22 | + "origins": "*" |
| 23 | + } |
| 24 | +}) |
| 25 | +app.debug = True |
| 26 | +app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 |
| 27 | +@app.after_request |
| 28 | +def after_request(response): |
| 29 | + response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate, public, max-age=0" |
| 30 | + response.headers["Expires"] = 0 |
| 31 | + response.headers["Pragma"] = "no-cache" |
| 32 | + return response |
| 33 | + |
| 34 | +# initializing global variables |
| 35 | +username = '' |
| 36 | +tabServer = 'http://localhost:8000' |
| 37 | + |
| 38 | + |
| 39 | +# this secret key is here a string just so we have forms working - if you want to know more google it ;-) |
| 40 | +app.config['SECRET_KEY'] = 'somesecretkey' |
| 41 | + |
| 42 | +# instance the form class - inheritance is from the FlaskForm. |
| 43 | +# You can name the calss as you like - we named it "UserForm" |
| 44 | +class UserForm(FlaskForm): |
| 45 | + # Below are the form fields we want to be able to capture and send (in our case just the username) to Tableau server. |
| 46 | + # These are used as form attributes in .html file |
| 47 | + # in the quotes is the text user will see when using the form |
| 48 | + username = StringField("Username:", validators=[validators.DataRequired()]) |
| 49 | + |
| 50 | +##########Rendering the login page########## |
| 51 | +@app.route('/') |
| 52 | +def index(): |
| 53 | + return render_template('index.html') |
| 54 | + |
| 55 | +@app.route('/login2') |
| 56 | +def login2(): |
| 57 | + return render_template('login2.html') |
| 58 | +@app.route('/login3') |
| 59 | +def login3(): |
| 60 | + return render_template('login3.html') |
| 61 | +@app.route('/login9') |
| 62 | +def login9(): |
| 63 | + return render_template('login9.html') |
| 64 | + |
| 65 | +@app.route('/test') |
| 66 | +def test(): |
| 67 | + return render_template('loader.html') |
| 68 | + |
| 69 | +@app.route('/loadingCA', methods=['GET','POST']) |
| 70 | +@cross_origin() |
| 71 | +def getJWT(): |
| 72 | + global username |
| 73 | + if request.method == 'POST': |
| 74 | + username = request.form['username'] |
| 75 | + print(username) |
| 76 | + CA_SSO_token = jwt.encode( |
| 77 | + { |
| 78 | + "iss": 'ff3ad96c-1d60-4ff2-89ee-02e99fe551ad', |
| 79 | + "exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=10), |
| 80 | + "jti": str(uuid.uuid4()), |
| 81 | + "aud": "tableau", |
| 82 | + "sub": username, |
| 83 | + "scp": ["tableau:views:embed", "tableau:metrics:embed"] |
| 84 | + }, |
| 85 | + '0/oP45C+hQ8YY8+EZs/I6+SbTCU+BVYnlimq7fkRHk0=', |
| 86 | + algorithm="HS256", |
| 87 | + headers={ |
| 88 | + 'kid': '784f8c48-e657-4245-b887-8bbd45bd40f0', |
| 89 | + 'iss': 'ff3ad96c-1d60-4ff2-89ee-02e99fe551ad' |
| 90 | + } |
| 91 | + ) |
| 92 | + |
| 93 | + headers = { |
| 94 | + 'Access-Control-Allow-Origin': '*', |
| 95 | + 'content-type': 'application/json' |
| 96 | + } |
| 97 | + |
| 98 | + print("Here's your JWT!: \n" + CA_SSO_token) |
| 99 | + if request.form['route'] =='2': |
| 100 | + return render_template('loader2.html', CA_SSO_token=CA_SSO_token,tabServer = tabServer,username=username) |
| 101 | + if request.form['route'] =='3': |
| 102 | + return render_template('loader3.html', CA_SSO_token=CA_SSO_token,tabServer = tabServer,username=username) |
| 103 | + if request.form['route'] =='9': |
| 104 | + return render_template('loader9.html', CA_SSO_token=CA_SSO_token,tabServer = tabServer,username=username) |
| 105 | + |
| 106 | +@app.route('/lesson1') |
| 107 | +def loadLesson1(): |
| 108 | + return render_template('lesson1.html', username = username, tabServer = tabServer) |
| 109 | +@app.route('/lesson2') |
| 110 | +def loadLesson2(): |
| 111 | + return render_template('lesson2.html', username = username, tabServer = tabServer) |
| 112 | +@app.route('/lesson3_1') |
| 113 | +def loadLesson3_1(): |
| 114 | + return render_template('lesson3_1.html', username = username, tabServer = tabServer) |
| 115 | +@app.route('/lesson3_2_1') |
| 116 | +def loadLesson3_2_1(): |
| 117 | + return render_template('lesson3_2_1.html', username = username, tabServer = tabServer) |
| 118 | +@app.route('/lesson3_2_2') |
| 119 | +def loadLesson3_2_2(): |
| 120 | + return render_template('lesson3_2_2.html', username = username, tabServer = tabServer) |
| 121 | +@app.route('/lesson3_3') |
| 122 | +def loadLesson3_3(): |
| 123 | + return render_template('lesson3_3.html', username = username, tabServer = tabServer) |
| 124 | +@app.route('/lesson3_4') |
| 125 | +def loadLesson3_4(): |
| 126 | + return render_template('lesson3_4.html', username = username, tabServer = tabServer) |
| 127 | + |
| 128 | + |
| 129 | +@app.route('/complete') |
| 130 | +def loadcomplete(): |
| 131 | + return render_template('complete.html', username = username, tabServer = tabServer) |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | +@app.route('/ask') |
| 137 | +def askData(): |
| 138 | + return render_template('askdata.html', username = username, tabServer = tabServer) |
| 139 | + |
| 140 | +if __name__ == '__main__': |
| 141 | + app.run(host='0.0.0.0', port=80) |
0 commit comments