# Path: recruit_app/extensions.py

# 
# Path: recruit_app/user/models.py
# class User(SurrogatePK, Model, UserMixin):
#     __tablename__ = 'users'
# 
#     email = Column(db.String(80), unique=True, nullable=False)
#     #: The hashed password
#     password = Column(db.String(128), nullable=True)
#     created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
#     active = Column(db.Boolean(), default=False)
#     is_admin = Column(db.Boolean(), default=False)
# 
#     confirmed_at = Column(db.DateTime, nullable=True)
# 
#     last_login_at = Column(db.DateTime())
#     current_login_at = Column(db.DateTime())
#     last_login_ip = Column(db.String(100))
#     current_login_ip = Column(db.String(100))
#     login_count = Column(db.Integer)
# 
#     roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic'), lazy='dynamic')
# 
#     main_character_id = ReferenceCol('characters', pk_name='character_id', nullable=True)
#     main_character = relationship('EveCharacter', backref='user_main_character', foreign_keys=[main_character_id])
# 
#     def set_password(self, password):
#         self.password = encrypt_password(password)
#         self.save()
# 
#     def check_password(self, value):
#         return verify_and_update_password(value, self)
# 
#     @classmethod
#     def create(self, **kwargs):
#         """Create a new record and save it the database."""
#         instance = self(**kwargs)
#         if kwargs['password']:
#             instance.password = encrypt_password(kwargs['password'])
#         return instance.save()
# 
#     @property
#     def get_ips(self):
#         return self.last_login_ip.split(', ') + self.current_login_ip.split(', ')
# 
#     def __repr__(self):
#         return '<User({name})>'.format(name=self.email)
# 
#     def __str__(self):
#         return self.email
# 
# Path: recruit_app/public/forms.py
# class LoginForm(Form):
#     email = TextField('Email', validators=[DataRequired()])
#     password = PasswordField('Password', validators=[DataRequired()])
#     submit = SubmitField(label='Log In')
# 
#     def __init__(self, *args, **kwargs):
#         super(LoginForm, self).__init__(*args, **kwargs)
#         self.user = None
# 
#     def validate(self):
#         initial_validation = super(LoginForm, self).validate()
#         if not initial_validation:
#             return False
# 
#         self.user = user_datastore.get_user(self.email.data)
#         if not self.user:
#             self.email.errors.append('Unknown email address')
#             return False
# 
#         if not self.user.check_password(self.password.data):
#             self.password.errors.append('Invalid password')
#             return False
# 
#         if not self.user.active:
#             self.email.errors.append('User not activated')
#             return False
#         return True
# 
# Path: recruit_app/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
# class SurrogatePK(object):
# class TimeMixin(object):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
#     def get_by_id(cls, id):
# def ReferenceCol(tablename, nullable=True, pk_name='id', **kwargs):
# 
# Path: recruit_app/blacklist/models.py
# class BlacklistCharacter(SurrogatePK, TimeMixin, Model):
#     __tablename__ = 'blacklist_character'
#     # __searchable__ = ['name', 'main_name', 'corporation', 'alliance', 'notes', 'ip_address']
# 
#     name = Column(db.Unicode, nullable=True)
#     main_name = Column(db.Unicode, nullable=True)
#     corporation = Column(db.Unicode)
#     alliance = Column(db.Unicode)
#     notes = Column(db.Unicode)
# 
#     ip_address = Column(db.Unicode)
# 
#     creator_id = ReferenceCol('users', nullable=True)
#     creator = relationship('User', foreign_keys=[creator_id], backref='blacklist_character_entries')
# 
#     def __repr__(self):
#         return '<' + self.name + ': ' + self.notes + '>'


from flask import (Blueprint, request, render_template, flash, url_for,
                    redirect, session)
from flask_security.utils import login_user, logout_user
from flask_security.decorators import login_required
from flask_security import current_user
from recruit_app.extensions import security, user_datastore
from recruit_app.user.models import User
from recruit_app.public.forms import LoginForm
from recruit_app.utils import flash_errors
from recruit_app.database import db
from recruit_app.blacklist.models import BlacklistCharacter
@blueprint.route("/", methods=["GET", "POST"])
def home():
    form = LoginForm(request.form)
    return render_template("public/home.html", login_user_form=form)

@blueprint.route("/login/", methods=["GET", "POST"])
def login():
    login_user_form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if login_user_form.validate_on_submit():
            login_user(login_user_form.user)
            flash("You are logged in.", 'success')
            redirect_url = request.args.get("next") or url_for("user.members")
            return redirect(redirect_url)
        else:
            flash_errors(login_user_form)
    return render_template("public/login.html", login_user_form=login_user_form)


@blueprint.route('/logout/')
@login_required
def logout():
    logout_user()
    flash('You are logged out.', 'info')
    return redirect(url_for('public.home'))


@blueprint.route("/about/")
def about():

# Path: recruit_app/extensions.py

