# Path: models/user.py
# class User(TableBase, UserMixin):
#     """A user."""
# 
#     __tablename__ = 'user'
#     id = Column(Integer, primary_key=True)
#     email = Column(String(63), unique=True)
#     passwordhash = Column(String(127), nullable=False)
#     salt = Column(String(127), nullable=False)
#     username = Column(String(127))
#     if os.getenv('FLASK_TESTING'):
#         avatar = Column(String(16777215))
#     else:
#         avatar = Column(MEDIUMTEXT())
#     description = Column(Text())
#     education = Column(Text())
#     major = Column(Text())
# 
#     def __init__(self, email, password, username):
#         self.email = email
#         self.set_password(password)
#         self.username = username
# 
#     def set_password(self, password):
#         """hash and save the password"""
#         self.salt = random_string(10)
#         s = hashlib.sha256()
#         s.update(password.encode('utf-8'))
#         s.update(self.salt.encode('utf-8'))
#         self.passwordhash = s.hexdigest()
# 
#     def check_password(self, password):
#         """hash and check the password"""
#         s = hashlib.sha256()
#         s.update(password.encode('utf-8'))
#         s.update(self.salt.encode('utf-8'))
#         return self.passwordhash == s.hexdigest()
# 
#     @classmethod
#     def get_user_by_email(cls, email):
#         return session.query(cls).filter_by(email=email).first()
# 
#     @classmethod
#     def get_user_by_id(cls, id):
#         return session.query(cls).get(id)
# 
# Path: plugin.py
# class Plugin:
# class PluginManager:
# class Documents:
#     def __init__(self):
#     def user(self):
#     def process(self, request):
#     def unload(self):
#     def __init__(self):
#     def load_plugin(self, name, reload=False):
#     def get_plugins(self):
#     def send_request(self, plugin, request):
#     def __init__(self, plugin: Plugin):
#     def set_document_type(self, name: str):
#     def set_document_table(self, table):
#     def get(self, pid):
#     def list(self, owner):
#     def create(self, pdoc: PluginDocument):
#     def update(pdoc: PluginDocument):
#     def delete(self, pdoc: PluginDocument):


from flask import Blueprint, redirect, url_for, request
from flask_login import current_user, login_required, login_user, logout_user
from models import User
from plugin import plugin_manager
import json

plugin = Blueprint('plugin', __name__)


@plugin.route('/', methods=['GET', 'POST'])
def plugin_request():
    plugin_name = request.values['plugin'] if 'plugin' in request.values else ''
    req = {v: request.values[v] for v in request.values}
    if 'file' in request.files and request.files['file'].filename:
        req['file'] = request.files['file']
        print('Got a file:', request.files['file'].filename)

# Path: models/user.py
# class User(TableBase, UserMixin):
#     """A user."""
# 
#     __tablename__ = 'user'
#     id = Column(Integer, primary_key=True)
#     email = Column(String(63), unique=True)
#     passwordhash = Column(String(127), nullable=False)
#     salt = Column(String(127), nullable=False)
#     username = Column(String(127))
#     if os.getenv('FLASK_TESTING'):
#         avatar = Column(String(16777215))
#     else:
#         avatar = Column(MEDIUMTEXT())
#     description = Column(Text())
#     education = Column(Text())
#     major = Column(Text())
# 
#     def __init__(self, email, password, username):
#         self.email = email
#         self.set_password(password)
#         self.username = username
# 
#     def set_password(self, password):
#         """hash and save the password"""
#         self.salt = random_string(10)
#         s = hashlib.sha256()
#         s.update(password.encode('utf-8'))
#         s.update(self.salt.encode('utf-8'))
#         self.passwordhash = s.hexdigest()
# 
#     def check_password(self, password):
#         """hash and check the password"""
#         s = hashlib.sha256()
#         s.update(password.encode('utf-8'))
#         s.update(self.salt.encode('utf-8'))
#         return self.passwordhash == s.hexdigest()
# 
#     @classmethod
#     def get_user_by_email(cls, email):
#         return session.query(cls).filter_by(email=email).first()
# 
#     @classmethod
#     def get_user_by_id(cls, id):
#         return session.query(cls).get(id)
# 
# Path: plugin.py
# class Plugin:
# class PluginManager:
# class Documents:
#     def __init__(self):
#     def user(self):
#     def process(self, request):
#     def unload(self):
#     def __init__(self):
#     def load_plugin(self, name, reload=False):
#     def get_plugins(self):
#     def send_request(self, plugin, request):
#     def __init__(self, plugin: Plugin):
#     def set_document_type(self, name: str):
#     def set_document_table(self, table):
#     def get(self, pid):
#     def list(self, owner):
#     def create(self, pdoc: PluginDocument):
#     def update(pdoc: PluginDocument):
#     def delete(self, pdoc: PluginDocument):


# Path: app/views/plugin.py
from flask import Blueprint, redirect, url_for, request
from flask_login import current_user, login_required, login_user, logout_user
from models import User
from plugin import plugin_manager
import json


plugin = Blueprint('plugin', __name__)


@plugin.route('/', methods=['GET', 'POST'])
def plugin_request():
    plugin_name = request.values['plugin'] if 'plugin' in request.values else ''
    req = {v: request.values[v] for v in request.values}
    if 'file' in request.files and request.files['file'].filename:
        req['file'] = request.files['file']
        print('Got a file:', request.files['file'].filename)

    rtv = plugin_manager.send_request(plugin_name, req)