Esempio n. 1
0
def account():
    form = AccountInfo()
    if form.validate_on_submit():
        if form.picture.data:
            # delete current profile image if current is not default.jpg
            if current_user.image_file != 'default.jpg':
                delete_picture(current_user.image_file)

            # save new profile image
            current_user.image_file = save_picture(form.picture.data)
        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',
                           form=form,
                           image_file=image_file)
Esempio n. 2
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            delete_picture(current_user.image_file)
            picture_file = save_picture(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('You have updated your profile.', category='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',
                           form=form, image_file=image_file)
Esempio n. 3
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            if current_user.image_file and 'default.jpeg' not in current_user.image_file:
                delete_picture(current_user.image_file)
            current_user.image_file = save_picture(form.picture.data)
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Account info has been updated', 'ui positive message')
        return redirect('account')
    if 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='Account',
                           image_file=image_file,
                           form=form)
Esempio n. 4
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        # Check if picture was uploaded
        if form.file.data:
            # Save picture locally
            picture_name = save_picture(form.file.data)
            previous_image = current_user.image_file
            current_user.image_file = picture_name
            # Delete previous picture
            delete_picture(previous_image)
        # Update database and redirect to account
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash("Your account has been updated!", "success")
        return redirect("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="Account", image_file=image_file, form=form)