# Path: yams_api/utils/logger.py
# class ContextFilter(logging.Filter):
# class Logger:
#     def filter(self, record):
#     def __init__(self, formatter=None, log_level=config.DEFAULT_LOG_LEVEL, syslog_address="/dev/log"):
#     def syslog(self):
# 
# Path: yams/core/dev/users/forms.py
# class EmailPasswordForm(Form):
#     email = StringField('e-mail', validators=[DataRequired(), Email()])
#     password = PasswordField('password', validators=[DataRequired()])
# 
# class EmailSignupForm(EmailPasswordForm):
# 
#     first_name = StringField('Your first name', validators=[DataRequired(message="Please tell me your first name.")])
# 
# Path: yams/core/dev/users/methods.py
# class User(UserMixin):
#     """An intermediary state to calling the DB for a YAMS user.  Future plans need to support querying
#     multiple sources, which is why this is a middleware -- e.g. calling the User model and a node classifier.
# 
#     Further, this should support calling over to the API or another source
#     (e.g. if the user wants to use LDAP)
# 
#     """
# 
#     def __init__(self, first_name=None, username=None, email=None, password_from_web=None, supplied_token=None):
#         self.id = None
#         self.first_name = first_name
#         self.username = username
#         self.email = email
#         self.password_from_web = password_from_web
#         self.token = supplied_token
#         self.yams_queried_user_obj = self.user_object_from_db
# 
#     def is_active(self):
#         # pulling this one out of the super class because it's really important to implement
#         return True
# 
#     def token_valid(self):
#         if self.token == self.yams_queried_user_obj.token:
#             return True
# 
#     def create_account(self):
#         r = r_post(
#             API_HOST+"/core/user/create",
#             data={
#                 "email": self.email,
#                 "first_name": self.first_name,
#                 "password": self.password_from_web
#             }
#         )
#         print("sending!")
#         if not str(r.status_code).startswith("2"):
#             raise ValueError("Account possibly already exists for that e-mail address.")
#         return True
# 
#     @property
#     def user_object_from_db(self):
#         # todo: actually call the upstream auth source
#         return UserProps(
#             1,
#             'test_user',
#             'noreply@example.org',
#             '',
#             True,
#             True
#         )
# 
# 
#     @property
#     def to_properties(self):
#         # ['id', 'name', 'email', 'is_authenticated', 'active']
#         if self.is_active():
#             return UserProps(
#                 self.id,
#                 self.username,
#                 self.email,
#                 self.token,
#                 self.is_authenticated(),
#                 self.is_active()
#             )
# 
# class YAMSAnonymousUser(AnonymousUserMixin):
# 
#     # accept whatever, we're going to return an anonymous user
#     def __init__(self, *args, **kwargs):
#         self.id = 0
#         self.username = 'guest'
#         self.email = None
#         self.token = None
# 
#     @property
#     def to_properties(self):
#         return UserProps(
#             self.id,
#             self.username,
#             self.email,
#             self.token,
#             self.is_authenticated(),
#             self.is_active()
#         )
# 
# def confirm_token(token):
#     # send off token for confirmation in API
#     pass


from flask import Blueprint, jsonify, render_template, redirect, url_for, abort, flash
from yams_api.utils.logger import log
from .forms import EmailPasswordForm, EmailSignupForm
from .methods import User, YAMSAnonymousUser, confirm_token
    return render_template(
        "/core/dev/users.html",
        users=['todo: have this render an account management page']
    )

@core_users_bp.route("/account/login", methods=["GET", "POST"])
def user_account_login():

    form = EmailPasswordForm()
    if form.validate_on_submit():
        _user = User(
            email=form.email.data,
            password_from_web=form.password.data
        )
        # todo: call the API to see if this is correct
        return redirect(url_for('index'))

    return render_template(
        "/core/dev/users/login.html",
        form=form
    )


@core_users_bp.route("/account/create", methods=["GET", "POST"])
def user_account_create():

    form = EmailSignupForm()
    if form.validate_on_submit():

        # todo: call the API to try to create the account

