def index(): posts = Post.query.order_by(Post.date_posted.desc()).limit(15).all() if current_user.is_authenticated: rendered_html = render_template('index.html', **holders, posts=posts, image_file=current_user_image_file(), input_search_form=search_form()) return html_minify(rendered_html) rendered_html = render_template('index.html', **holders, posts=posts, input_search_form=search_form()) return html_minify(rendered_html)
def profile(user): session['url'] = '/account/profile/' + user # print(session['url']) user = User.query.filter_by(username=user).first_or_404() # Public image path posts = Post.query.filter_by(author=user).order_by(Post.date_posted.desc()) if current_user.is_authenticated: return render_template('account/profile.html', title='Account', user=user, image_file=current_user_image_file(), input_search_form=search_form(), posts=posts) return render_template('account/profile.html', title='Account', user=user, posts=posts, input_search_form=search_form())
def sign_up(): form = SignUp() if request.method == 'POST' and form.validate_on_submit(): new_user = User(username=request.form['username'], email=request.form['email'], password_hash=generate_password_hash( request.form['password_hash'])) db.session.add(new_user) db.session.commit() flash('You Sign Up successfully.') return redirect(url_for('auth.home')) return render_template('auth/sign-up.html', input_search_form=search_form(), form=form)
def update_account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.image_file.data: image_file = save_picture(form.image_file.data) current_user.image_file = image_file current_user.username = form.username.data current_user.email = form.email.data current_user.git_username = form.git_username.data db.session.commit() flash('Your account has been updated!', 'success') return redirect(url_for('account.update_account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email form.git_username.data = current_user.git_username # Private image path return render_template('account/account.html', title='Account', image_file=current_user_image_file(), input_search_form=search_form(), form=form)
def sign_in(): global form if not current_user.is_authenticated: form = SignIn() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and check_password_hash(user.password_hash, form.password_hash.data): # login_user(user, remember=form.remember.data) login_user(user, remember=True) flash('You Sing In successfully.') if 'url' in session: return redirect(session['url']) else: return redirect(url_for('index')) elif current_user.is_authenticated: if 'url' in session: flash('You are already Signed In successfully.') return redirect(session['url']) else: return redirect(url_for('index')) return render_template('auth/sign-in.html', input_search_form=search_form(), form=form)