1
1
from flask import Flask , render_template
2
+ from flask_httpauth import HTTPBasicAuth
3
+ from werkzeug .security import generate_password_hash , check_password_hash
2
4
import connexion
3
5
import requests
4
6
import myapi
5
7
6
8
#Create the application instance!
7
9
app = connexion .App (__name__ , specification_dir = './' )
10
+ auth = HTTPBasicAuth ()
11
+
12
+
13
+ users = {
14
+ "john" : generate_password_hash ("hello" ),
15
+ "susan" : generate_password_hash ("bye" )
16
+ }
17
+
18
+ @auth .verify_password
19
+ def verify_password (username , password ):
20
+ if username in users and \
21
+ check_password_hash (users .get (username ), password ):
22
+ return username
23
+
8
24
9
25
#Read the swagger.yml file to configure the endpoints
10
26
app .add_api ('swagger.yml' )
11
27
12
28
#Create a URL route in our application for "/"
13
29
@app .route ('/' , methods = ["GET" ,"POST" ])
30
+ @auth .login_required
14
31
def home ():
15
- return render_template ('home.html' )
32
+ #return "Hello, {}!".format(auth.current_user())
33
+ if (auth .current_user ()):
34
+ #uname = auth.current_user()
35
+ return render_template ('home.html' , username = auth .username ())
36
+ else :
37
+ print ("ERROR" )
16
38
17
39
if __name__ == '__main__' :
18
- app .run (host = '0.0.0.0' , port = 8080 , debug = True )
40
+ app .run (host = '0.0.0.0' , port = 8080 , debug = True )
41
+
42
+
43
+
0 commit comments