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)
def usertabelle(): users = db.query(User) return render_template("users.html", redirectTo=getPath(), users=users)
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())
def pwny(): return render_template("pwnyname.html", redirectTo=getPath())
def gallery(): return render_template("gallery.html", redirectTo=getPath())
def crypto(): return render_template("crypto.html", redirectTo=getPath())
def faq(): return render_template("faq.html", redirectTo=getPath())
def about(): return render_template("about.html", redirectTo=getPath())