Example #1
0
def login_view():
    """
    Renders a login page and redirects to the index on completion
    """
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user = get_user(form.data['shortname'])
        login_user(user)
        return redirect(url_for('admin.index'))
    return render_template_with_models('login.html', form=form)
Example #2
0
def profile_view(name):
    """
    Renders a profile page for a user

    :param name: shortname to look up the user
    """
    user = get_user(name)
    if user is None:
        abort(404)
    return render_template_with_models('profile.html', user=user)
Example #3
0
def user_view(name):
    """
    Render a page with a listing of all of a user's posts

    :param name: shortname to look up the user
    """
    user = get_user(name)
    if user is None:
        abort(404)
    user_posts = sorted(user.posts, key=lambda x: x.date)
    return render_template_with_models('user_posts.html', user=user, user_posts=user_posts)
Example #4
0
def post_view(slug):
    """
    Renders a page for an individual post

    :param slug: slug to look up the post
    """
    post = get_post(slug)
    if post is None:
        abort(404)
    user = get_user(post.user_shortname)
    services = user.services
    return render_template_with_models('post.html', post=post, user=user, services=services)
Example #5
0
def validate_login(form, field):
    """
    Validation method to check that the user is valid and the password matches

    :param form: The form from the login template
    :param field: The Field this validator is attached to
    :raise ValidationError: Raises if the user is invalid or the password does not match
    """
    user = get_user(form.shortname.data)

    if user is None:
        raise ValidationError('Invalid user')
    elif not user.check_password(form.password.data):
        raise ValidationError('Bad password')