-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
53 lines (44 loc) · 1.35 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python3
#@nathanaelassis
from functools import wraps
from ldap3 import Server, Connection
from flask import Flask, render_template, request, redirect, session, g
from blueprints.docker_routes import docker_routes
from blueprints.gitlab_routes import gitlab_routes
from blueprints.jenkins_routes import jenkins_routes
app = Flask(__name__)
app.secret_key = 'TqMYB8^wbe!%cTcx3UbV!qUsZ2*#*XK6B3ZFj*zK'
app.url_map.strict_slashes = False
app.register_blueprint(docker_routes)
app.register_blueprint(gitlab_routes)
app.register_blueprint(jenkins_routes)
@app.before_request
def load_auth():
if 'auth' in session:
g.auth = True
else:
g.auth = False
@app.route('/')
def index():
if g.auth:
return redirect('/docker')
return render_template('login.html')
@app.route('/login', methods=['POST'])
def login():
usuario = request.form['usuario']
senha = request.form['senha']
server = Server('27.11.90.30', use_ssl=False)
ldap = Connection(server,
user='uid={},dc=ldap,dc=example,dc=com'.format(usuario),
password=senha)
if ldap.bind():
session['auth'] = True
return redirect('/docker')
else:
return redirect('/')
@app.route('/logoff')
def logoff():
del session['auth']
return redirect('/')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)