This repository was archived by the owner on Jan 30, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnumu.py
More file actions
78 lines (52 loc) · 1.67 KB
/
numu.py
File metadata and controls
78 lines (52 loc) · 1.67 KB
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
import logging
from logging.handlers import RotatingFileHandler
import response
from flask import Flask, make_response, jsonify, g
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_httpauth import HTTPBasicAuth
from flask_bcrypt import Bcrypt
app = Flask(__name__)
bcrypt = Bcrypt(app)
auth = HTTPBasicAuth()
app.config.from_object("config.Config")
db = SQLAlchemy(app)
import backend.models
migrate = Migrate(app, db)
err_handler = RotatingFileHandler("numu-error.log", maxBytes=1000000, backupCount=5)
err_handler.setFormatter(
logging.Formatter(
"%(asctime)s | %(pathname)s:%(lineno)d | %(funcName)s | %(levelname)s | %(message)s"
)
)
err_handler.setLevel(logging.ERROR)
app.logger.addHandler(err_handler)
app.logger.setLevel(logging.DEBUG)
from backend import repo
@auth.verify_password
def verify_password(username, password):
g.user = None
if password == "icloud":
user = repo.get_user_by_icloud(username)
if user:
g.user = user
return True
else:
user = repo.get_user_by_email(username)
if user and bcrypt.check_password_hash(user.password_hash, password):
g.user = user
return True
return False
@app.errorhandler(404)
def not_found(error):
return make_response(jsonify({"error": "Not found"}), 404)
@auth.error_handler
def unauthorized():
return response.unauthorized()
@app.route("/")
def index():
return "Numu Tracker API - {}".format(app.config["ENVIROMENT"])
from rest import app as api_v3
app.register_blueprint(api_v3, url_prefix="/v3")
from commands import app as commands
app.register_blueprint(commands)