Upload files to "app"
This commit is contained in:
parent
db458e0c29
commit
6768acf648
57
app/__init__.py
Normal file
57
app/__init__.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import os
|
||||||
|
import time
|
||||||
|
from flask import Flask, g, request
|
||||||
|
from flask_login import LoginManager, current_user
|
||||||
|
from uuid import uuid4
|
||||||
|
from app.main import bp as main_bp
|
||||||
|
# from app.auth import bp as auth_bp
|
||||||
|
from app import config
|
||||||
|
from app.playgrounds import bp as pg_bp
|
||||||
|
# from app_common import login_manager
|
||||||
|
from authlib.integrations.requests_client import OAuth2Session
|
||||||
|
# from app.auth import google
|
||||||
|
|
||||||
|
|
||||||
|
def create_app(app_name):
|
||||||
|
app_root_path = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
# app = Flask(app_name, template_folder=os.path.join(app_root_path, 'templates'), static_folder=os.path.join(app_root_path, 'static'))
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
app.secret_key = str(uuid4())
|
||||||
|
|
||||||
|
from app import model
|
||||||
|
|
||||||
|
# login_manager.init_app(app)
|
||||||
|
|
||||||
|
app.config.from_object(config)
|
||||||
|
|
||||||
|
app.register_blueprint(main_bp)
|
||||||
|
app.register_blueprint(pg_bp)
|
||||||
|
# app.register_blueprint(auth_bp)
|
||||||
|
|
||||||
|
# app.register_blueprint(google.app)
|
||||||
|
|
||||||
|
@app.before_request
|
||||||
|
def before_request():
|
||||||
|
|
||||||
|
g.start = time.time()
|
||||||
|
|
||||||
|
@app.after_request
|
||||||
|
def after_request(response):
|
||||||
|
if hasattr(g, 'start'):
|
||||||
|
request_time = time.time() - g.start
|
||||||
|
else:
|
||||||
|
request_time = 'N/A '
|
||||||
|
# app.logger.info(f'HTTP request completed (method={request.method}, path={request.path}, status_code={response.status_code}, request_time={request_time}s, '
|
||||||
|
# f'user={current_user.id if current_user and hasattr(current_user, "id") else "None"}).')
|
||||||
|
return response
|
||||||
|
|
||||||
|
app.logger.info('Config Values:\n -' + '\n -'.join([f'{k}: {app.config[k]}' for k in app.config]))
|
||||||
|
|
||||||
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = create_app(__name__)
|
||||||
|
app.run()
|
||||||
|
|
||||||
13
app/client_secret.json
Normal file
13
app/client_secret.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"web": {
|
||||||
|
"client_id": "158082608933-4m1ehbkkk7qadekmp3hvl02oht2o1ucg.apps.googleusercontent.com",
|
||||||
|
"project_id": "quarter-internal",
|
||||||
|
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||||
|
"token_uri": "https://oauth2.googleapis.com/token",
|
||||||
|
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||||
|
"client_secret": "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",
|
||||||
|
"redirect_uris": [
|
||||||
|
"http://localhost/google/auth"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
12
app/config.py
Normal file
12
app/config.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
LDAP_BASE_DN = 'dc=quarter,dc=int'
|
||||||
|
LDAP_ADMIN_DN = f'cn=admin,{LDAP_BASE_DN}'
|
||||||
|
LDAP_ADMIN_PASS = 'ijfijfijf++'
|
||||||
|
|
||||||
|
GOOGLE_API_KEY = 'AIzaSyAh6GQdB6ewtDQ3KZT4hlTKClHUm9W-OsY'
|
||||||
|
|
||||||
|
FANNIE_CLIENT_ID = '12bcb905-d418-4561-8fbb-aabaa0df2229'
|
||||||
|
FANNIE_CLIENT_SECRET = 'XVAyWc5BjkTIPL3ivWAijPvC4_B-U.P-Y.XpxDTEqAVg5lQiYb8Q1400d~Pw-O2W'
|
||||||
|
FANNIE_AUTH_TOKEN = ''
|
||||||
|
|
||||||
|
UPLOAD_PATH = 'uploads'
|
||||||
71
app/model.py
Normal file
71
app/model.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# import ldap
|
||||||
|
# from flask import current_app
|
||||||
|
# from flask_login import UserMixin
|
||||||
|
# # from app_common import make_ldap_connection, close_ldap_connection, login_manager
|
||||||
|
#
|
||||||
|
# users = {}
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# class User(UserMixin):
|
||||||
|
#
|
||||||
|
# def __init__(self, id_, name, email):
|
||||||
|
# self.name = name
|
||||||
|
# self.email = email
|
||||||
|
# self.phone = None
|
||||||
|
# self.group = None
|
||||||
|
# self.id_ = None
|
||||||
|
# ssh_pub_keys = []
|
||||||
|
#
|
||||||
|
# @staticmethod
|
||||||
|
# def authenticate(user_id, password):
|
||||||
|
# ldap_connection = make_ldap_connection
|
||||||
|
# result = ldap_connection.search_s(current_app.config['LDAP_BASE_DN'], ldap.SCOPE_SUBTREE, f'uid={user_id}')[0]
|
||||||
|
# user = User.from_raw_ldap(result, password)
|
||||||
|
#
|
||||||
|
# try:
|
||||||
|
# ldap_connection.bind_s(f'uid={user.id_},ou={user.group},{current_app.config["LDAP_BASE_DN"]}', password, ldap.AUTH_SIMPLE)
|
||||||
|
# return user
|
||||||
|
# except Exception as ex:
|
||||||
|
# print(f'ERROR: {str(ex)}')
|
||||||
|
# finally:
|
||||||
|
# close_ldap_connection(ldap_connection)
|
||||||
|
#
|
||||||
|
# @staticmethod
|
||||||
|
# def from_raw_ldap(raw_user, password=None):
|
||||||
|
# raw_dn = raw_user[0]
|
||||||
|
# raw_user_data = raw_user[1]
|
||||||
|
# dn = parse_user_dn(raw_dn)
|
||||||
|
# user = User()
|
||||||
|
# user.id_ = raw_user_data.get('cn')[0].decode('utf-8')
|
||||||
|
# user.group = dn.get('ou')
|
||||||
|
# user.name = raw_user_data.get('displayName')[0].decode('utf-8')
|
||||||
|
# user.phone = raw_user_data.get("mobile", [b''])[0].decode('utf-8')
|
||||||
|
# user.ssh_pub_keys = [k.decode('utf-8') for k in raw_user_data.get('sshPublicKey', [])]
|
||||||
|
# user.password = password
|
||||||
|
#
|
||||||
|
# if user.id_ not in users:
|
||||||
|
# users[user.id_] = user
|
||||||
|
# elif users[user.id_].password is None and password is not None:
|
||||||
|
# users[user.id_] = user
|
||||||
|
#
|
||||||
|
# return user
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# def parse_user_dn(user_dn):
|
||||||
|
# group = user_dn.split(',')
|
||||||
|
# result = {}
|
||||||
|
# for g in group:
|
||||||
|
# split = g.split('=')
|
||||||
|
# result[split[0]] = split[1]
|
||||||
|
# return result
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# @login_manager.user_loader
|
||||||
|
# def load_user(user_id):
|
||||||
|
# ldap_connection = make_ldap_connection()
|
||||||
|
# raw_user = ldap_connection.search_s(current_app.config['LDAP_BASE_DN'], ldap.SCOPE_SUBTREE, f'uid={user_id}')[0]
|
||||||
|
# _users = users
|
||||||
|
# user = User.from_raw_ldap(raw_user)
|
||||||
|
# close_ldap_connection(ldap_connection)
|
||||||
|
# return user
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user