-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.py
63 lines (49 loc) · 1.58 KB
/
web.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
from flask import Flask, request
import db
from ipdb import set_trace
app = Flask(__name__)
USE_DB = "MYSQL"
#USE_DB = "SQLITE"
@app.route("/")
def index():
return "OK\n"
@app.route("/login")
def login():
username = request.args.get('user')
password = request.args.get('pass')
if not all([username, password]):
return "username or password empty\n"
verbose = True if "verbose" in request.args else False
print("got: ",username, password)
return db.login(username, password, verbose)
@app.route("/list")
def list():
username = request.args.get('user')
verbose = True if "verbose" in request.args else False
return db.list_user(username, verbose)
@app.route("/add")
def add():
username = request.args.get('user')
password = request.args.get('pass')
if not all([username, password]):
return "username or password empty\n"
verbose = True if "verbose" in request.args else False
return db.add(username, password, verbose)
@app.route("/del")
def delete():
user_id = request.args.get('id')
if not user_id:
return "id is empty\n"
verbose = True if "verbose" in request.args else False
return db.delete(user_id, verbose)
@app.route("/update")
def update():
user_id = request.args.get('id')
password = request.args.get('pass')
if not all([user_id, password]):
return "id, username empty\n"
verbose = True if "verbose" in request.args else False
return db.update(user_id, password, verbose)
if __name__ == '__main__':
db.init(USE_DB, app)
app.run(host="0.0.0.0", debug=True)