Beispiel #1
0
def register():
    """Registers the user."""
    if g.user:
        return redirect(url_for('timeline'))
    error = None
    if request.method == 'POST':
        if not request.form['username']:
            error = 'You have to enter a username'
        elif not request.form['email'] or \
                '@' not in request.form['email']:
            error = 'You have to enter a valid email address'
        elif not request.form['password']:
            error = 'You have to enter a password'
        elif request.form['password'] != request.form['password2']:
            error = 'The two passwords do not match'
        elif get_user_id(request.form['username']) is not None:
            error = 'The username is already taken'
        else:
            db = get_db()
            db.execute('''insert into user (
              username, email, pw_hash) values (?, ?, ?)''',
              [request.form['username'], request.form['email'],
               generate_password_hash(request.form['password'])])
            db.commit()
            flash('You were successfully registered and can login now')
            return redirect(url_for('login'))
    return render_template('register.html', error=error)
Beispiel #2
0
def register():
    """Registers the user."""
    if g.user:
        return redirect(url_for('timeline'))
    error = None
    if request.method == 'POST':
        if not request.form['username']:
            error = 'You have to enter a username'
        elif not request.form['email'] or \
                '@' not in request.form['email']:
            error = 'You have to enter a valid email address'
        elif not request.form['password']:
            error = 'You have to enter a password'
        elif request.form['password'] != request.form['password2']:
            error = 'The two passwords do not match'
        elif get_user_id(request.form['username']) is not None:
            error = 'The username is already taken'
        else:
            db = get_db()
            db.execute(
                '''insert into user (
              username, email, pw_hash) values (?, ?, ?)''', [
                    request.form['username'], request.form['email'],
                    generate_password_hash(request.form['password'])
                ])
            db.commit()
            flash('You were successfully registered and can login now')
            return redirect(url_for('login'))
    return render_template('register.html', error=error)
Beispiel #3
0
def test_escaping_without_template_filename():
    app = keyes.Keyes(__name__)
    with app.test_request_context():
        assert keyes.render_template_string(
            '{{ foo }}', foo='<test>') == '&lt;test&gt;'
        assert keyes.render_template('mail.txt', foo='<test>') == \
            '<test> Mail'
Beispiel #4
0
def test_escaping_without_template_filename():
    app = keyes.Keyes(__name__)
    with app.test_request_context():
        assert keyes.render_template_string('{{ foo }}',
                                            foo='<test>') == '&lt;test&gt;'
        assert keyes.render_template('mail.txt', foo='<test>') == \
            '<test> Mail'
Beispiel #5
0
 def index():
     return keyes.render_template(
         [
             'no_template.xml',  # should skip this one
             'simple_template.html',  # should render this
             'context_template.html'
         ],
         value=23)
Beispiel #6
0
def public_timeline():
    """Displays the latest messages of all users."""
    return render_template('timeline.html',
                           messages=query_db(
                               '''
        select message.*, user.* from message, user
        where message.author_id = user.user_id
        order by message.pub_date desc limit ?''', [PER_PAGE]))
Beispiel #7
0
def test_templates_and_static(test_apps):
    from blueprintapp import app
    c = app.test_client()

    rv = c.get('/')
    assert rv.data == b'Hello from the Frontend'
    rv = c.get('/admin/')
    assert rv.data == b'Hello from the Admin'
    rv = c.get('/admin/index2')
    assert rv.data == b'Hello from the Admin'
    rv = c.get('/admin/static/test.txt')
    assert rv.data.strip() == b'Admin File'
    rv.close()
    rv = c.get('/admin/static/css/test.css')
    assert rv.data.strip() == b'/* nested file */'
    rv.close()

    # try/finally, in case other tests use this app for Blueprint tests.
    max_age_default = app.config['SEND_FILE_MAX_AGE_DEFAULT']
    try:
        expected_max_age = 3600
        if app.config['SEND_FILE_MAX_AGE_DEFAULT'] == expected_max_age:
            expected_max_age = 7200
        app.config['SEND_FILE_MAX_AGE_DEFAULT'] = expected_max_age
        rv = c.get('/admin/static/css/test.css')
        cc = parse_cache_control_header(rv.headers['Cache-Control'])
        assert cc.max_age == expected_max_age
        rv.close()
    finally:
        app.config['SEND_FILE_MAX_AGE_DEFAULT'] = max_age_default

    with app.test_request_context():
        assert keyes.url_for('admin.static',
                             filename='test.txt') == '/admin/static/test.txt'

    with app.test_request_context():
        with pytest.raises(TemplateNotFound) as e:
            keyes.render_template('missing.html')
        assert e.value.name == 'missing.html'

    with keyes.Keyes(__name__).test_request_context():
        assert keyes.render_template('nested/nested.txt') == 'I\'m nested'