# 
# Path: recruit_app/user/models.py
# class User(SurrogatePK, Model, UserMixin):
#     __tablename__ = 'users'
# 
#     email = Column(db.String(80), unique=True, nullable=False)
#     #: The hashed password
#     password = Column(db.String(128), nullable=True)
#     created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
#     active = Column(db.Boolean(), default=False)
#     is_admin = Column(db.Boolean(), default=False)
# 
#     confirmed_at = Column(db.DateTime, nullable=True)
# 
#     last_login_at = Column(db.DateTime())
#     current_login_at = Column(db.DateTime())
#     last_login_ip = Column(db.String(100))
#     current_login_ip = Column(db.String(100))
#     login_count = Column(db.Integer)
# 
#     roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic'), lazy='dynamic')
# 
#     main_character_id = ReferenceCol('characters', pk_name='character_id', nullable=True)
#     main_character = relationship('EveCharacter', backref='user_main_character', foreign_keys=[main_character_id])
# 
#     def set_password(self, password):
#         self.password = encrypt_password(password)
#         self.save()
# 
#     def check_password(self, value):
#         return verify_and_update_password(value, self)
# 
#     @classmethod
#     def create(self, **kwargs):
#         """Create a new record and save it the database."""
#         instance = self(**kwargs)
#         if kwargs['password']:
#             instance.password = encrypt_password(kwargs['password'])
#         return instance.save()
# 
#     @property
#     def get_ips(self):
#         return self.last_login_ip.split(', ') + self.current_login_ip.split(', ')
# 
#     def __repr__(self):
#         return '<User({name})>'.format(name=self.email)
# 
#     def __str__(self):
#         return self.email
# 
# Path: recruit_app/public/forms.py
# class LoginForm(Form):
#     email = TextField('Email', validators=[DataRequired()])
#     password = PasswordField('Password', validators=[DataRequired()])
#     submit = SubmitField(label='Log In')
# 
#     def __init__(self, *args, **kwargs):
#         super(LoginForm, self).__init__(*args, **kwargs)
#         self.user = None
# 
#     def validate(self):
#         initial_validation = super(LoginForm, self).validate()
#         if not initial_validation:
#             return False
# 
#         self.user = user_datastore.get_user(self.email.data)
#         if not self.user:
#             self.email.errors.append('Unknown email address')
#             return False
# 
#         if not self.user.check_password(self.password.data):
#             self.password.errors.append('Invalid password')
#             return False
# 
#         if not self.user.active:
#             self.email.errors.append('User not activated')
#             return False
#         return True
# 
# Path: recruit_app/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
# class SurrogatePK(object):
# class TimeMixin(object):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
#     def get_by_id(cls, id):
# def ReferenceCol(tablename, nullable=True, pk_name='id', **kwargs):
# 
# Path: recruit_app/blacklist/models.py
# class BlacklistCharacter(SurrogatePK, TimeMixin, Model):
#     __tablename__ = 'blacklist_character'
#     # __searchable__ = ['name', 'main_name', 'corporation', 'alliance', 'notes', 'ip_address']
# 
#     name = Column(db.Unicode, nullable=True)
#     main_name = Column(db.Unicode, nullable=True)
#     corporation = Column(db.Unicode)
#     alliance = Column(db.Unicode)
#     notes = Column(db.Unicode)
# 
#     ip_address = Column(db.Unicode)
# 
#     creator_id = ReferenceCol('users', nullable=True)
#     creator = relationship('User', foreign_keys=[creator_id], backref='blacklist_character_entries')
# 
#     def __repr__(self):
#         return '<' + self.name + ': ' + self.notes + '>'


# Path: recruit_app/public/views.py
from flask import (Blueprint, request, render_template, flash, url_for,
                    redirect, session)
from flask_security.utils import login_user, logout_user
from flask_security.decorators import login_required
from flask_security import current_user
from recruit_app.extensions import security, user_datastore
from recruit_app.user.models import User
from recruit_app.public.forms import LoginForm
from recruit_app.utils import flash_errors
from recruit_app.database import db
from recruit_app.blacklist.models import BlacklistCharacter

@blueprint.route("/", methods=["GET", "POST"])
def home():
    form = LoginForm(request.form)
    return render_template("public/home.html", login_user_form=form)

@blueprint.route("/login/", methods=["GET", "POST"])
def login():
    login_user_form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if login_user_form.validate_on_submit():
            login_user(login_user_form.user)
            flash("You are logged in.", 'success')
            redirect_url = request.args.get("next") or url_for("user.members")
            return redirect(redirect_url)
        else:
            flash_errors(login_user_form)
    return render_template("public/login.html", login_user_form=login_user_form)


@blueprint.route('/logout/')
@login_required
def logout():
    logout_user()
    flash('You are logged out.', 'info')
    return redirect(url_for('public.home'))


@blueprint.route("/about/")
def about():

    form = LoginForm(request.form)