# Path: app/models/users.py
# def create_account(email, password, nickname):
# def get_user_by_email(email):
# def is_email_available(email):
# def is_valid_password(password):
# def is_correct_password(email, password):
# def update(id, **kw):
# def get_user_by_id(id):
# 
# Path: app/helpers/session.py
# def add_sessions_to_app(app):
# def get_session():
# def is_logged():
# def login(email):
# def logout():
# def reset():
# def get_user_id():
# def get_last_visited_url():
# def set_last_visited_url():
# def login_required(meth):
#     def new(*args):
# def login_required_for_reviews(meth):
#     def new(*l):
# 
# Path: app/helpers/email_templates.py
# def to_applicant(applicant):
# def to_applicant_simple(applicant):
# def to_referee(applicant):
# def notify_applicant(applicant):
# def notify_referee(applicant):
# def resend_password(user):


import web
from web import form
from app.models import users
from app.helpers import session
from app.helpers import email_templates
from config import view
    form.Textbox('email', 
        form.notnull, vemail,
        form.Validator('There is no record of this email in our database.', 
        lambda x: not users.is_email_available(x)),
        description='Your email:'),
                
    form.Button('submit', type='submit', value='Register'),
)

def render_account(show='all', 
    login_form=login_form(), register_form=register_form(), forgot_password_form=forgot_password_form(), 
    on_success_message=''):
    
    return view.base(
        view.account(show, login_form, register_form, forgot_password_form, on_success_message))

class index:
    def GET(self):
        return render_account(show='all')

class login:
    def GET(self):
        return render_account(show='login_only')
    
    def POST(self):
        f = self.form()
        if not f.validates(web.input(_unicode=False)):
            show = web.input(show='all').show
            return render_account(show, login_form=f)
        else:

# Path: app/models/users.py
# def create_account(email, password, nickname):
# def get_user_by_email(email):
# def is_email_available(email):
# def is_valid_password(password):
# def is_correct_password(email, password):
# def update(id, **kw):
# def get_user_by_id(id):
# 
# Path: app/helpers/session.py
# def add_sessions_to_app(app):
# def get_session():
# def is_logged():
# def login(email):
# def logout():
# def reset():
# def get_user_id():
# def get_last_visited_url():
# def set_last_visited_url():
# def login_required(meth):
#     def new(*args):
# def login_required_for_reviews(meth):
#     def new(*l):
# 
# Path: app/helpers/email_templates.py
# def to_applicant(applicant):
# def to_applicant_simple(applicant):
# def to_referee(applicant):
# def notify_applicant(applicant):
# def notify_referee(applicant):
# def resend_password(user):


# Path: app/controllers/account.py
import web
from web import form
from app.models import users
from app.helpers import session
from app.helpers import email_templates
from config import view

    form.Textbox('email', 
        form.notnull, vemail,
        form.Validator('There is no record of this email in our database.', 
        lambda x: not users.is_email_available(x)),
        description='Your email:'),
                
    form.Button('submit', type='submit', value='Register'),
)

def render_account(show='all', 
    login_form=login_form(), register_form=register_form(), forgot_password_form=forgot_password_form(), 
    on_success_message=''):
    
    return view.base(
        view.account(show, login_form, register_form, forgot_password_form, on_success_message))

class index:
    def GET(self):
        return render_account(show='all')

class login:
    def GET(self):
        return render_account(show='login_only')
    
    def POST(self):
        f = self.form()
        if not f.validates(web.input(_unicode=False)):
            show = web.input(show='all').show
            return render_account(show, login_form=f)
        else:

            session.login(f.d.email)