-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
132 lines (114 loc) · 4.02 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import uuid
from flask import Flask, redirect, request, url_for
from flask import render_template
from flask_login import LoginManager, current_user, login_required, login_user, logout_user
from api import *
app = Flask(__name__)
app.secret_key = 'secret_rianng.cn_8023_{}'.format(uuid.uuid1())
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'
@login_manager.user_loader
def load_user(user_id):
return User.get(user_id)
@app.route('/register', methods=['GET', 'POST'])
def register():
form = RegisterForm()
emsg = None
if form.validate_on_submit():
username = form.username.data
password1 = form.password1.data
password2 = form.password2.data
user_info = get_user(username)
if user_info is None:
if password1 == password2:
create_user(username, password1)
return redirect(url_for('login'))
else:
emsg = 'Different password.'
else:
emsg = 'Username exists.'
return render_template('register.html', form=form, emsg=emsg)
@app.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForm()
emsg = None
if form.validate_on_submit():
username = form.username.data
password = form.password.data
user_info = get_user(username)
if user_info is None:
emsg = 'Wrong username or password.'
else:
user = User(user_info)
if user.verify_password(password):
login_user(user)
return redirect(request.args.get('next') or url_for('index'))
else:
emsg = 'Wrong username or password.'
return render_template('login.html', form=form, emsg=emsg)
@app.route('/logout')
@login_required
def logout():
logout_user()
return redirect(url_for('login'))
@app.route('/', methods=['GET', 'POST'])
@login_required
def index():
a_config = ada_config()
user = User(current_user)
accs_token = user.get_accs_token()
accs_info = []
for acc_token in accs_token:
a_api = ada_api(acc_token, only_read=True)
acc_info = a_api.get_account_info()
accs_info.append(acc_info)
if request.method == 'GET':
return render_template('index.html', accounts=accs_info, user=current_user)
else:
token = request.form.get('token')
a_api = ada_api(token, only_read=True)
if a_api.account is not None:
acc_info = a_api.get_account_info()
return render_template('index.html', accounts=accs_info, new_acc_info=acc_info, user=current_user)
else:
return render_template('index.html', accounts=accs_info, new_acc_info={'None': token}, user=current_user)
@app.route('/api/acc/add', methods=['POST'])
@login_required
def add_acc():
token = request.form.get('token')
a_config = ada_config()
a_api = ada_api(token)
acc_info = a_api.get_account_info()
user = User(current_user)
user.add_acc(acc_info['uid'])
return redirect('/')
@app.route('/analyze/refresh', methods=['POST'])
@login_required
def refresh_ada():
token = request.form.get('token')
a_api = ada_api(token)
return redirect('/')
@app.route('/analyze/refresh/force', methods=['POST'])
@login_required
def refresh_force_ada():
token = request.form.get('token')
a_api = ada_api(token, force_refresh=True)
return redirect('/')
@app.route('/analyze', methods=['POST'])
@login_required
def analyze_results():
token = request.form.get('token')
a_config = ada_config()
user = User(current_user)
accs_token = user.get_accs_token()
accs_info = []
for acc_token in accs_token:
a_api = ada_api(acc_token, only_read=True)
acc_info = a_api.get_account_info()
accs_info.append(acc_info)
a_api = ada_api(token, only_read=True)
a_info = a_api.get_all_info()
return render_template('analysis.html', info=a_info, accounts=accs_info, user=current_user)
if __name__ == '__main__':
app.run(debug=True, port=8900)