This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapp.py
60 lines (43 loc) · 1.41 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
54
55
56
57
58
59
60
from os import path, getcwd
from sys import argv
from flask import Flask, render_template, session, redirect, send_from_directory
from flask_cas import CAS
from flask_cas import login
from flask_cas import logout
from flask_cas import login_required
import logging
app = Flask(__name__)
cas = CAS(app, '/cas')
app.config['CAS_SERVER'] = 'https://casserver.herokuapp.com'
app.config['CAS_AFTER_LOGIN'] = 'secure'
# app.config['CAS_LOGOUT_ROUTE'] =
# app.config['CAS_VALIDATE_ROUTE'] =
# app.config['CAS_VALIDATE_ROUTE'] =
@app.route("/logout")
def logout():
session.clear()
return render_template('logout.html')
@app.route("/secure")
@login_required
def secure():
username = cas.username
attributes = cas.attributes
logging.info('CAS username: %s', username)
logging.info('CAS attributes: %s', attributes)
return render_template('secure.html', cas=cas)
@app.route("/caslogout")
def caslogout():
return redirect(app.config['CAS_LOGOUT_ROUTE'], code=302)
@app.route("/")
def main():
return render_template('index.html')
@app.route("/<path:filename>")
def static_files(filename):
return send_from_directory(path.join(getcwd(), 'static'), filename)
if __name__ == "__main__":
if len(argv) >= 3 and argv[1] == '--server':
app.config['CAS_SERVER'] = argv[2]
app.secret_key = 'super secret key'
app.config['SESSION_TYPE'] = 'filesystem'
app.debug = True
app.run()