示例#1
0
def login():
    login_form = form.LoginForm()
    if not login_form.validate_on_submit():
        return jsonify(errors=login_form.errors)

    email = login_form.email.data
    password = login_form.password.data

    try:
        user = User.query.filter_by(email=email, password=password).one()
    except exc.NoResultFound:
        return pages.index(login_form=login_form, bad_login=True)

    login_user(user)
    return fl.redirect(fl.url_for("index"))
示例#2
0
def app(environ, start_response):
    '''App object'''

    ## environ is a dict of environment variables
    # gunicorn theoretically can handle auth?? MEHHH

    # parse_qs returns a dict from the query string
    queryd = parse_qs(environ['QUERY_STRING'])
    print queryd
    #wtf why can't gunicorn/wsgi take a unicode string list

    data = pages.index(queryd).encode('utf-8')  # construct the page

    status = '200 OK'
    response_headers = [('Content-type', 'text/html; charset=utf-8'),
                        ('Content-length', str(len(data)))]
    start_response(status, response_headers)

    return iter([data])
示例#3
0
def register():
    register_form = form.RegisterForm()
    if not register_form.validate_on_submit():
        return jsonify(errors=register_form.errors)

    name = register_form.name.data
    email = register_form.email.data
    password = register_form.password.data

    user = User.query.filter_by(email=email).first()
    if user is None:
        user = User(email=email, name=name, password=password)

        db.session.add(user)
        db.session.commit()

        login_user(user)
        return fl.redirect(fl.url_for("index"))

    return pages.index(bad_register=True)
示例#4
0
def show_page():
    return index()
示例#5
0
def index():
    return pages.index()
示例#6
0
import datetime

from flask import Flask, render_template
from flask_frozen import Freezer
import yaml

import pages

app = Flask(__name__)

# list of pages and their rendering functions
page_list = [("/", "index", pages.index("data/main_links.yml")),
             ("/quicklinks/", "quicklinks",
              pages.quicklinks("data/quicklinks.yml")),
             ("/fontinfo/", "fontinfo",
              pages.text("font information", "data/fontinfo.html")),
             ("/404.html", "404", pages.text("404", "data/404.html"))]

# add each page to app
for rule, endpoint, view_func in page_list:
    if rule[-1] == '/':  # add "index.html" if necessary for freezing purposes
        rule += "index.html"
    app.add_url_rule(rule, endpoint, view_func)


# generate sitemap from page_list
@app.route("/sitemap.xml")
def sitemap():
    locations = [rule for rule, endpoint, _ in page_list if endpoint != "404"]
    date = datetime.datetime.now().strftime("%Y-%m-%d")
    return render_template("sitemap.xml", date=date, locations=locations)