Example #1
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_image(form.picture.data)
            current_user.image_file = picture_file

        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('As informações da conta foram atualizadas', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email

    image_file = url_for(
        'static',
        filename=f'profile_pics/{current_user.image_file}'
    )
    return render_template(
        'account.html',
        title='Minha conta',
        image_file=image_file,
        form=form
    )
Example #2
0
def profile_settings():
    form = ProfileSettingsForm()

    if form.validate_on_submit():
        if form.image_file.data:
            new_file_name = save_image(form.image_file.data)
            # update current user's profile pic in DB
            current_user.image_file = new_file_name

        current_user.name = form.name.data
        current_user.email = form.email.data
        # save the settings to db
        db.session.commit()
        flash('Settings Updated Successfully', 'positive')
        return redirect(url_for('users.profile', username=current_user.name))

    # set the placeholders for the input fields
    elif request.method == 'GET':
        form.name.data = current_user.name
        form.email.data = current_user.email

    image_file = url_for(
        'static', filename=f'profile_pictures/{current_user.image_file}')
    return render_template('profile_settings.html',
                           title='Profile Settings',
                           image_file=image_file,
                           form=form)
Example #3
0
def my_account():
    form = UpdateUserForm()
    if form.validate_on_submit():
        if form.picture.data:
            profile_picture = save_image(form.picture.data)
            current_user.profile_image = profile_picture
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated successfully', 'success')
        return redirect(url_for('users.my_account'))
    if request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    return render_template('account.html', title='My Account page', form=form)
Example #4
0
def account():
    form = UpdateForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_image(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been Updated!', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static', filename='profile_pics/' + current_user.image_file)
    return render_template('account.html', title='Account', image_file=image_file, form=form)
Example #5
0
def account():
	form = UpdateForm()
	if form.validate_on_submit():
		if form.picture.data:
			picture_file = save_image(form.picture.data)
			current_user.user_image = picture_file
		current_user.username = form.username.data
		current_user.email = form.email.data
		db.session.commit()
		flash("Your account has been successfully updated","success")
		return redirect(url_for('users.account'))
	elif request.method == 'GET':
		form.username.data = current_user.username
		form.email.data = current_user.email
	image_file = url_for("static", filename="profile_pictures/" + current_user.user_image)
	return render_template("account.html", title="Account Info", image_file=image_file, form=form)
Example #6
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        if form.image.data:
            image_file = save_image(form.image.data)
            post = Post(title=form.title.data,
                        content=sanitize_html(form.content.data),
                        author=current_user,
                        image=image_file)
        else:
            post = Post(title=form.title.data,
                        content=sanitize_html(form.content.data),
                        author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Your post has been created!', 'success')
        return redirect(url_for('main.home'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='New Post')
Example #7
0
def settings(user_id):
    if not current_user.is_authenticated:
        return redirect(url_for('users.login'))
    user = User.query.get(user_id)
    form = forms.UpdateUserForm()
    form.username.data = user.username
    form.email.data = user.email
    form.bio.data = user.bio
    if request.method == 'POST':
        form = forms.UpdateUserForm()
        if form.validate_on_submit():
            user.username = form.username.data
            user.email = form.email.data
            user.bio = form.bio.data
            if form.profile_image.data:
                image = save_image(form.profile_image.data)
                user.profile_image = image
            db.session.commit()
            flash('Updated successfuly', 'success')
            return redirect(url_for('users.profile', user_id=current_user.id))

    return render_template('settings.html', title='Settings', form=form)
Example #8
0
def update_post(post_id):
    post = Post.query.get_or_404(post_id)
    if post.author != current_user and current_user.is_admin == False:
        abort(403)
    else:
        form = PostForm()
        if form.validate_on_submit():
            post.title = form.title.data
            post.content = sanitize_html(form.content.data)
            if form.image.data:
                image_file = save_image(form.image.data)
                post.image = image_file
            db.session.commit()
            flash('Your post has been updated!', 'success')
            return redirect(url_for('posts.post', post_id=post.id))
        elif request.method == 'GET':
            form.title.data = post.title
            form.content.data = sanitize_html(post.content)
            form.image.data = post.image
    return render_template('create_post.html',
                           title='Update Post',
                           form=form,
                           legend='Update Post')