def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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('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)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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('Your account has been updated!', 'success') # this avoids "are you sure you want to reload the page? form data will be sent again..." 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)
def profile(): form = UpdateAccountForm() if form.validate_on_submit(): if form.new_thumbnail.data: new_thumbnail = save_thumbnail(form.new_thumbnail.data) current_user.thumbnail = new_thumbnail current_user.username = form.new_username.data current_user.email = form.new_email.data db.session.commit() flash('Your account has been successfully updated!', 'success') return redirect(url_for('users.profile')) elif request.method == 'GET': form.new_username.data = current_user.username form.new_email.data = current_user.email thumbnail = url_for('static', filename='thumbnails/' + current_user.thumbnail) return render_template('profile.html', title=f"{current_user.username}'s profile", legend='Update profile', thumbnail=thumbnail, form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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('Your account has been updated', 'success') return redirect(url_for('users.account')) elif request.method == 'GET': # this ensures form loads withcurrent user data when first loaded 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)
def user_posts(username): page = request.args.get('page', 1, type=int) user = User.query.filter_by(username=username).first_or_404() posts = Post.query.filter_by(author=user)\ .order_by(Post.date_posted.desc())\ .paginate(page=page, per_page=5) form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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('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('user_posts.html', posts=posts, user=user, form=form, image_file=image_file, title=user.username)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.pic.data: pic_file = save_pic(form.pic.data) current_user.image_file = pic_file # sqlAlchemy lets you just change user variable current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('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)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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('Your account details has been updated successfully !!', '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)
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)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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("Account has been updated", "success") return redirect(url_for('users.account')) elif request.method == 'GET': # If we load the webpage form.email.data = current_user.email form.username.data = current_user.username image_file = url_for('static', filename='profile_pic/' + current_user.image_file) return render_template('account.html', title="Account", image_file=image_file, form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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(u"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 # static folder, path = images/profile/image.png image_file = url_for('static', filename="images/profile/" + current_user.image_file) return render_template("account.html", title="Account", image_file=image_file, form=form)
def account_update(): try: form = UpdateAccountForm() website = User.query.filter_by(id=current_user.id).first() if form.validate_on_submit(): current_user.name = form.name.data current_user.email = form.email.data.lower() cu = stripe.Customer.retrieve(current_user.customer_id) cu.email = current_user.email cu.save() db.session.commit() flash("Your account information has been updated!", 'success') return redirect(url_for('users.account')) elif request.method == 'GET': form.name.data = current_user.name form.email.data = current_user.email return render_template("update_account.html", title="Update Account Info", form=form, post=website) except Exception as e: SendErrMail(e)
def account(): players_pattern = get_player_pattern() form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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('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) if (request.method == 'POST'): return nav_search() return render_template('account.html', title='Account', image_file=image_file, form=form, players_pattern=players_pattern)
def account(user_id): user = User.query.get(user_id) image_file = url_for('static', filename='profile_pics/' + user.image_file) form = UpdateAccountForm() if current_user.id == user.id: if form.validate_on_submit(): if form.picture.data: picture_fn_name = save_picture(form.picture.data) current_user.image_file = picture_fn_name 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', user_id=current_user.id)) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email return render_template("account.html", title="Account", image_file=image_file, form=form, user=user)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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('Account Info Updated!', 'success') return redirect( url_for('users.account' )) # redirecting here avoids post -> get redirect pattern 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)
def account(): image_file = url_for('static', filename='profile_pics/' + current_user.image_file) form = UpdateAccountForm() if form.validate_on_submit(): if form.pic.data: pic_file = save_pic(form.pic.data) current_user.image_file = pic_file current_user.email = form.email.data current_user.username = form.username.data db.session.commit() flash('Profile has been updated!', 'success') redirect( url_for('users.account') ) #avoid post re post form request, so run get request with redirect instead elif request.method == 'GET': form.email.data = current_user.email form.username.data = current_user.username return render_template('account.html', title="Account", form=form, image_file=image_file)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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('Successfully Updated Account!', 'success') logger.info(f'Updated account for user: {current_user.username}') 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, today=date.today())
def account(): form = UpdateAccountForm() if form.validate_on_submit(): #check if there's picture data if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file User.objects(email=current_user.email).update_one(image_file=picture_file) current_user.username = form.username.data current_user.email = form.email.data User.objects(email=current_user.email).update_one( username=form.username.data, email=form.email.data ) flash('account updated', 'success') return redirect(url_for('users.account')) elif request.method == 'GET': # populate form fields 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)
def account(): form = UpdateAccountForm() #Vérifie si le formulaire est valide if form.validate_on_submit(): #change et commit les valeurs if form.picture.data: 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("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)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file if (form.username.data != current_user.username or form.email.data != current_user.email or form.picture.data): current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash("Account info updated successfully!", "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)
def update_info(): form = UpdateAccountForm() image_file = url_for('static', filename='profile_pics/' + current_user.image_file) if form.validate_on_submit(): #checking if profile picture is updated if form.picture.data: picture_fn = save_picture(form.picture.data) current_user.image_file = picture_fn #update the user info in database current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Account info updated!', 'success') return redirect(url_for('users.account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email return render_template('update_info.html', title='update info', form=form, image_file=image_file)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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 plus bootstrap category flash('Your account has been updated!', 'success') # post-get-redirect pattern, odes a GET request instead of another post 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)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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("Your account information has been updated", "success") return redirect(url_for("users.account")) # POST GET redirect pattern 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) print(current_user.image_file) return render_template("account.html", title="Account", image_file=image_file, form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) remove_old_file = os.path.join(os.getcwd() + "/flaskblog/static/profile_pics/" + current_user.image_file) default_picture = os.path.join(os.getcwd() + "/flaskblog/static/profile_pics/default.jpg") if os.path.exists(remove_old_file): if remove_old_file != default_picture: os.remove(remove_old_file) print('File ' + remove_old_file + ' REMOVED!!') 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)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_date(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(f"Account has been updated", category='success') return redirect(url_for('users.account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email posts = Post.query.order_by( Post.date_posted.desc()).filter_by(author=current_user).all() 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, posts=posts)
def account(): form = UpdateAccountForm() # if we submit the form request.method == 'POST': if form.validate_on_submit(): if form.picture.data: 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(f'Your Account is Updated', 'success') return redirect(url_for('users.account')) # if we just access normally the account page elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email image_file = url_for('static', filename='image/' + current_user.image_file) return render_template('account.html', title='Account', image_file=image_file, form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: print(form.picture.data) 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('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) msgs = Message.query.filter_by(author=current_user).all() return render_template('account.html', title='Account', image_file=image_file, form=form, messages=msgs)
def account(): form = UpdateAccountForm() # use acc update import for image updates if form.validate_on_submit(): if form.picture.data: 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('Account details updated!', 'success') return redirect(url_for( 'users.account')) # redirect back to account page after update elif request.method == 'GET': # populate data for update form.username.data = current_user.username form.email.data = current_user.email #set default avatar image_file = url_for('static', filename='profilepic/' + current_user.image_file ) # name of the column storing images in models.py return render_template('account.html', title='Account', image_file=image_file, form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) if current_user.image_file != "default.jpg": old_picture = current_user.image_file remove_picture(old_picture) 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("users/account.html", title="Account", image_file=image_file, form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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('Your account has been updated!', 'success') # Redirects so that we avoid having a 'confirm?' message in our browser when updating the form return redirect(url_for('users.account')) # Populates with current user data 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)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.profile.data: profile_file = save_profile(form.profile.data) current_user.image_file = profile_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')) if request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email image_file = url_for('static', filename='profile_img/' + current_user.image_file) return render_template('account.html', title='Account', image_file=image_file, form=form)
def account(): if current_user.is_auth == 0: if current_user.is_authenticated: flash("You need to Confirm you email address for you to log in", "info") return redirect(url_for('users.logout')) flash("You need to Confirm you email address for you to log in", "info") return redirect(url_for('users.dashboard')) form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: 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('Your account has been updated!', 'success') return redirect(url_for('users.account_details')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email image_file = url_for('static', filename='profile_pic/' + current_user.image_file) return render_template('account.html', title='Account', image_file=image_file, form=form)