# Path: yams_api/utils/logger.py
# class ContextFilter(logging.Filter):
# class Logger:
#     def filter(self, record):
#     def __init__(self, formatter=None, log_level=config.DEFAULT_LOG_LEVEL, syslog_address="/dev/log"):
#     def syslog(self):
# 
# Path: yams/core/dev/users/forms.py
# class EmailPasswordForm(Form):
#     email = StringField('e-mail', validators=[DataRequired(), Email()])
#     password = PasswordField('password', validators=[DataRequired()])
# 
# class EmailSignupForm(EmailPasswordForm):
# 
#     first_name = StringField('Your first name', validators=[DataRequired(message="Please tell me your first name.")])
# 
# Path: yams/core/dev/users/methods.py
# class User(UserMixin):
#     """An intermediary state to calling the DB for a YAMS user.  Future plans need to support querying
#     multiple sources, which is why this is a middleware -- e.g. calling the User model and a node classifier.
# 
#     Further, this should support calling over to the API or another source
#     (e.g. if the user wants to use LDAP)
# 
#     """
# 
#     def __init__(self, first_name=None, username=None, email=None, password_from_web=None, supplied_token=None):
#         self.id = None
#         self.first_name = first_name
#         self.username = username
#         self.email = email
#         self.password_from_web = password_from_web
#         self.token = supplied_token
#         self.yams_queried_user_obj = self.user_object_from_db
# 
#     def is_active(self):
#         # pulling this one out of the super class because it's really important to implement
#         return True
# 
#     def token_valid(self):
#         if self.token == self.yams_queried_user_obj.token:
#             return True
# 
#     def create_account(self):
#         r = r_post(
#             API_HOST+"/core/user/create",
#             data={
#                 "email": self.email,
#                 "first_name": self.first_name,
#                 "password": self.password_from_web
#             }
#         )
#         print("sending!")
#         if not str(r.status_code).startswith("2"):
#             raise ValueError("Account possibly already exists for that e-mail address.")
#         return True
# 
#     @property
#     def user_object_from_db(self):
#         # todo: actually call the upstream auth source
#         return UserProps(
#             1,
#             'test_user',
#             'noreply@example.org',
#             '',
#             True,
#             True
#         )
# 
# 
#     @property
#     def to_properties(self):
#         # ['id', 'name', 'email', 'is_authenticated', 'active']
#         if self.is_active():
#             return UserProps(
#                 self.id,
#                 self.username,
#                 self.email,
#                 self.token,
#                 self.is_authenticated(),
#                 self.is_active()
#             )
# 
# class YAMSAnonymousUser(AnonymousUserMixin):
# 
#     # accept whatever, we're going to return an anonymous user
#     def __init__(self, *args, **kwargs):
#         self.id = 0
#         self.username = 'guest'
#         self.email = None
#         self.token = None
# 
#     @property
#     def to_properties(self):
#         return UserProps(
#             self.id,
#             self.username,
#             self.email,
#             self.token,
#             self.is_authenticated(),
#             self.is_active()
#         )
# 
# def confirm_token(token):
#     # send off token for confirmation in API
#     pass


# Path: yams/core/dev/users/views.py
from flask import Blueprint, jsonify, render_template, redirect, url_for, abort, flash
from yams_api.utils.logger import log
from .forms import EmailPasswordForm, EmailSignupForm
from .methods import User, YAMSAnonymousUser, confirm_token

    return render_template(
        "/core/dev/users.html",
        users=['todo: have this render an account management page']
    )

@core_users_bp.route("/account/login", methods=["GET", "POST"])
def user_account_login():

    form = EmailPasswordForm()
    if form.validate_on_submit():
        _user = User(
            email=form.email.data,
            password_from_web=form.password.data
        )
        # todo: call the API to see if this is correct
        return redirect(url_for('index'))

    return render_template(
        "/core/dev/users/login.html",
        form=form
    )


@core_users_bp.route("/account/create", methods=["GET", "POST"])
def user_account_create():

    form = EmailSignupForm()
    if form.validate_on_submit():

        # todo: call the API to try to create the account

        _user = User(