def account(): information_form = UpdateForm() if information_form.validate_on_submit(): if information_form.profile_picture.data: image_file = save_picture(information_form.profile_picture.data) current_user.profile_pic = image_file current_user.username = information_form.username.data current_user.email = information_form.email.data db.session.commit() flash(f'Your account has been updated successfully', 'success') return redirect(url_for('users.account')) elif request.method == 'GET': information_form.username.data = current_user.username information_form.email.data = current_user.email image_file = url_for( 'static', filename=f'Profile_Pictures/{current_user.profile_pic}') return render_template('account.htm', title='Account', image_file=image_file, form=information_form)
def updateprofile(user_id): user = User.query.get(user_id) if current_user != user: abort(403) form = UpdateProfile() if form.validate_on_submit(): if form.picture.data: user.image = save_picture(form.picture.data) user.email = form.email.data user.username = form.username.data user.information = form.information.data user.twitter = form.twitter.data user.Linkedin = form.linkedin.data user.instagram = form.instagram.data flash("Your profile has been updated", "success") db.session.commit() return redirect(url_for("users.profile", username=user.username)) elif request.method == "GET": form.username.data = user.username form.email.data = user.email form.twitter.data = user.twitter form.instagram.data = user.instagram form.linkedin.data = user.Linkedin return render_template("update_profile.html", form=form, legend="Update Profile", 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 db.session.commit() flash('Your account has been updated', 'success') return redirect(url_for('main.account')) elif request.method == 'GET': form.username.data = current_user.username 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_url = save_picture(form.picture.data) current_user.image_file = picture_url current_user.username = form.username.data current_user.email = form.email.data current_user.save() 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 return render_template("users/account.html", title="Account", form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: file_name = save_picture(form.picture.data) current_user.image = file_name current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash("Your 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 image = url_for("static", filename=f"profile_pics/{current_user.image}") return render_template("account.html", title="Account", image=image, 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.save() flash(f'Your Account Have 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') return redirect( url_for('users.account')) #to avoid the post get redirect pattern 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('Updated Success', '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 the user wants to update account info 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') # don't use render_template here, so the browser doesn't submit the form twice return redirect(url_for('users.account')) # if user just navigates to account page 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: current_user.image_file = save_picture(form.picture.data) # add() the database automatically 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': # displays current username in the forms 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 # update users name and email 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': # populate the form with current username and email 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 about(): form = UpdateForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) current_user.picture = picture_file current_user.email = form.email.data # hash new password and then save it new_pwd_hashed = crypt.generate_password_hash(form.new_password.data) current_user.password = new_pwd_hashed db.session.commit() flash(f'Your account have been update', 'success') return redirect(url_for('users.about')) elif request.method == 'GET': form.email.data = current_user.email # render to about page picture = url_for('static', filename='pictures/' + current_user.picture) return render_template('about.html', title='About', picture=picture, form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: old_picture = current_user.image_file picture_file = save_picture(form.picture.data) current_user.image_file = picture_file #delete the old picture from the file system if is different than default if old_picture != 'default.jpg': old_picture_path = os.path.join(users.root_path, 'static/profile_pics', old_picture) try: os.remove(old_picture_path) except: pass 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)