Beispiel #8
0
def test_templates_and_static(test_apps):
    from blueprintapp import app
    c = app.test_client()

    rv = c.get('/')
    assert rv.data == b'Hello from the Frontend'
    rv = c.get('/admin/')
    assert rv.data == b'Hello from the Admin'
    rv = c.get('/admin/index2')
    assert rv.data == b'Hello from the Admin'
    rv = c.get('/admin/static/test.txt')
    assert rv.data.strip() == b'Admin File'
    rv.close()
    rv = c.get('/admin/static/css/test.css')
    assert rv.data.strip() == b'/* nested file */'
    rv.close()

    # try/finally, in case other tests use this app for Blueprint tests.
    max_age_default = app.config['SEND_FILE_MAX_AGE_DEFAULT']
    try:
        expected_max_age = 3600
        if app.config['SEND_FILE_MAX_AGE_DEFAULT'] == expected_max_age:
            expected_max_age = 7200
        app.config['SEND_FILE_MAX_AGE_DEFAULT'] = expected_max_age
        rv = c.get('/admin/static/css/test.css')
        cc = parse_cache_control_header(rv.headers['Cache-Control'])
        assert cc.max_age == expected_max_age
        rv.close()
    finally:
        app.config['SEND_FILE_MAX_AGE_DEFAULT'] = max_age_default

    with app.test_request_context():
        assert keyes.url_for('admin.static', filename='test.txt') == '/admin/static/test.txt'

    with app.test_request_context():
        with pytest.raises(TemplateNotFound) as e:
            keyes.render_template('missing.html')
        assert e.value.name == 'missing.html'

    with keyes.Keyes(__name__).test_request_context():
        assert keyes.render_template('nested/nested.txt') == 'I\'m nested'
Beispiel #9
0
def login():
    error = None
    if request.method == 'POST':
        if request.form['username'] != app.config['USERNAME']:
            error = 'Invalid username'
        elif request.form['password'] != app.config['PASSWORD']:
            error = 'Invalid password'
        else:
            session['logged_in'] = True
            flash('You were logged in')
            return redirect(url_for('show_entries'))
    return render_template('login.html', error=error)
Beispiel #10
0
def login():
    error = None
    if request.method == 'POST':
        if request.form['username'] != app.config['USERNAME']:
            error = 'Invalid username'
        elif request.form['password'] != app.config['PASSWORD']:
            error = 'Invalid password'
        else:
            session['logged_in'] = True
            flash('You were logged in')
            return redirect(url_for('show_entries'))
    return render_template('login.html', error=error)
Beispiel #11
0
def timeline():
    """Shows a users timeline or if no user is logged in it will
    redirect to the public timeline.  This timeline shows the user's
    messages as well as all the messages of followed users.
    """
    if not g.user:
        return redirect(url_for('public_timeline'))
    return render_template('timeline.html', messages=query_db('''
        select message.*, user.* from message, user
        where message.author_id = user.user_id and (
            user.user_id = ? or
            user.user_id in (select whom_id from follower
                                    where who_id = ?))
        order by message.pub_date desc limit ?''',
        [session['user_id'], session['user_id'], PER_PAGE]))
Beispiel #12
0
def timeline():
    """Shows a users timeline or if no user is logged in it will
    redirect to the public timeline.  This timeline shows the user's
    messages as well as all the messages of followed users.
    """
    if not g.user:
        return redirect(url_for('public_timeline'))
    return render_template(
        'timeline.html',
        messages=query_db(
            '''
        select message.*, user.* from message, user
        where message.author_id = user.user_id and (
            user.user_id = ? or
            user.user_id in (select whom_id from follower
                                    where who_id = ?))
        order by message.pub_date desc limit ?''',
            [session['user_id'], session['user_id'], PER_PAGE]))
Beispiel #13
0
def login():
    """Logs the user in."""
    if g.user:
        return redirect(url_for('timeline'))
    error = None
    if request.method == 'POST':
        user = query_db('''select * from user where
            username = ?''', [request.form['username']], one=True)
        if user is None:
            error = 'Invalid username'
        elif not check_password_hash(user['pw_hash'],
                                     request.form['password']):
            error = 'Invalid password'
        else:
            flash('You were logged in')
            session['user_id'] = user['user_id']
            return redirect(url_for('timeline'))
    return render_template('login.html', error=error)
