def profile(): edit_form = EditProfile(current_user.name) password_form = EditPassword() uplaod_photo = UploadPhoto() if uplaod_photo.validate_on_submit(): avatar = uplaod_photo.photo.data filename = secure_filename(generate_id(6) + ".jpg") avatar.save(os.path.join(app.config["UPLOAD_FOLDER"], filename)) current_user.avatar_id = filename db.session.commit() return redirect("/profile") if edit_form.validate_on_submit(): current_user.name = edit_form.username.data current_user.bio = edit_form.bio.data db.session.commit() return redirect("/profile") elif request.method == 'GET': edit_form.username.data = current_user.name edit_form.bio.data = current_user.bio if password_form.validate_on_submit(): if check_password_hash(current_user.password, password_form.password_old.data): current_user.password = generate_password_hash( password_form.password.data) db.session.commit() return redirect("/profile") return render_template("profile.html", form=edit_form, upload_ph=uplaod_photo, password_form=password_form, title="Profile")
def update_profile(): """Update profile for current user.""" if not g.user: flash("Access unauthorized.", "danger") return redirect("/") form = EditProfile(obj=g.user) if form.validate_on_submit(): g.user.location = form.location.data or None g.user.bio = form.bio.data or None g.user.header_image_url = form.header_image_url.data or None g.user.image_url = form.image_url.data or g.user.image_url g.user.username = form.username.data g.user.email = form.email.data password = form.password.data user = User.authenticate(g.user.username, password) if user: db.session.add(g.user) db.session.commit() return redirect(f"/users/{g.user.id}") else: flash("Password Incorrect") return render_template("users/edit.html", form=form, user_id=g.user.id)
def edit_user(user_id): user = User.query.filter_by(user_id=user_id).first() form = EditProfile(obj=user) if form.validate_on_submit(): form.populate_obj(user) db.session.commit() return redirect(url_for('user', user_id=user_id)) return render_template('edit_user.html', user=user, form=form)
def editprofile(id): user= User.query.filter_by(id=id).one() form = EditProfile() if form.validate_on_submit(): user.name= form.name.data user.email = form.email.data db.session.add(user) db.session.commit() flash('Profile Successfully edited.') return redirect(url_for('myprofile',id=id)) return render_template('editprofile.html',user=user, form=form)
def edit_profile(): newform=EditProfile() if newform.validate_on_submit(): current_user.name=newform.name.data current_user.location=newform.location.data current_user.about_me=newform.about_me.data db.session.add(current_user) flash('Profile Updated') return redirect(url_for('user',username=current_user.username)) newform.name.data=current_user.name newform.location.data=current_user.location newform.about_me.data=current_user.about_me return render_template('edit_profile.html',form=newform)
def editProfileAdmin(id): # Retrieve user or 404 code user = User.query.get_or_404(id) if current_user.username != user.username and not current_user.admin(): abort(403) # Create form object form = EditProfile() # If request method is POST (the form was submitted) if request.method == "POST": if checkBtn("cancel", form): # If cancel button is pressed, issue a redirect to profile page return redirect(url_for('.profile', username=user.username)) elif checkBtn("submit", form): # If submit button is pressed, update about me. user.about_me = form.about_me.data # Flash message flash("The profile has been successfully updated.", 'success') # Issue redirect return redirect(url_for('.profile', username=user.username)) # Set initial value form.about_me.data = user.about_me # Render template return render_template("blog/editProfile.html", title="Blog - User's Profile", year=year, form=form, user=user)
def editProfile(): # Create form object form = EditProfile() # If request method is POST (the form was submitted) if request.method == "POST": if checkBtn("cancel", form): # If cancel button is pressed, issue a redirect to profile page return redirect(url_for('.profile', username=current_user.username)) elif checkBtn("submit", form): # If submit button is pressed, update about me. current_user.about_me = form.about_me.data # Flash message flash("Your profile has been successfully updated.", 'success') # Issue redirect return redirect(url_for('.profile', username=current_user.username)) # Set initial value form.about_me.data = current_user.about_me # Render template return render_template("blog/editProfile.html", title="Blog - Edit Your Profile", year=year, form=form)
def edit_profile(): form = EditProfile() user = User.query.filter_by(email=current_user.email).first() if form.validate_on_submit(): current_user.handle = form.handle.data current_user.rsi_profile = form.rsi_profile.data current_user.tas_profile = form.tas_profile.data current_user.hide_email = form.hide_email.data db.session.add(user) flash('Your profile has been updated.', 'info') return redirect(url_for('user.profile', handle=current_user.handle)) form.handle.data = current_user.handle form.rsi_profile.data = current_user.rsi_profile form.tas_profile.data = current_user.tas_profile form.hide_email.data = current_user.hide_email return render_template('user/edit_profile.html', form=form)
def edit(): edit_form = EditProfile() edit_avatar = EditAvatar() if edit_avatar.avatar.data: file_path = os.path.join(app.config['UPLOAD_FOLDER'], current_user.nickname + ".png") edit_avatar.avatar.data.save(file_path) if edit_form.validate_on_submit(): about_me = edit_form.about_me.data current_user.about_me = about_me db.session.add(current_user) db.session.commit() return redirect(url_for('edit')) return render_template('edit_profile.html', edit_form = edit_form, edit_avatar = edit_avatar)