Esempio n. 1
0
def load_logged_in_user():
    user_id = session.get('user_id')

    if user_id is None:
        g.user = None
    else:
        g.user = get_db.execute('SELECT * FROM user WHERE id = ?',
                                (user_id, )).fetchone
Esempio n. 2
0
def test_register(client, app):
    assert client.get('/auth/register').status_code == 200
    response = client.post('/auth/register',
                           data={
                               'username': '******',
                               'password': '******'
                           })
    assert 'http://localhost/auth/login' == response.headers['Location']

    with app.app_context():
        assert get_db.execute(
            "select * from user where username = '******'", ).fetchone() is not None
Esempio n. 3
0
def get_post(id, check_author=True):
    post = get_db.execute(
        'SELECT p.id, title, body, created, author_id, username'
        ' FROM post p JOIN user u ON p.author_id = u.id'
        ' WHERE p.id = ?', (id, )).fetchone()

    if post is None:
        abort(404, f'Post id {id} doesn\'t exist')

    if check_author and post['autor_id'] != g.user['id']:
        abort(403)

    return post