Exemple #1
0
def posts():

    current_user = request.user

    if request.method == "POST":

        title = request.form.get("posttitle")
        text = request.form.get("posttext")
        post = Post(
            title=title, text=text,
            user=current_user
        )
        db.session.add(post)
        db.session.commit()

        # send notification email
        # send notification email
        msg = Message(
            subject="WebDev Blog - Posted a post",
            sender=SENDER,
            recipients=[current_user.email]
        )

        full_post_link = HOST_ADDR + url_for('blog.post', post_id=post.id)

        msg.body = f"Hi {current_user.username}!\n" \
            f"There is news, check this out:{full_post_link}\n" \
            f"Enjoy!"
        msg.html = render_template("new_post.html",
                                   username=current_user.username,
                                   link=f"{full_post_link}",
                                   post=post)
        mail.send(msg)

        return redirect(url_for('blog.posts'))

    if request.method == "GET":
        posts = Post.query.all()
        return render_template("posts.html", posts=posts, redirectTo=getPath(), user=request.user)
Exemple #2
0
def usertabelle():
    users = db.query(User)
    return render_template("users.html", redirectTo=getPath(), users=users)
Exemple #3
0
def post(post_id):
    current_user = request.user
    post = Post.query.filter(Post.id == post_id).first()

    if request.method == "POST":

        text = request.form.get("text")

        comment = Comment(
            text=text,
            post=post,
            user=current_user
        )
        db.session.add(comment)
        db.session.commit()

        # if user writes comment, with all other users
        # who have written a comment in this post and notify them
        users = list(set([c.user for c in post.comments] + [post.user]))
        for user in users:
            # send notification email
            msg = Message(
                subject=f"Hello World Blog - News about a Blogpost you are interestet in",
                sender=SENDER,
                recipients=[user.email]
            )

            full_post_link = HOST_ADDR + url_for('blog.post', post_id=post.id)

            msg.body = f"Hi {user.username}!\n" \
                f"Another Comment Reply on the Post: {post.title}" \
                f"\n{full_post_link}" \
                f"\nEnjoy!"
            msg.html = render_template("new_comment.html",
                                       username=current_user.username,
                                       link=f"{full_post_link}",
                                       post=post,
                                       comment=comment)
            mail.send(msg)

        return redirect(url_for("blog.post", post_id=post.id))

    elif request.method == "GET":
        comments = Comment.query.filter(Comment.post_id == post_id).all()
        return render_template('post.html', post=post, comments=comments, user=request.user, redirectTo=getPath())
Exemple #4
0
def pwny():
    return render_template("pwnyname.html", redirectTo=getPath())
Exemple #5
0
def gallery():
    return render_template("gallery.html", redirectTo=getPath())
Exemple #6
0
def crypto():
    return render_template("crypto.html", redirectTo=getPath())
Exemple #7
0
def faq():
    return render_template("faq.html", redirectTo=getPath())
Exemple #8
0
def about():
    return render_template("about.html", redirectTo=getPath())