def profile(): user = g.user form = ProfileForm(request.form, obj=user) if form.validate_on_submit(): user.name = form.name.data user.mobile = form.mobile.data user.website = form.website.data user.description = form.description.data if 'photo' in request.files: # remove user photo and thumbs mfile = request.files['photo'] if mfile and allowed_image_file(mfile.filename): # if file reuploaded if user.photo and len(user.photo) > 0: photo = os.path.join( UPLOAD_FOLDER, str(user.id), user.photo ) try: os.remove(photo) except Exception as e: print ("removing %s" % photo) current_app.logger.exception(e) fufile = str(photo.split('.')[0]) for basewidth in [200, 245]: thumb = fufile + '_thumb%s.png' % basewidth try: os.remove(thumb) except Exception as e: print ("removing %s" % thumb) current_app.logger.exception(e) user.photo = '' filename = secure_filename(mfile.filename) ext = filename.rsplit('.', 1)[1] fname = '%s_%s' % (g.user.id, g.user.email) newfn = '%s.%s' % (base64.b64encode(fname), ext) photo = os.path.join( UPLOAD_FOLDER, str(user.id), newfn ) mfile.save(photo) user.photo = newfn db.session.commit() flash(gettext(u'Profile updated')) return redirect(url_for("users.profile")) return dict(form=form, user=user)
def profile(): form = ProfileForm(user=g.user, obj=g.user) if form.validate_on_submit(): g.user.name = form.name.data g.user.email = form.email.data if form.password.data: g.user.password = bcrypt.generate_password_hash(form.password.data) db.session.add(g.user) db.session.commit() flash('Your profile has changed successfully.') return redirect(url_for('users.profile')) return render_template('profile.html', form=form, title='Me Profile')
def profile(): form = ProfileForm() if request.method == "GET": form.full_name.data = current_user.full_name form.age.data = current_user.age if form.validate_on_submit(): current_user.full_name = form.full_name.data current_user.age = form.age.data db.session.commit() flash("Your profile has information has been saved", "success") return redirect(url_for('users.dashboard')) return render_template('profile.html', form=form, title="Edit Profile")
def change_password(): user = User.query.get(session['user_id']) form = ProfileForm(request.form, obj=user) if form.validate_on_submit(): user.name = form.name.data user.country = form.country.data user.address = form.address.data user.mobile = form.mobile.data user.website = form.website.data db.session.commit() flash(gettext(u"Profile updated")) return redirect(url_for("users.home")) return dict(form=form, user=user)