Beispiel #14
0
def user_timeline(username):
    """Display's a users tweets."""
    profile_user = query_db('select * from user where username = ?',
                            [username], one=True)
    if profile_user is None:
        abort(404)
    followed = False
    if g.user:
        followed = query_db('''select 1 from follower where
            follower.who_id = ? and follower.whom_id = ?''',
            [session['user_id'], profile_user['user_id']],
            one=True) is not None
    return render_template('timeline.html', messages=query_db('''
            select message.*, user.* from message, user where
            user.user_id = message.author_id and user.user_id = ?
            order by message.pub_date desc limit ?''',
            [profile_user['user_id'], PER_PAGE]), followed=followed,
            profile_user=profile_user)
Beispiel #15
0
def login():
    """Logs the user in."""
    if g.user:
        return redirect(url_for('timeline'))
    error = None
    if request.method == 'POST':
        user = query_db('''select * from user where
            username = ?''', [request.form['username']],
                        one=True)
        if user is None:
            error = 'Invalid username'
        elif not check_password_hash(user['pw_hash'],
                                     request.form['password']):
            error = 'Invalid password'
        else:
            flash('You were logged in')
            session['user_id'] = user['user_id']
            return redirect(url_for('timeline'))
    return render_template('login.html', error=error)
Beispiel #16
0
def user_timeline(username):
    """Display's a users tweets."""
    profile_user = query_db('select * from user where username = ?',
                            [username],
                            one=True)
    if profile_user is None:
        abort(404)
    followed = False
    if g.user:
        followed = query_db('''select 1 from follower where
            follower.who_id = ? and follower.whom_id = ?''',
                            [session['user_id'], profile_user['user_id']],
                            one=True) is not None
    return render_template('timeline.html',
                           messages=query_db(
                               '''
            select message.*, user.* from message, user where
            user.user_id = message.author_id and user.user_id = ?
            order by message.pub_date desc limit ?''',
                               [profile_user['user_id'], PER_PAGE]),
                           followed=followed,
                           profile_user=profile_user)
Beispiel #17
0
 def index():
     return keyes.render_template('index.html')
Beispiel #18
0
 def index():
     return keyes.render_template('context_template.html', value=23)
Beispiel #19
0
 def index():
     return keyes.render_template('index.html')
Beispiel #20
0
def index():
    """Just a generic index page to show."""
    return render_template('index.html')
Beispiel #21
0
def index():
    return render_template('frontend/index.html')
Beispiel #22
0
def show_entries():
    db = get_db()
    cur = db.execute('select title, text from entries order by id desc')
    entries = cur.fetchall()
    return render_template('show_entries.html', entries=entries)
Beispiel #23
0
def show_entries():
    db = get_db()
    cur = db.execute('select title, text from entries order by id desc')
    entries = cur.fetchall()
    return render_template('show_entries.html', entries=entries)
Beispiel #24
0
def index():
    """Just a generic index page to show."""
    return render_template('index.html')
Beispiel #25
0
 def index():
     return keyes.render_template('non_escaping_template.txt', text=text,
                                  html=keyes.Markup(text))
Beispiel #26
0
def show(page):
    try:
        return render_template('pages/%s.html' % page)
    except TemplateNotFound:
        abort(404)
Beispiel #27
0
def index2():
    return render_template('./admin/index.html')
Beispiel #28
0
 def index():
     return keyes.render_template('context_template.html', value=23)
Beispiel #29
0
 def index():
     return keyes.render_template('non_escaping_template.txt',
                                  text=text,
                                  html=keyes.Markup(text))
Beispiel #30
0
 def index():
     return keyes.render_template('simple_template.html', whiskey=42)
Beispiel #31
0
 def index():
     return keyes.render_template('template_filter.html', value='abcd')
Beispiel #32
0
def index():
    return render_template('admin/index.html')
Beispiel #33
0
def public_timeline():
    """Displays the latest messages of all users."""
    return render_template('timeline.html', messages=query_db('''
        select message.*, user.* from message, user
        where message.author_id = user.user_id
        order by message.pub_date desc limit ?''', [PER_PAGE]))
Beispiel #34
0
 def index():
     return keyes.render_template(
         ['no_template.xml',  # should skip this one
         'simple_template.html',  # should render this
         'context_template.html'],
         value=23)
Beispiel #35
0
def missing_template():
    return render_template('missing_template.html')
Beispiel #36
0
def index():
    return render_template('index.html')
Beispiel #37
0
def show(page):
    try:
        return render_template('pages/%s.html' % page)
    except TemplateNotFound:
        abort(404)
Beispiel #38
0
 def index():
     return keyes.render_template('template_filter.html', value='abcd')
Beispiel #39
0
 def index():
     return keyes.render_template('template_test.html', value=False)
Beispiel #40
0
 def index():
     return keyes.render_template('simple_template.html', whiskey=42)
Beispiel #41
0
 def index():
     return keyes.render_template('template_test.html', value=False)
Beispiel #42
0
def index():
    return render_template('index.html')