# 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: database.py
# def get_session():
# def teardown_session(exception):


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 database import session

home = Blueprint('home', __name__)


@home.route('/')
def index():
    if current_user.is_authenticated:
        return redirect(url_for('static', filename='projects.html'))
    return redirect(url_for('static', filename='login.html'))


@home.route('/validateLogin', methods=['POST'])
def login():
    username = request.values['username']
    password = request.values['password']
    return username


@home.route('/login/<int:id>')
def login_test(id):

# 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: database.py
# def get_session():
# def teardown_session(exception):


# Path: app/views/home.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 database import session


home = Blueprint('home', __name__)


@home.route('/')
def index():
    if current_user.is_authenticated:
        return redirect(url_for('static', filename='projects.html'))
    return redirect(url_for('static', filename='login.html'))


@home.route('/validateLogin', methods=['POST'])
def login():
    username = request.values['username']
    password = request.values['password']
    return username


@home.route('/login/<int:id>')
def login_test(id):

    login_user(session.query(User).get(id))