def attempt_login(): u = request.form["username"] p = request.form["password"] user = User.query.filter_by(sid=uidify(u)).first() if user and user.verify_password(p): session["user_sid"] = uidify(u) session.permanent = True return redirect("/") elif "'" in u or "'" in p: flash("H-honto baka!") else: flash("I don't recognize you, sorry.") return redirect("/")
def diary_latest(author_sid): author = User.query.filter_by(sid = uidify(author_sid)).first() if author: posts = author.posts.order_by(Post.posted_date.desc()).all() return render_diary(author, posts, "") else: return page_not_found()
def __init__(self, name, password, email=None, invite_key=""): self.sid = uidify(name) self.name = name self.set_password(password) self.email = email self.invite_key = invite_key self.join_time = datetime.now()
def diary(author_sid): # Dict of year: [list months] author = User.query.filter_by(sid = uidify(author_sid)).first() if author: posts = (author.posts.order_by(Post.posted_date.desc()) .limit(7).all()) return render_diary(author, posts, template="diary-search.html") else: return page_not_found()
def diary_search(author_sid): author = User.query.filter_by(sid = uidify(author_sid)).first() if author: print(request.form['search_term']) posts = (author.posts .order_by(Post.posted_date.desc()) .filter(Post.content.ilike('%%%s%%' % request.form['search_term'])) .limit(100).all()) posts = [p for p in posts if p.viewable_by(g.user, g.date)] return render_diary(author, posts, template="diary-search.html", search_term = request.form['search_term']) else: return page_not_found()
def diary_day(author_sid, year, month, day): author = User.query.filter_by(sid = uidify(author_sid)).first() if author: try: the_date = date(year, month, day) except ValueError: return page_not_found() else: post = author.posts.filter(Post.posted_date == the_date).first() if post: return render_diary(author, [post], the_date.strftime('%B %d, %Y'), template="diary-single.html") else: return page_not_found() else: return page_not_found()
def diary_month(author_sid, year, month): author = User.query.filter_by(sid = uidify(author_sid)).first() if author: try: min_date = date(year, month, 1) max_date = date(year, month, calendar.monthrange(year, month)[1]) except ValueError: return page_not_found() else: posts = author.posts\ .filter(Post.posted_date >= min_date)\ .filter(Post.posted_date <= max_date)\ .order_by(Post.posted_date.asc())\ .all() return render_diary(author, posts, min_date.strftime('')) else: return page_not_found()
def register_action(): invite_key = request.form.get('invite_key') username = request.form.get('username') password = request.form.get('password') email = request.form.get('email') or None # temporary session variables for registration session['cur_username'] = username session['cur_email'] = email # propriety checks if User.query.count() > 400 and invite_key != 'koi dorobou': flash("Actually, we're out of spots for registrations. Sorry!") elif len(username) < 2: flash("Please enter a username at least 2 characters long.") elif len(password) < 3: flash("Please enter a password at least 3 characters long.") elif User.query.filter_by(sid=uidify(username)).first(): flash("We already have someone with that name.") session['cur_username'] = '' else: new_user = User(username, password) new_user.email = email new_user.invite_key = invite_key new_user.timezone = g.timezone db.session.add(new_user) db.session.commit() session['user_sid'] = new_user.sid session.permanent = True # clear old session vars session['cur_username'] = '' session['cur_email'] = '' return redirect('/') # failed, send 'em back to the form return redirect('/register')
def diary_search_page(author_sid): author = User.query.filter_by(sid = uidify(author_sid)).first() if author: return render_diary(author, [], template="diary-search.html") else: return page_not_found()